Any way to resolve C4772 errors without having to register DLLs?

余生长醉 提交于 2020-01-14 19:10:45

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3773568/any-way-to-resolve-c4772-errors-without-having-to-register-dlls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!