Click here to Skip to main content
13,353,706 members (56,233 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 13 Nov 2005

Type Library Browser for .NET 2.0

, 13 Nov 2005
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


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 = _
                    Case Else ' We got descriptive name of TypeLib
                        typeLib.FullName = regVersion.GetValue(strValueName)
                End Select

            ' 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 = _
                                Case "WIN32" : tlbFile.Platform = _
                                Case "WIN64" : tlbFile.Platform = _
                                Case Else : tlbFile.Platform = _
                            End Select

                            tlbFile.File = _
                            ' Get name of file as a default value

                            ' Add file to collection

                        typeLib.Files = typeLibFiles
                        ' Set files collection to typelib info
                End Select

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

    Return Nothing
End Function


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


About the Author

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

You may also be interested in...


Comments and Discussions

QuestionWhat's comig after the introduction? Pin
Mircea Puiu13-Nov-05 2:08
memberMircea Puiu13-Nov-05 2:08 
AnswerRe: What's comig after the introduction? Pin
Tommi G13-Nov-05 10:23
memberTommi G13-Nov-05 10:23 
Sorry about that...I was in a bit of a hurry while writing this and the publishing tool wasn't as easy to use as I thought since I wanted to add few screenshots of the registry keys we are dealing in code.

This piece of code, however, is about to be evolving and (hopefully) soon I'm about to provide larger example with managed code use of Type Library interfaces etc. with a bit more documentation and explaining how I thought this through.

Tommi G

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

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

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