Using Visual Studio with Microsoft's C++ compiler, we have several source files which use the Microsoft-specific '#import' directive to import a type library. For instance:
#import my_type_lib.tlb
I'd like to remove the #import from the source code, and replace it with a command line step to be executed via GNU Make. The necessary interface definitions (.idl source code) are available during the build.
How can I remove my dependency on #import and replace it with specialized build tools to be executed via the command line?
As far as I know, there are no separate tools to generate code from the type lib.
You could do #import
once, and then stash away the generated files and include them as regular source files. But then changes to the type library would need a new supervised build to regenerate the files.
Which parts of the generated information are you using? If you only use this to get to IIDs, interfaces and CLSIDs, and you have the .IDL, you can use MIDL.EXE to generate a C++ representation.
If you're using the wrapper classes (IxxxPtr
), I think you're short on luck -- these are produced by #import
.
It just occurred to me that you could use the compiler directly to generate the .tli/.tlh files from a type library.
With a simple source file, like this
// imports.cpp
#import "foo.dll"
#import "bar.dll"
int main(int argc, char* argv[])
{
}
you can use cl.exe to generate #import
wrappers, and a useless .exe file, like so:
...\>cl.exe imports.cpp
From there on, #include
the wrappers (foo.tlh/.tli) in your regular source code.
Not sure that this is an improvement on #import
, but at least you've extracted #import
out of your code base.