How to get type library from ProgID or CLSID (without loading a COM object)?

How can I get the path or LIBID of a type library programmatically, given the ProgID or CLSID of the COM class contained in this type library without creating an instance of the COM object?

For some COM objects, you can do this through the registry path

HKEY_CLASSES_ROOT\CLSID\{clsid}\TypeLib 

But some COM objects do not have a TypeLib key, for example Word.Application :

enter image description here

How can I determine the type library path or LIBID for these COM objects without instantiating the COM object?

+7
source share
2 answers

A type library may or may not be associated with this CLSID . If you don't have a reference to the type library in the registry, you might be lucky to get it at runtime using IDispatch::GetTypeInfo .

A COM class without a type library (registered type library) is still a valid COM class, so you can run it completely and use it without a type library.

Another chance you have is to find the binary hosting of the COM server, be it .EXE , .DLL or .OCX , and try to load the type library from your resources (usually under identifier 1). Quite often, a type library is right there.

+2
source

As you mentioned in your question, not all COM objects have a TypeLib identifier in the registry or are not even forced to send their TypeLib to the target system, but in order to be able to disclose information about the object, TypeLib. Therefore, it is common that their TypeLib information is stored in an EXE or DLL as a resource. You can use LoadTypeLib to extract TypeLib information like ITypeLib from and then write your own IDL or even extract the resource and then save it as .tlb .

0
source

All Articles