Archived

This topic is now archived and is closed to further replies.

COM: Get the REFIID from CLSID?

Recommended Posts

ghost1206    122
How can someone having the CLSID of the class in a COM object can expose the interfaces available? The only way I can see is to use QueryInterface in a loop until he/she "bumps" into an interface that is supported (quite ugly). Any better ways?

Share on other sites
Try using CoCreateInstance and the IDispatch interface along with the CLSID. Here's a snippet of how to do it in C

  IDispatch *pIDispatch;HRESULT hr = CoCreateInstance(&clsid, 0 , CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , &IID_IDispatch, (void**)&pIDispatch);ITypeInfo *pTypeInfo;hr = IDispatch_GetTypeInfo(pIDispatch, 0, 0, &pTypeInfo);// pIDispatch->lpVtbl->GetTypeInfoBSTR interfaceName;hr = ITypeInfo_GetDocumentation(pTypeInfo, -1, &interfaceName, 0, 0, 0);// pTypeInfo->lpVtbl->GetDocumentation

From there you can use GetTypeAttr, GetFuncDesc, and GetDocumentation to retrieve method names.

For how to do it in C++ see

http://ript.net/~spec/typeinf2/

Edited by - lessbread on February 1, 2002 2:33:38 AM

Share on other sites
The best is to do an interface that give this fonctionnality.

But the Query way is not so bad.

Share on other sites
ghost1206    122
Thanks lessbread! I haven''t tried it yet, but it seems logical and I certainly will. I owe one

Share on other sites
ghost1206    122
Ok jesterlecodeur, suppose you make this interface that exposes all the REFIIDs of the interfaces supported by the COM dll. How would you then get the REFIID of this interface having only the CLSID?

Another way is to make a function that would do exactly that: return the REFIID of such an interface. Then with a "LoadLibrary" and a "GetProcAddress" you could get this function and then the interface and from there... talking about ugly ways! Let alone that I think it''s breaking the COM model of programming. I''ll better check the stuff lessbread sent me