Introduction
Just wondered around the other day and tried to find a ready made class library to get COM+/ActiveX Type Library information from registered objects. Since I couldn't find anything, I decided to quickly implement my own version.
The solution
The basic idea is that you should create a new object of type TypeLibraries
, and with a single call of the method GetAllFromRegistry()
, should populate it with information from the Registry. The form of collection is CollectionBase
, so basically it should be easy to sort, search, and modify the way you want. Another method you can find is FindByGUIDAndVersion
which searches from the TypeLibraries
collection TypeLibrary
class with similar GUID and version information - this is because many times the GUID might be the same, but only the version changes.
The whole thing is basically in the following code - the rest of the classes are merely placeholders:
Public Sub GetAllFromRegistry()
Const TLB_ROOT As String = "TypeLib"
Dim rkey As RegistryKey = Registry.ClassesRoot
Dim regTypeLibRoot As RegistryKey = rkey.OpenSubKey(TLB_ROOT)
For Each strTypeLib As String In regTypeLibRoot.GetSubKeyNames
Dim regTypeLib As RegistryKey = regTypeLibRoot.OpenSubKey(strTypeLib)
For Each strVersion As String In regTypeLib.GetSubKeyNames
Dim regVersion As RegistryKey = regTypeLib.OpenSubKey(strVersion)
Dim typeLib As New TypeLibrary
typeLib.GUID = strTypeLib
typeLib.Version = strVersion
For Each strValueName As String In regVersion.GetValueNames
Select Case strValueName
Case "PrimaryInteropAssemblyName"
typeLib.PrimaryInteropAssemblyName = _
regVersion.GetValue(strValueName)
Case Else typeLib.FullName = regVersion.GetValue(strValueName)
End Select
Next
For Each strSubKey As String In regVersion.GetSubKeyNames
Dim regSubKey As RegistryKey = regVersion.OpenSubKey(strSubKey)
Select Case strSubKey
Case "FLAGS" : typeLib.Flags = regSubKey.GetValue("")
Case "HELPDIR" : typeLib.HelpDir = regSubKey.GetValue("")
Case Else
Dim typeLibFiles As New TypeLibraryFiles
For Each strPlatform As String In regSubKey.GetSubKeyNames
Dim tlbFile As New TypeLibraryFile
tlbFile.Number = strSubKey
Select Case UCase(Trim(strPlatform))
Case "WIN16" : tlbFile.Platform = _
TypeLibraryFile.TypeLibraryPlatformType.Win16
Case "WIN32" : tlbFile.Platform = _
TypeLibraryFile.TypeLibraryPlatformType.Win32
Case "WIN64" : tlbFile.Platform = _
TypeLibraryFile.TypeLibraryPlatformType.Win64
Case Else : tlbFile.Platform = _
TypeLibraryFile.TypeLibraryPlatformType.Unknown
End Select
tlbFile.File = _
regSubKey.OpenSubKey(strPlatform).GetValue("")
typeLibFiles.Add(tlbFile)
Next
typeLib.Files = typeLibFiles
End Select
Next
MyBase.List.Add(typeLib)
Next
Next
End Sub
Public Function FindByGUIDAndVersion(ByVal GUID As String, _
ByVal Version As String) As TypeLibrary
If Me.InnerList.Count = 0 Then Me.GetAllFromRegistry()
For Each t As TypeLibrary In Me.InnerList
If GUID = t.GUID And Version = t.Version Then Return t
Next
Return Nothing
End Function