c++ - Loading an interface fails -
i'd use com function : createinstance http://msdn.microsoft.com/en-us/library/k2cy7zfz%28v=vs.80%29.aspx
like this
ipointer p=null; hresult hr=p.createinstance(xxx); however don't have clsid of xxx know interface name isubpointer can see interface description inside tlb file when view file oleview. should use createinstance ?
there 2 ways this:
1st: classfactory ,and
2nd: helper function create pointer.
i found this:
int main() { imath* pimath; hresult hr; // 1. initialize com library coinitialize(null); // 2. call cocreateinstance imath interface pointer hr = cocreateinstance ( __uuidof(cmathcomp), null, clsctx_inproc_server, __uuidof(imath), (void**) &pimath ); if ( failed(hr) ) { return 0; } // 3. call interface functions int sum = pimath->add(1, 3); printf("sum = %d \n", sum); int sub = pimath->sub(4, 3); printf("sub = %d \n", sub); // 4. release interface pointer if done pimath->release(); // 5. un-initialize com library couninitialize(); return 0; } also see msdn:
hresult cocreateinstance( _in_ refclsid rclsid, _in_ lpunknown punkouter, _in_ dword dwclscontext, _in_ refiid riid, _out_ lpvoid *ppv ); if can gather clsid oleview use it, otherwise there must documentation this. can't deliver component without exposing ist clsid.
Comments
Post a Comment