tags:

views:

146

answers:

3

Is there any way for a consumer to enumerate all interfaces implemented by a given COM object?

+1  A: 

Dependency Walker might do the job for you...

http://theircorp.byethost11.com/index.php?vw=TypeLib is a free tool to examine the TBL files.

weismat
Does Dependency Walker have a feature for this?
Kim Gräsman
+2  A: 

Dependency Walker won't show the interfaces as the only exports are DllGetClassObject, DllRegisterServer, etc (for DLL-hosted COM).

You may, as weismat says, inspect the TLB files. Many COM objects contain embedded typelibs in the resource section of the executable. With a tool such as resource hacker you can extract the TLBs and use LoadTypeLib COM functions to get a pointer to ITypeLib interface (you could use LoadTypeLib/LoadTypeLibEx directly with a COM or EXE DLL, of course).

WIth this interface you can iterate over the types contained within.

Hernán
Evaluating the TLB's contents will not expose information about any private interfaces the COM object may be using, though.
Remy Lebeau - TeamB
Private COM Interfaces won't appear, you're right.
Hernán
+2  A: 

You can try IDispatch/IDispatchEx if you simply want to know what methods are callable from your consumer.

In COM, the QueryInterface method on IUnknown is not required to expose what interfaces it may return. You ask for one based on its IID and you either get it or not. The implementation of QI in a particular COM object varies considerably although it's supposed to follow the pattern described by Microsoft here - http://msdn.microsoft.com/en-us/library/ms682521%28VS.85%29.aspx.

MB
If don't remember bad, with IDispatch/IDispatchEx you will catch the interfaces with oleautomation attribute in the IDL.
Hernán