开发者

C4772 even when the type library is registered and present

开发者 https://www.devze.com 2022-12-21 21:17 出处:网络
I have a set of Visual C++ 9 COM component projects dependent on each other. ComponentA publishes its typelib into ComponentA.tlb. ComponentB imports ComponentA.tlb into ComponentB.idl and publishes

I have a set of Visual C++ 9 COM component projects dependent on each other.

ComponentA publishes its typelib into ComponentA.tlb. ComponentB imports ComponentA.tlb into ComponentB.idl and publishes ComponentB.tlb. Methods signatures in ComponentB.idl contain parameters of types defined in ComponentA.tlb. Both ComponentA and ComponentB projects compile allright.

ComponentC #imports both ComponentA.tlb and ComponentB.tlb into stdafx.h - this suddenly fails with

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

and later a set of

error C2440: 'return' : cannot convert from '__missing_type__ *' to '__missing_type__'

for wrappers using types defined in ComponentA.tlb. Usually th开发者_运维知识库at happens when ComponentA.tlb is not registered, but I've surely run regtlib and see in regedit that it is registered. ComponentA.tlb is present exactly on the path specified in the registry.

What's the problem source and how can the problem be resolved?


Not sure I had the same problem as you, but I would get the C4772 error on my first build, then it would go away on a second build.

The solution was to copy A.tlb into the project dir (copy "$(OutDir)\A.tlb .") as a pre-build step, then delete it as a post-link step.

My program does a #import on A.tlb then B.tlb (which depends on types in A.tlb). The #import of A.tlb succeeded, but B.tlb failed. Both TLB files were in an include directory, and neither underlying .DLL was registered with regsvr32 (everything works fine if the COM objects are registered).

Best I can tell, the #import statement does not honor the C++ include path, which is why it could not find A.tlb when A.dll was not registered.


Looks like the problem can be attributed to changing ComponentA interfaces. Once ComponentA interfaces change while its typelib is registered the problem starts arising.

The workaround I use is to unregister ComponentA typelib and register it again - I crafted a small program (regtlib just can't unregister a typelib) that calls RegisterTypeLib() and UnregisterTypeLib() for that and looks like the problem is gone.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号