VB and VBA Users Source Code: Converting Class IDs to a Prog IDs and back
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Converting Class IDs to a Prog IDs and back
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, January 08, 2001
Hits:
631
Category:
Windows API
Article:
To convert a Class ID to a prog ID and back use the following routines. Note, a demonstration routine can be found at the bottom of this post: Private Declare Function ProgIDFromCLSID Lib "ole32.dll" (CLSID As Any, lProgID As Long) As Long Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lProgID As Long, CLSID As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (vDest As Any, vSource As Any, ByVal lBytes As Long) Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal lpszProgID As Long, pCLSID As Any) As Long Private Declare Function StringFromCLSID Lib "ole32.dll" (pCLSID As Any, lpszProgID As Long) As Long Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long) 'Purpose : Converts a string Class ID (inc. braces) into as string Prog ID 'Inputs : sCLSID The Class ID to find the Prog ID of. 'Outputs : Returns the Prog ID as a string 'Author : Andrew Baker 'Date : 09/01/2001 00:19 'Notes : 'Revisions : Function CLSIDToProgID(ByVal sCLSID As String) As String Dim lFirstChar As Long, lLastChar As Long, iChar As Integer Dim abGuid(15) As Byte 'Convert string to a binary CLSIDFromString StrPtr(sCLSID), abGuid(0) 'Convert to a string and get pointer to result ProgIDFromCLSID abGuid(0), lFirstChar lLastChar = lFirstChar 'Find end of string Do CopyMemory iChar, ByVal lLastChar, 2 If iChar Then lLastChar = lLastChar + 2 End If Loop While iChar CLSIDToProgID = Space$((lLastChar - lFirstChar) \ 2) CopyMemory ByVal StrPtr(CLSIDToProgID), ByVal lFirstChar, (lLastChar - lFirstChar) End Function 'Purpose : Converts a string Prog ID (inc. braces) into as string Class ID 'Inputs : sProgID The Prog ID to find the Class ID of. 'Outputs : Returns the Class ID as a string 'Author : Andrew Baker 'Date : 09/01/2001 00:19 'Notes : 'Revisions : Function ProgIDToCLSID(ByVal sProgID As String) As String Dim lFirstChar As Long, lLastChar As Long Dim iChar As Integer Dim abGuid(15) As Byte 'Get CLSID CLSIDFromProgID StrPtr(sProgID), abGuid(0) 'Convert to a string and get pointer to result StringFromCLSID abGuid(0), lFirstChar 'Find end of string lLastChar = lFirstChar Do CopyMemory iChar, ByVal lLastChar, 2 If iChar Then lLastChar = lLastChar + 2 End If Loop While iChar ProgIDToCLSID = Space$((lLastChar - lFirstChar) \ 2) CopyMemory ByVal StrPtr(ProgIDToCLSID), ByVal lFirstChar, (lLastChar - lFirstChar) End Function 'Demonstration routine Sub Test() Dim sProgID 'Get the Prog ID for Excel sProgID = CLSIDToProgID("{00024500-0000-0000-C000-000000000046}") Debug.Print sProgID 'Get the Class ID for Excel (as above) Debug.Print ProgIDToCLSID(sProgID) End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder