How do I convert a .tlb file to headers and implementation files?

jcao219 picture jcao219 · Jun 24, 2011 · Viewed 8.2k times · Source

I'm trying to convert mscorlib.tlb. It normally used in C++ like this:

#import "mscorlib.tlb" raw_interfaces_only              \
     high_property_prefixes("_get","_put","_putref")        \
     rename("ReportEvent", "InteropServices_ReportEvent")

How can I convert it to headers and implementation files?

I was able to use Visual Studio to compile a dummy cpp file that contained the lines above, and it produced a .tlh file. Shouldn't there also be implementation files?

Answer

Eli picture Eli · Aug 18, 2011

You can split implementation and declaration by using the "no_implementation" and "implementation_only" parameters to #import. These generate .tlh (type library header) and .tli (type library implementation) files.

I typically put the following into a header file (like stdafx.h):

#import "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.tlb" no_implementation

And the following into a .cpp file (like stdafx.cpp):

#import "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.tlb" implementation_only