DumpCOM Sample
Demonstrates ComDiag.cs usage. ComDiag provides services to investigate
certain COM object at runtime. Idea was taken from OLE/COM Object Viewer tool and
Andrew Nosenko's unmanaged DumpQIQS
C++ tool dumping registered interfaces/services supported by certain COM object.
Learning .NET interop, I created managed version of this tool.
ComDiag exposes two useful functions: DumpInterfaces and DumpServices. DumpInterfaces
accepts raw pointer to IUnknown interface and outputs other interfaces supported
by this object:
object obj = new Object();
IntPtr pUnk = Marshal.GetIUnknownForObject(obj);
ComDiag.DumpInterfaces(pUnk);
Marshal.Release(pUnk);
This outputs:
Dump interfaces for IUnknown 0x07290004
--
{00000000-0000-0000-C000-000000000046} : [0x07290004] IUnknown
{00000003-0000-0000-C000-000000000046} : [0x0019EACC] IMarshal
{00020400-0000-0000-C000-000000000046} : [0x07290004] IDispatch
{65074F7F-63C0-304E-AF0A-D51741CB4A8D} : [0x07290004] _Object
{B196B283-BAB4-101A-B69C-00AA00341D07} : [0x0019EAC8] IProvideClassInfo
{B196B284-BAB4-101A-B69C-00AA00341D07} : [0x0019EADC] IConnectionPointContainer
{C3FCC19E-A970-11D2-8B5A-00A0C9B7C9C4} : [0x0019EAD8] IManagedObject
{DF0B3D60-548F-101B-8E65-08002B2BD119} : [0x0019EAD0] ISupportErrorInfo
{DF0B3D60-548F-101B-8E65-08002B2BD119} : [0x0019EAD0] PSSupportErrorInfo
DumpServices outputs services exposed by COM object via IServiceProvider interface.
It's often useful in WebBrowser development:
WebBrowserClass wb = new WebBrowserClass();
IntPtr pUnk2 = Marshal.GetIUnknownForObject(wb);
ComDiag.DumpServices(pUnk2);
Marshal.Release(pUnk2);
And output:
Dump Services for IUnknown 0x00175CD0
--
{332C4427-26CB-11D0-B483-00C04FD90119} : [0x00175FAC] IHTMLWindow2
{79EAC9C5-BAF9-11CE-8C82-00AA004BA90B} : [0x00175CD0] IHlinkFrame
--
Download
dumpcom.zip.