Question

I am maintaining a VS2010 project which has a number of cross-referenced COM libraries. I am trying to configure the project in such a way that it is buildable from a random workstation which has VS2010 installed. The workstation could be both 32 and 64 bit, so if I configure project to "register output", the build will fail to build on 32-bit machine, since 64-bit DLL will not be possible to load to call DllRegisterServer.

Here is an example: Typelib from project B references typelib from project A. Project C will reference project B via following statement:

#import "B.tlb"

Since library B references A, when B.tlb is being imported, the compiler tries to load types from A. So, if A is not registered, the compile will fail with:

error C4772: #import referenced a type from a missing type library ...

I tried to open B.tlb using the OleView application, and it's sure as hell only showing right file name for library A reference if it is registered using regsvr32.

So, my question here is: is there any alternative way for library references to resolve themselves properly, without having to register TLBs, just by putting all the files in the same directory somehow, or attaching some sort of manifest? For example, rename the TLB for a library as .tlb or something of that sort.

Was it helpful?

Solution

Try import the referenced A.tlb first, or list it in the import of B.tlb using the include() option.

Only #import the parts of the interface you plan to use if you can avoid bringing in other references unnecessarily.

OTHER TIPS

There is a good option: add path to the .tlb files to VC++ Directories -> Executable Directories This adds the path to PATH environment variable which will be given to the compiler. According to this: http://msdn.microsoft.com/en-us/library/sce74ah7.aspx all .tlb REFERENCED in imported one are searched only in PATH and LIB.

The easiest way it is place all *.tlb files in dir when they are used.

Depends on your project configuration. Copy all *.tlb files into: $(OutDir), $(ProjectDir), dir where is file with #import, dir when you generate *.tlb etc

Regards, Mariusz

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top