Getting TypeLib ID of a COM dll

N

nassegris

Hello!

I need to somehow extract the TypeLib ID from a COM-dll compiled using
VB6. Is is possible or do I have to look it up in the registry somehow
(ie by iterating over TypeLibIDs in HKEY_CLASSES_ROOT\TypeLib\ and
matching the DLL path info?

Please excuse any inaccuracies in this post, my understanding of COM
is patchy, especially the progid/clsid/typelib part of it.
 
N

Nicholas Paldino [.NET/C# MVP]

To what end do you need to get the type library id? The type library id
is the unique identifier for the TLB/DLL, while the CLSID is for the
individual type in the type library.

Regardless, if you want to get information about the type library, you
can call the LoadTypeLibEx function through the P/Invoke layer. You can use
this to get an instance of the ITypeLib interface in the
System.Runtime.InteropServices.ComTypes namespace.

From there, you have to call the GetLibAttr method on the ITypeLib
interface, getting an IntPtr which points to the structure in memory which
has the type library id. You will have to define the TLIBATTR structure,
and then call the static PtrToStructure method on the Marshal class to get
an instance of it (passing the IntPtr returned to you when you called
GetLibAttr).

Once you have the structure, you can access the guid property on it to
get the type library id. Also, don't forget to call ReleaseTLibAttr,
passing the IntPtr you used to get the TLIBATTR structure, so the memory can
be released.
 
N

nassegris

Thank you Nicholas, worked like a charm! :)
The reason I needed to do this was that I was writing a vb5 reference
fixer app. I have several large vb6 solutions (20-30 projects
in each one, all of them with dependencies to eachother) and when one
project breaks the binary compatibility I have to update
references to it. Also different versions of components come from
other developers etc, so the invalid reference problem is something I
have to face daily. Now I have an app that goes through the .vbp file
and updates all dll references to the correct typelib ids. =)

To what end do you need to get the type library id? The type library id
is the unique identifier for the TLB/DLL, while the CLSID is for the
individual type in the type library.

Regardless, if you want to get information about the type library, you
can call the LoadTypeLibEx function through the P/Invoke layer. You can use
this to get an instance of the ITypeLib interface in the
System.Runtime.InteropServices.ComTypes namespace.

From there, you have to call the GetLibAttr method on the ITypeLib
interface, getting an IntPtr which points to the structure in memory which
has the type library id. You will have to define the TLIBATTR structure,
and then call the static PtrToStructure method on the Marshal class to get
an instance of it (passing the IntPtr returned to you when you called
GetLibAttr).

Once you have the structure, you can access the guid property on it to
get the type library id. Also, don't forget to call ReleaseTLibAttr,
passing the IntPtr you used to get the TLIBATTR structure, so the memory can
be released.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I need to somehow extract the TypeLib ID from a COM-dll compiled using
VB6. Is is possible or do I have to look it up in the registry somehow
(ie by iterating over TypeLibIDs in HKEY_CLASSES_ROOT\TypeLib\ and
matching the DLL path info?
Please excuse any inaccuracies in this post, my understanding of COM
is patchy, especially the progid/clsid/typelib part of it.- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top