VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get GUID string

by Bogdan Chernyachuk (2 Submissions)
Category: OLE/COM/DCOM/Active-X
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (11 Votes)

Generates Global Unique ID - when you want to create an identifier which will never repeat all over the word , you will find this usefull.

Code Returns
Returns Global Unique ID in string format (the same as the format of ClassID written in registry).
API Declarations
Public Type GUID ' a structure for Global Uniq. ID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0, 7) As Byte
End Type
Declare Function CoCreateGuid Lib "ole32" (ByRef lpGUID As GUID) As Long
Declare Function StringFromGUID2 Lib "ole32" (ByRef lpGUID As GUID, ByVal lpStr As String, ByVal lSize As Long) As Long

Rate Get GUID string

Public Function GetNewGUIDStr() As String
Dim pGuid As GUID
Dim lResult As Long
Dim s As String
  
  'this is a buffer string to be passed in API function
  '100 chars will be enough
  s = String(100, " ")
  'creating new ID and obtaining result in pointer to GUID 
  lResult = CoCreateGuid(pGuid)
  'converting GUID structure to string
  lResult = StringFromGUID2(pGuid, s, 100)
  'removing all trailing blanks
  s = Trim(s)
  'converting a sting from unicode
  GetNewGUIDStr = StrConv(s, vbFromUnicode)
  
End Function

Download this snippet    Add to My Saved Code

Get GUID string Comments

No comments have been posted about Get GUID string. Why not be the first to post a comment about Get GUID string.

Post your comment

Subject:
Message:
0/1000 characters