visual-c++importvisual-studio-2008comregtlib

C4772 even when the type library is registered and present


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 that 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?


Solution

  • 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.