Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate type library from unmanaged COM dll

I have to use third party, unmanaged COM dll into my .NET application. I need to modify this assembly to produce a custom RCW. In order to Edit Interop Assembly I need the type library of the particular assembly. Can any one explain me that how to How to generate type library from unmanaged COM dll?

There is no option in regsvr32 to generate type library.

Thank you, Best Regards, Robo.

like image 357
RoboAlex Avatar asked Feb 14 '11 08:02

RoboAlex


3 Answers

You need the OLE-COM Object Viewer, available as part of whatever is the latest Windows SDK. Then you can go to File->View Type Lib and save the IDL to a text file. Then you can use MIDL (also part of the Windows SDK) to regenerate a TLB and header file. Something like this should do for basic cases:

midl /out c:\temp /header MyHeader.h MyIDLFile.idl
like image 171
Guido Domenici Avatar answered Oct 17 '22 20:10

Guido Domenici


If all you're trying to do is create an Interop Assembly from a native dll (and the native DLL embeds the TLB as a resource), you can just call tlbimp directly on the dll:

tlbimp Foo.dll /out:Interop.Foo.dll

Which will generate Interop.Foo.dll. You can then use ildasm to modify the IL:

ildasm Interop.Foo.dll /out=Foo.il
like image 6
smarcellus Avatar answered Oct 17 '22 21:10

smarcellus


If all you have is that COM DLL, you can't generate a type library. A type library describes the COM interfaces implemented. But an unmanaged COM DLL merely needs to expose DllGetClassObject. This only gets you an IClassFactory, which lets you create new objects if you knwo the correct type up front.

like image 5
MSalters Avatar answered Oct 17 '22 20:10

MSalters