Results 1 to 11 of 11

Thread: Getting the GUID of a Type Library

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Getting the GUID of a Type Library

    Is there a way to obtain the GUID for a type library?

    This is actually in the contect of ActiveX class projects. So I need the most recent version registered...

    IS this possible?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Getting the GUID of a Type Library

    You can use Win32_TypeLibraryAction WMI class to retrieve GUID of a Type library.

    VB Code:
    1. 'Place a TextBox, Multiline = true, (set both scrollbars if you wish)
    2. 'Try under button click
    3. Dim WMI As Object
    4. Dim obs As Object
    5. Dim ob As Object
    6.  
    7. Set WMI = GetObject("winmgmts:")
    8. Set obs = WMI.InstancesOf("Win32_TypeLibraryAction")
    9.  
    10. 'if you wish to find LibID of a specific library, then you can even try
    11. 'example if i am looking for Microsoft Word 10.0 Object Library
    12. 'Set obs = WMI.InstancesOf("Win32_TypeLibraryAction where Name='Microsoft Word 10.0 Object Library'")
    13.  
    14. For Each ob In obs
    15.  
    16.     Text1.Text = Text1.Text & vbCrLf & "Caption" & vbTab & vbTab & ":" & vbTab & ob.Caption
    17.     Text1.Text = Text1.Text & vbCrLf & "Name" & vbTab & vbTab & ":" & vbTab & ob.Name
    18.     Text1.Text = Text1.Text & vbCrLf & "Description" & vbTab & ":" & vbTab & ob.Description
    19.     Text1.Text = Text1.Text & vbCrLf & "Language" & vbTab & ":" & vbTab & ob.Language
    20.     Text1.Text = Text1.Text & vbCrLf & "LibID" & vbTab & vbTab & ":" & vbTab & ob.LibID
    21.     Text1.Text = Text1.Text & vbCrLf & "Version" & vbTab & vbTab & ":" & vbTab & ob.Version
    22.     Text1.Text = Text1.Text & vbCrLf & vbCrLf
    23.  
    24. Next
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Getting the GUID of a Type Library

    Thanks for your reply.

    However it does not seem to list all registered type libraries...?

    I have compiled various ActiveX DLL projects. How do I obtain the details for those?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Getting the GUID of a Type Library

    Oh , it was my mistake that I forgot to mention, not all DLLs (or COM components) need to be registered. Though I am not sure about this, but I saw in one of the post here which said this. Maybe a more experienced member could tell you exactly.

    As for your question, there are 2 APIs, CLSIDFromProgID and ProgIDFromCLSID (vice versa of former).

    Firstly, GUID is logically divided into 4 parts, Long, Int, Int, and Byte array.
    VB Code:
    1. Private Type GUID
    2.     Data1 As Long
    3.     Data2 As Integer
    4.     Data3 As Integer
    5.     Data4(7) As Byte
    6. End Type
    Furthermore, COM supports the concept of Binary Compatibility where two objects with different GUIDs can be used interchangeably. [Source here]. Not really sure what it meant, but I am interested in learning if you could raise this question.

    A small example:

    1) Create a new VB 6 Active DLL project.

    2) It will create Class1, by default.

    3) Compile the project. Now, you have a test component: Project1.dll, which contains a COM class (Project1.Class1 - this is known as ProgID!!). And you not registering the DLL and this method will work on both registered and unregistered DLLs.

    4) Create a new Standard EXE project in Visual Basic.

    5) Add twoTextBoxes (one for ProgID, one for CLSID/GUID), one Command button, and one ListBox (to show divisions of CLSID) to Form1.

    6) Paste the following code:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type GUID
    4.     Data1 As Long
    5.     Data2 As Integer
    6.     Data3 As Integer
    7.     Data4(7) As Byte
    8. End Type
    9.  
    10. Private Declare Function CLSIDFromProgID _
    11.     Lib "ole32.dll" (ByVal lpszProgID As Long, _
    12.     pCLSID As GUID) As Long
    13.  
    14. Private Declare Function StringFromCLSID _
    15.     Lib "ole32.dll" (pCLSID As GUID, lpszProgID As Long) As Long
    16.  
    17. Private Declare Sub CopyMemory Lib "kernel32" Alias _
    18.     "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    19.  
    20. Private Sub Command1_Click()
    21.  
    22.     Dim udtCLSID As GUID
    23.     Dim strCLSID As String * 255
    24.     Dim pCLSID As Long
    25.     Dim lngRet As Long
    26.     Dim strTemp As String
    27.     Dim i As Integer
    28.  
    29.     'Reading the ProgID.
    30.     strTemp = Text1.Text
    31.  
    32.     'Get CLSID.
    33.     lngRet = CLSIDFromProgID(StrPtr(strTemp), udtCLSID)
    34.  
    35.     'Breaking the long CLSIDs helps you in comparing them
    36.     List1.AddItem Hex(udtCLSID.Data1)
    37.     List1.AddItem Hex(udtCLSID.Data2)
    38.     List1.AddItem Hex(udtCLSID.Data3)
    39.     For i = 0 To 7
    40.         List1.AddItem Hex(udtCLSID.Data4(i))
    41.     Next
    42.  
    43.     'Convert CLSID to a string and get the pointer back.
    44.     lngRet = StringFromCLSID(udtCLSID, pCLSID)
    45.  
    46.     'Get the CLSID string and display it.
    47.     StringFromPointer pCLSID, strCLSID
    48.     Text2.Text = strCLSID
    49.  
    50. End Sub
    51.  
    52. Private Sub StringFromPointer(pOleStr As Long, strOut As String)
    53.    
    54.     Dim ByteArray(255) As Byte
    55.     Dim intTemp As Integer
    56.     Dim intCount As Integer
    57.     Dim i As Integer
    58.  
    59.     intTemp = 1
    60.  
    61.     'Walk the string and retrieve the first byte of each WORD.
    62.     While intTemp <> 0
    63.         CopyMemory intTemp, ByVal pOleStr + i, 2
    64.         ByteArray(intCount) = intTemp
    65.         intCount = intCount + 1
    66.         i = i + 2
    67.     Wend
    68.  
    69.     'Copy the byte array to our string.
    70.     CopyMemory ByVal strOut, ByteArray(0), intCount
    71.    
    72. End Sub
    73.  
    74. Private Sub Form_Load()
    75.          
    76.     Text1.Text = "Project1.Class1"
    77. End Sub
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Getting the GUID of a Type Library

    Thanks again for your reply...but I'm not sure it does what I want.

    I would give it a ProgID (i.e. TypeLibraryName.ClassName) and it would give me the GUID of the class...but not the GUID of the Type Library itself...wouldn't it?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Getting the GUID of a Type Library

    huh??

  7. #7

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Getting the GUID of a Type Library

    When an ActiveX DLL project is compiled, each public class has a GUID and the project itself (i.e. the type library) has a GUID. I need the type library GUID and not the individual class ID's.

    The first solution you posted gave me the Type Library ID for various libraries but only a small subset of those actually registered on my system.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  8. #8
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Getting the GUID of a Type Library

    Can you show me an example, GUID of Library itself?? Like one I can look for in Regedit myself.

    Frankly, I am sure that ProgID and GUID/CLSID is created for classes within DLLs and not for the libraries, because I was searching for the similar thing few days back.
    Show Appreciation. Rate Posts.

  9. #9

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Getting the GUID of a Type Library

    In the registry, go to HKEY_CLASSES_ROOT\TypeLib

    In there, you will find listed the GUID for each registered type library with the binary compatible versions listed as sub folders.

    Also, if you open a VB project file in notepad, you will see each reference listed with a GUID. Once for each type library registered (not for each class). This GUID can be found in the above section of the registry.
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  10. #10
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Getting the GUID of a Type Library

    oh,oh oh, sorry, I forgot about it. You are right.

    Like I posted before that not all Dlls need to be registered, so probably that's the case with you that the first example (using WMI) was not showing your custom libraries.

    But VB do provide a functionality to check the TypeLib Information. I tried with a small ActiveX dll file and the result matched the value in the specified Reg path.
    VB Code:
    1. Dim tliob As Object
    2.  
    3. Private Sub Command1_Click()
    4.  
    5. 'your dll file "[path]\name" here
    6. tliob.ContainingFile = "C:\Documents and Settings\Administrator\Desktop\test\Project1.dll"
    7.  
    8. Text1.Text = tliob.GUID
    9.  
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13.  
    14.     Set tliob = CreateObject("TLI.TypeLibInfo")
    15.  
    16. End Sub
    I hope I am correct this time.
    Show Appreciation. Rate Posts.

  11. #11
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Getting the GUID of a Type Library

    Just to make sure I am not wrong, I searched a little and found this - MSDN Mag - Inspect COM Components Using the TypeLib Information Object Library
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width