View Information Stored in Type Libraries

You can use this method to view all the CoClasses, and Interfaces present in thetype library.

In order to run this tech tip you need following things:
(a) VB5 or VB6
(b) Reference to Type Lib information object component (TLIBINF32.dll).

This method takes in the name of the com component (or dll) or the type libraryfor which you wish to view the information. It stuffs all the information into alist box (lstTypeLibDetails).

 Private Sub PopulateTypeLibInfo(ByVal strTypeLibName As String)    On Error GoTo ErrorHandler    Dim pTypeLibInfo As TLI.TypeLibInfo     ' Pointer to TypeLibrary Info object    Dim pCoClasses As TLI.CoClasses         ' Pointer to Coll. of CoClasses    Dim pCoClassInfo As TLI.CoClassInfo     ' Pointer to a CoClass    Dim pInterfaces As TLI.Interfaces       ' Pointer to Coll. of Interfaces for a CoClass    Dim pInterfaceInfo As TLI.InterfaceInfo ' Pointer to a Interface for aCoClass    Dim lClassCount As Long    Dim lInterfaceCount As Long    Dim lClassIndex As Long    Dim lInterfaceIndex As Long    Dim strStringToAdd As String    ' Make sure that name is proper    If (strTypeLibName = "") Then        Exit Sub    End If    ' Get the pointer to type library information for the specified file    Set pTypeLibInfo = TypeLibInfoFromFile(strTypeLibName)    strStringToAdd = "Type Library : " & pTypeLibInfo.Name & Space(1) &pTypeLibInfo.Guid    ' Add this Type Lib name to the list control    lstTypeLibDetails.AddItem strStringToAdd    ' Add one empty line for clarity in the UI    lstTypeLibDetails.AddItem ""    ' Get the pointer to Com Classes with in this type library    Set pCoClasses = pTypeLibInfo.CoClasses    ' Take the count of total no. of CoClasses in this Type Lib    lClassCount = pCoClasses.Count    ' Traverse all the CoClasses in this type lib info to get the information    For lClassIndex = 1 To lClassCount        If (lClassIndex > 1) Then            ' Add one empty line for clarity in the UI            lstTypeLibDetails.AddItem ""        End If        Set pCoClassInfo = pCoClasses.Item(lClassIndex)        strStringToAdd = "CoClass : " & pCoClassInfo.Name & Space(1) &pCoClassInfo.Guid        ' Add this CoClass name to the list control        lstTypeLibDetails.AddItem strStringToAdd        ' Take out the Interfaces collection out for this CoClass        Set pInterfaces = pCoClassInfo.Interfaces        ' Take the count of total no. of CoClasses in this Type Lib        lInterfaceCount = pInterfaces.Count        For lInterfaceIndex = 1 To lInterfaceCount            Set pInterfaceInfo = pInterfaces.Item(lInterfaceIndex)            strStringToAdd = vbTab & " Interface : " & pInterfaceInfo.Name &Space(1) & pInterfaceInfo.Guid            ' Add this CoClass name to the list control            lstTypeLibDetails.AddItem strStringToAdd            Set pInterfaceInfo = Nothing        Next lInterfaceIndex        ' Release the CoClassInfo pointer        Set pCoClassInfo = Nothing        Set pInterfaces = Nothing    Next lClassIndex    ' Release the pointers    Set pCoClasses = Nothing    Set pTypeLibInfo = Nothing    Exit SubErrorHandler:    ' Release the pointers    Set pInterfaceInfo = Nothing    Set pCoClassInfo = Nothing    Set pInterfaces = Nothing    Set pCoClasses = Nothing    Set pTypeLibInfo = Nothing    ' Display the complete error message    MsgBox "Number      : " & Err.Number & vbCrLf & _           "Description : " & Err.Description & vbCrLf & _           "Source      : " & Err.Source & vbCrLf & _           "Help File   : " & Err.HelpFile & vbCrLf & _           "Last DLL Err: " & Err.LastDllError & vbCrLf, vbCritical + vbOKOnly,"Type Lib Error"End Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: