Click here to Skip to main content
Click here to Skip to main content

Type Library Browser for .NET 2.0

, 12 Nov 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
Example application to demonstrate how to get the COM+ type library information from the Registry and display it.

Sample Image - typelibbrowser.jpg

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)

        ' In strVersions we should have list of typelib versions
        For Each strVersion As String In regTypeLib.GetSubKeyNames
            Dim regVersion As RegistryKey = regTypeLib.OpenSubKey(strVersion)

            ' Now we can create a new TypeLibrary object since under 
            ' this value there should be only descriptive info of Type Library
            Dim typeLib As New TypeLibrary

            ' Set values we know by now
            typeLib.GUID = strTypeLib
            typeLib.Version = strVersion

            ' Here we should have at least one value for 
            ' descriptive name of TypeLib - not always though...
            For Each strValueName As String In regVersion.GetValueNames
                Select Case strValueName
                    Case "PrimaryInteropAssemblyName"
                    ' We got name of PrimaryInteropAssemblyName
                        typeLib.PrimaryInteropAssemblyName = _
                                regVersion.GetValue(strValueName)
                    Case Else ' We got descriptive name of TypeLib
                        typeLib.FullName = regVersion.GetValue(strValueName)
                End Select
            Next

            ' Iterate through subkeys
            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 ' We found propably number with subkey 
                              ' of "win32","win16" or even "win64"

                        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("")
                            ' Get name of file as a default value

                            typeLibFiles.Add(tlbFile)
                            ' Add file to collection
                        Next

                        typeLib.Files = typeLibFiles
                        ' Set files collection to typelib info
                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()
    ' if no data exists, populate
    For Each t As TypeLibrary In Me.InnerList
        If GUID = t.GUID And Version = t.Version Then Return t
    Next

    Return Nothing
End Function

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tommi G
Web Developer
Finland Finland
Microsoft Certified Professional (MCP)

Comments and Discussions

 
QuestionWhat's comig after the introduction? PinmemberMircea Puiu13-Nov-05 1:08 
AnswerRe: What's comig after the introduction? PinmemberTommi G13-Nov-05 9:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 13 Nov 2005
Article Copyright 2005 by Tommi G
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid