1

Whilst I am doing VB6 development, I think that this is a wider issue. I have found that sometimes in the VB IDE we get an error: [BadImplementsRefInCompatLib]. Using the Type Library Viewer that comes with "Advanced Visual Basic 6" by Matt Curland, it flags up that the type library in my component has a reference to a type library it can't find, but not what it is. The underlying error is with the TLI component when it tries to find out about an interface that is defined in another type library.

I also tried OLE View - to try and reverse compile the IDL - but again, it gave an error message when trying to get the external type, without identifying the erroneous value.

I traced the actual error back to the type library reference in the registry which was point to a component, but the major version was incorrect. Replacing the major version fixed the issue.

I used a binary editor to see if I could spot what information is being used in the type library. And indeed, I found the names (no paths) of the components which it references, but I couldn't work out the format. I was actually hoping to find a table of type library GUIDs and version numbers. I suppose I could write code to extract these names, and eliminate the "working" references, but this is a bit crude.

Does anyone know how a type library references external types?

4

1 回答 1

2

[BadImplementsRefInCompatLib] means that your binary compatible target's typelib has a reference to an external typelib and this external typelib is not registered.

For instance if you have a project group with several ActiveX DLLs that are set to binary compatible version compatibility and Project2 references Project1 (uses types from Project1 on functions/properties prototypes of a public class) when Project1 breaks compatibility and gets recompiled Project2's compatibility target has a typelib that references external typelib that is not registered (namely the old version of Project1 component).

In our shop we do have references across VB6 projects but never ever use types from core on public methods/properties of classes. Such parameters are declared As Object and down-cast in code which is less trouble than tying components with external cross references. Curland's EditTLB is used regularly to spot offending classes.

No idea how a type library references external types. I just importlib("component.tlb") in idl and use types from component at will.

Btw, a very simple way to "protect" a COM component (DLL/OCX) from being used in VB6 IDE is to reference a struct in external custom made typelib (param to a public method) and then "forget" to ship this external typelib. VB6 IDE chokes with "Error loading DLL" on adding a reference to the DLL/OCX but the component works and registers perfectly, provided you don't try to call this "obfuscated" method cross threads (in-process or not).

于 2012-11-09T15:07:38.073 回答