Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect all interfaces a COM object implements?

Tags:

windows

com

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

like image 235
sharptooth Avatar asked Nov 18 '09 14:11

sharptooth


2 Answers

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.

like image 51
MB. Avatar answered Sep 28 '22 17:09

MB.


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.

like image 39
Hernán Avatar answered Sep 28 '22 18:09

Hernán