I was previously using:
Public Declare Function StringFromGUID2 Lib "ole32.dll" _
(rclsid As GUID, ByVal lpsz As Long, ByVal cbMax As Long) As Long
under Access 2007 on both 32 bit and 64 bit Windows to generate GUIDs for me.
Where GUID Is defined as:
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
(since VT_GUID wasn’t supported in VBA for variants)
I’ve now got a new machine that is set up with Access 2010 64 bit and this stuff is now broken.
What is the equivalent code to do this under Access 2010 64 bit?
I have added the PtrSafe attribute as required:
Public Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" _
(rclsid As GUID, ByVal lpsz As Long, ByVal cbMax As Long) As Long
This causes a type mismatch at the actual call:
Dim rc As Long
Dim stGuid As String
' 39 chars for the GUID plus room for the Null char
stGuid = String$(40, vbNullChar)
rc = StringFromGUID2(rclsid, StrPtr(stGuid), Len(stGuid) - 1)
Which is to be expected since StrPtr will return a LongPtr on 64 bit and a Long on 32 bit systems.
I’m not a full-time developer so I’m not sure what is the most appropriate way to create GUID strings in a way that will work on both 32 and 64 bit systems.
StringFromGUID is available to the Access application.
Application.StringFromGUID Method (Access)
You can even use it in queries.