|
-
Oct 16th, 2006, 03:24 AM
#1
Thread Starter
Fanatic Member
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. 
-
Oct 16th, 2006, 09:33 AM
#2
Re: Getting the GUID of a Type Library
You can use Win32_TypeLibraryAction WMI class to retrieve GUID of a Type library.
VB Code:
'Place a TextBox, Multiline = true, (set both scrollbars if you wish)
'Try under button click
Dim WMI As Object
Dim obs As Object
Dim ob As Object
Set WMI = GetObject("winmgmts:")
Set obs = WMI.InstancesOf("Win32_TypeLibraryAction")
'if you wish to find LibID of a specific library, then you can even try
'example if i am looking for Microsoft Word 10.0 Object Library
'Set obs = WMI.InstancesOf("Win32_TypeLibraryAction where Name='Microsoft Word 10.0 Object Library'")
For Each ob In obs
Text1.Text = Text1.Text & vbCrLf & "Caption" & vbTab & vbTab & ":" & vbTab & ob.Caption
Text1.Text = Text1.Text & vbCrLf & "Name" & vbTab & vbTab & ":" & vbTab & ob.Name
Text1.Text = Text1.Text & vbCrLf & "Description" & vbTab & ":" & vbTab & ob.Description
Text1.Text = Text1.Text & vbCrLf & "Language" & vbTab & ":" & vbTab & ob.Language
Text1.Text = Text1.Text & vbCrLf & "LibID" & vbTab & vbTab & ":" & vbTab & ob.LibID
Text1.Text = Text1.Text & vbCrLf & "Version" & vbTab & vbTab & ":" & vbTab & ob.Version
Text1.Text = Text1.Text & vbCrLf & vbCrLf
Next
-
Oct 16th, 2006, 09:55 AM
#3
Thread Starter
Fanatic Member
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. 
-
Oct 16th, 2006, 03:57 PM
#4
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:
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
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:
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Declare Function CLSIDFromProgID _
Lib "ole32.dll" (ByVal lpszProgID As Long, _
pCLSID As GUID) As Long
Private Declare Function StringFromCLSID _
Lib "ole32.dll" (pCLSID As GUID, lpszProgID As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim udtCLSID As GUID
Dim strCLSID As String * 255
Dim pCLSID As Long
Dim lngRet As Long
Dim strTemp As String
Dim i As Integer
'Reading the ProgID.
strTemp = Text1.Text
'Get CLSID.
lngRet = CLSIDFromProgID(StrPtr(strTemp), udtCLSID)
'Breaking the long CLSIDs helps you in comparing them
List1.AddItem Hex(udtCLSID.Data1)
List1.AddItem Hex(udtCLSID.Data2)
List1.AddItem Hex(udtCLSID.Data3)
For i = 0 To 7
List1.AddItem Hex(udtCLSID.Data4(i))
Next
'Convert CLSID to a string and get the pointer back.
lngRet = StringFromCLSID(udtCLSID, pCLSID)
'Get the CLSID string and display it.
StringFromPointer pCLSID, strCLSID
Text2.Text = strCLSID
End Sub
Private Sub StringFromPointer(pOleStr As Long, strOut As String)
Dim ByteArray(255) As Byte
Dim intTemp As Integer
Dim intCount As Integer
Dim i As Integer
intTemp = 1
'Walk the string and retrieve the first byte of each WORD.
While intTemp <> 0
CopyMemory intTemp, ByVal pOleStr + i, 2
ByteArray(intCount) = intTemp
intCount = intCount + 1
i = i + 2
Wend
'Copy the byte array to our string.
CopyMemory ByVal strOut, ByteArray(0), intCount
End Sub
Private Sub Form_Load()
Text1.Text = "Project1.Class1"
End Sub
-
Oct 17th, 2006, 02:57 AM
#5
Thread Starter
Fanatic Member
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. 
-
Oct 17th, 2006, 03:16 AM
#6
Re: Getting the GUID of a Type Library
-
Oct 17th, 2006, 03:54 AM
#7
Thread Starter
Fanatic Member
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. 
-
Oct 17th, 2006, 02:59 PM
#8
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.
-
Oct 18th, 2006, 02:43 AM
#9
Thread Starter
Fanatic Member
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. 
-
Oct 18th, 2006, 05:57 AM
#10
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:
Dim tliob As Object
Private Sub Command1_Click()
'your dll file "[path]\name" here
tliob.ContainingFile = "C:\Documents and Settings\Administrator\Desktop\test\Project1.dll"
Text1.Text = tliob.GUID
End Sub
Private Sub Form_Load()
Set tliob = CreateObject("TLI.TypeLibInfo")
End Sub
I hope I am correct this time.
-
Oct 18th, 2006, 06:00 AM
#11
Re: Getting the GUID of a Type Library
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|