Archived

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

ghost1206

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 this post


Link to post
Share on other sites
LessBread    1415
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->GetTypeInfo


BSTR 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 this post


Link to post
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

Share this post


Link to post
Share on other sites
LessBread    1415
I''m curious myself as to whether the methods detailed in that article will produce useable interfaces - they might only give strings. If you don''t have adequate help info look for "automat.chm" and "automat.chi" in ftp://ftp.microsoft.com/developr/PlatformSDK/feb2001/common/help/
and "com.chi" and "com.chm" might also be helpful.

Share this post


Link to post
Share on other sites