Groups | Blog | Home
all groups > dotnet interop > may 2006 >

dotnet interop : .NET COM latebinding


MikeM
5/16/2006 10:31:51 AM
I'm facing a problem where I'm trying to use a new .NET app to access
some old VB6 ActiveX exes. The ActiveX exes implement a (base) COM dll
and use an exposed method from that COM dll to do some work. Here is
what I got from the OLE viewer

pcIEBase has a public function Export
interface _clsExportBase : IDispatch {
[id(0x6803001c), propput]
HRESULT Export(
[in] BSTR sTaskInfoXML,
[in] BSTR sParmInfoXML);

};

so coclass pcIENewHire has an interface like this:
coclass clsExportNewHire {
[default] interface _clsExportNewHire;
interface _clsExportBase;
};

How do I access the public Export function via the pcIENewHire from a
..NET app? The Export function is private in the ActiveX exe that I'm
interested in. The public function in the pcIEBase.dll is just a stub,
and In essence I want to execute the Export function located within the
pcIENewHire, but my only exposure is to the public pcIEBase.dll.

On a whim I added references to both the pcIEBase and the pcIENewHire
to my .NET app and via this early binding was able to execute the
proper version of the Export function. However in the real world, I
will not know the prog id at compile time, only at run time. So this is
the rub, early binding works but I haven't figured out the latebinding
call.

Any help would be appreciated


Thanks in advance
Mike Malinowski, Software Engineer
Dmytro Lapshyn [MVP]
5/18/2006 1:51:32 PM
Hi Mike,

So what you basically need in COM terms is to do QueryInterface on
_clsExportNewHire to get _clsExportBase. This should be possible even with
late binding. Try getting the type of the late binding reference:

Type t = typeof(myCOMObject);

and then call GetInterfaces or FindInterfaces on the obtained type to locate
the base interface.

Plus, you might find useful to read the MSDN docs on the
Marshal.QueryInterface method.

[quoted text, click to view]
AddThis Social Bookmark Button