8

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

For some COM objects, you can do that via the registry path

HKEY_CLASSES_ROOT\CLSID\{clsid}\TypeLib

But some COM objects do not have a TypeLib key, such as Word.Application:

enter image description here

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

2
  • There is a good microsoft tool that helps a lot when working with com/ole objects, which is called oleview. This could help you finding the path of the lib Commented Oct 19, 2012 at 13:51
  • @AquilaRapax: I am looking for a way how to do that programmatically. Commented Oct 19, 2012 at 13:59

2 Answers 2

2

Type library might be or might be not associated with given CLSID. If you do not have the type library reference on the registry, you might have better luck obtaining it on runtime using IDispatch::GetTypeInfo.

A COM class without type library (ore registered type library) is still a valid COM class, so you might end up having it well running and usable without type library at all.

One more chance that you have is to locate the binary hosting the COM server, whether it is .EXE, .DLL, or .OCX, and attempt to load a type library from its resources (typically under identifier of 1). Quite often, the type library is right there.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, I forgot to mention in my question that I am looking for a way how to achieve this without instantiating the COM object. Nevertheless, +1 for your answer.
Added another para (see above).
Unfortunately, not all COM objects store the type lib as a resource (for example Word.Application, which stores the type lib in a separate file).
In which case there is little you can do.
0

As you mentioned in your question not all COM objects have a TypeLib ID in the registry or even they are not forced to ship their TypeLib to target system, but in order to be able to expose their object's information they need a TypeLib. So it is common that their TypeLib information is stored in the EXE or DLL as a resource. You can use LoadTypeLib function to extract TypeLib information as ITypeLib from specified module and then write your own IDL or even extract the resource and then save it as .tlb.

6 Comments

How do you determine the file path needed by LoadTypeLib?
Of course from registry, same as COM find the module that required to instantiate your class, so if there is TypeLib in the registry use it, other wise find the module from InprocHandler32, InporcServer32 or LocalServer32 and then use it in a call to LoadTypeLib
The registry keys you mention contain the path to the DLL or EXE that hosts the COM object; these registry keys do not contain the path of the type library file (.TLB or .OLB).
That's certainly OK! I told you in my answer that it is common that their TypeLib information is stored in the EXE or DLL as a resource, take a look at LoadTypeLib, it can load type libraries and modules that contain type libraries as resource.
Unfortunately, not all COM objects store the type lib as a resource (for example Word.Application, which stores the type lib in a separate file).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.