[AccessD] Create GUID (was: wizard use in runtimes (A2K3))

Gustav Brock Gustav at cactus.dk
Mon Jul 17 13:27:45 CDT 2006


Hi Marty

Strange. I copied/pasted your code into a module in A97 on WinXP Pro SP2.
But no GUID, only three chars returned.

/gustav

>>> martyconnelly at shaw.ca 17-07-2006 18:40:34 >>>
Both methods work for me on Access97 and 2003 WinXP SP2.
My method was kind of old dating back to 1999 or 2000
Maybe a difference in one of the dll's

However CoCreateGuid seems to be the more prevalent 
method used today.



Gustav Brock wrote:

>Hi Marty
>
>That CreateGuid doesn't work for me - returns three chars only.
>We use this function which also looks much simpler to me:
>
>Public Type GUID
>  Data1         As Long
>  Data2         As Integer
>  Data3         As Integer
>  Data4(0 To 7) As Byte
>End Type
>
>Private Declare Function CoCreateGuid Lib "ole32.dll" ( _
>  ByRef pguid As GUID) As Long
>  
>Private Declare Function StringFromGUID2 Lib "ole32.dll" ( _
>  ByRef rguid As Any, _
>  ByVal lpstrClsId As Long, _
>  ByVal cbMax As Long) As Long
>
>Public Function GetGUIDString() As String
>
>' Create a GUID and return its string representation.
>'
>' 2002-12-15. Cactus Data ApS, CPH.
>
>  ' Length of GUID string per definition.
>  Const clngGUID    As Long = 38
>  ' Length of buffer with added space for zero terminator.
>  Const clngBuffer  As Long = clngGUID + 1
>  
>  Dim udtGuid       As GUID
>  Dim strGUID       As String * clngGUID
>  Dim abytGUID()    As Byte
>  
>  ' Dim byte array.
>  abytGUID() = String(clngBuffer, vbNullChar)
>  ' Create GUID.
>  If CoCreateGuid(udtGuid) = 0 Then
>    ' GUID was successfully created.
>    If StringFromGUID2(udtGuid, VarPtr(abytGUID(0)), clngBuffer) = clngBuffer Then
>      ' GUID was successfully copied into byte array abytGUID in Unicode.
>      ' Convert byte array to Ansi GUID string stripping zero terminator.
>      strGUID = abytGUID
>    End If
>  End If
>  
>  GetGUIDString = strGUID
>
>End Function
>
>Performance is about 100000 GUIDs/second/GHz
>
>/gustav
>
>  
>
>>>>martyconnelly at shaw.ca 17-07-2006 02:41:25 >>>
>>>>        
>>>>
>There were some service pack changes Office 2003 SP2 to acwizmain.mde.
>I  doubt if it was this, http://support.microsoft.com/kb/821549 
>
>However if you just need a random query name why not just create a GUID 
>string
>
>'Paul Brower - 02152001
>Private Const RPC_S_OK As Long = 0&
>Private Const RPC_S_UUID_LOCAL_ONLY As Long = 1824&
>Private Const RPC_S_UUID_NO_ADDRESS As Long = 1739&
>Private Type GUID
>  Data1 As Long
>  Data2 As Integer
>  Data3 As Integer
>  Data4(7) As Byte
>End Type
>
>Private Declare Function UuidCreate& Lib "rpcrt4" (lpGUID As GUID)
>Private Declare Function UuidToString& Lib "rpcrt4" Alias 
>"UuidToStringA" (lpGUID As GUID, lpGUIDString&)
>Private Declare Function RpcStringFree& Lib "rpcrt4" Alias 
>"RpcStringFreeA" (lpGUIDString&)
>Private Declare Function lstrlen& Lib "kernel32" Alias "lstrlenA" (ByVal 
>lpString&)
>Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" 
>(lpDest As Any, lpSource As Any, ByVal cBytes&)
>
>Public Function CreateGUID() As String
>'More GUID routines here
>' http://www.trigeminal.com/code/guids.bas 
>
>  Dim nGUID As GUID, lpStrGUID&, nStrLen&, sGUID$
>  Dim sBuffer() As Byte, bNoError As Boolean
>
>
>  If UuidCreate(nGUID) <> RPC_S_UUID_NO_ADDRESS Then
>    If UuidToString(nGUID, lpStrGUID) = RPC_S_OK Then
>      nStrLen = lstrlen(lpStrGUID)
>      ReDim sBuffer(nStrLen - 1) As Byte
>      CopyMemory sBuffer(0), ByVal lpStrGUID, nStrLen
>      Call RpcStringFree(lpStrGUID)
>      sGUID = StrConv(sBuffer, vbUnicode)
>      CreateGUID = UCase$(sGUID)
>      Exit Function
>    End If
>  End If
>  CreateGUID = "Error"
>End Function





More information about the AccessD mailing list