views:

171

answers:

3

We have a .NET app that needs to examine a folder that may contain COM libraries (DLL and OCX.) When we do encounter a COM library one thing we need to accomplish is to extract the GUID from the COM DLL or OCX.

Is there a straightforward way to do this with .NET without using 3rd party libraries?

A: 

You will have to use interop (both P/Invoke and COM) in order to do this. First, you will have to call the LoadTypeLib to get the ITypeLib interface for the type library.

From there, you will have to use the methods on that in order to get the GUID for the library, or get the CLSID or IID instances for anything defined in the library.

casperOne
+1  A: 

This should work for you. It requires a reference to c:\windows\system32\tlbinf32.dll, but I'm assuming that is okay because it isn't a third party component.

Imports TLI 'from c:\windows\system32\tlbinf32.dll

Dim reglib As TLI.TLIApplication = New TLI.TLIApplicationClass()
Dim DLLPath As String = "c:\mycomponent.ocx"
MsgBox(reglib.TypeLibInfoFromFile(DLLPath).GUID.ToString())
JohnFx
+1, I also thought about this approach (cf. http://msdn.microsoft.com/en-us/magazine/bb985086.aspx as as well), but I believe tlbinf32.dll was only shipped with VS 6.0 (and/or VB6), at least it is not present on my system.
0xA3
You could be right. I've got a VB6 install on my dev machine for maintaining some old ActiveX controls and legacy code. However, I found several sites where you could download it and you could probably distribute it without royalties.
JohnFx