GUID(Global Unique Identification) 만들기
▣ CoCreateGuid API를 이용하는 방법
'-------------------------------------------------------------------------------
' CoCreateGuid
' - Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As Any) As Long
'-------------------------------------------------------------------------------
' StringFromGUID2
' - Converts a globally unique identifier (GUID) into a string of printable characters
Private Declare Function StringFromGUID2 Lib "OLE32.DLL" (pGuid As Any, ByVal address As Long, ByVal Max As Long) As Long
Function CreateGUID() As String
Dim res As String
Dim resLen As Long
Dim guid(15) As Byte
res = Space$(128)
CoCreateGuid guid(0)
resLen = StringFromGUID2(guid(0), ByVal StrPtr(res), 128)
CreateGUID = Left$(res, resLen - 1)
End Function
' CoCreateGuid
' - Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers
Private Declare Function CoCreateGuid Lib "OLE32.DLL" (pGuid As Any) As Long
'-------------------------------------------------------------------------------
' StringFromGUID2
' - Converts a globally unique identifier (GUID) into a string of printable characters
Private Declare Function StringFromGUID2 Lib "OLE32.DLL" (pGuid As Any, ByVal address As Long, ByVal Max As Long) As Long
Function CreateGUID() As String
Dim res As String
Dim resLen As Long
Dim guid(15) As Byte
res = Space$(128)
CoCreateGuid guid(0)
resLen = StringFromGUID2(guid(0), ByVal StrPtr(res), 128)
CreateGUID = Left$(res, resLen - 1)
End Function
▣ Script를 이용하는 방법
Function CreateGUID() As String
Dim TypeLib As Object
Dim NewGuid As String
Dim StrGUID As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
NewGuid = TypeLib.guid
StrGUID = Left(NewGuid, 38)
Set TypeLib = Nothing
CreateGUID = StrGUID
End Function
Dim TypeLib As Object
Dim NewGuid As String
Dim StrGUID As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
NewGuid = TypeLib.guid
StrGUID = Left(NewGuid, 38)
Set TypeLib = Nothing
CreateGUID = StrGUID
End Function
댓글을 달아 주세요