With Acknowledgements to Randy Rogers and Graham Dawson, here’s how to add a function to create GUIDs to your app.
-
Use LibMaker to create a .lib file for rpcrt4.lib, which you will find in Windows\SYSWOW64
-
Add rpcrt4.lib to the libraries in your solution
-
Add this to Global Embeds After Global Includes
UUIDGT GROUP,TYPE
Data1 ULONG
Data2 USHORT
Data3 USHORT
Data4 BYTE,DIM(8)
end
- Add this to the global embed Inside the Global Map
module('Rpcrt4.dll')
UuidCreate(*UUIDGT),ULONG,PASCAL,RAW,NAME('UuidCreate')
UuidToString(*UUIDGT,*LONG),ULONG,PASCAL,RAW,NAME('UuidToStringA')
RpcStringFree(*LONG),ULONG,PASCAL,RAW,NAME('RpcStringFreeA')
end
- Create a source procedure called Get_GUID, with prototype
(),string
(don’t miss the comma!) and parameters ()
Get_GUID PROCEDURE(),STRING
Data section is:
RPC_S_OK EQUATE(0)
UUID LIKE(UUIDGT),AUTO
RPC_STATUS LONG
Code section is:
clear(UUID,-1)
RPC_STATUS = UuidCreate(UUID)
if RPC_STATUS = RPC_S_OK
return GUIDToString(UUID)
end
return '' !failed
- Create a source procedure called GUIDToString with prototype
(*UUIDGT pUuid),string
, parameters
(*UUIDGT pUuid)
GUIDToString PROCEDURE(*UUIDGT pUuid)
Data section is:
RPC_S_OK EQUATE(0)
lResult LONG
lpszUuid LONG
szUuid &CSTRING
sUuid STRING(36)
Code section is:
lResult = UuidToString(pUuid,lpszUuid) !address(lpszUuid))
IF lResult = RPC_S_OK
szUuid &= (lpszUuid)
sUuid = szUuid
lResult = RpcStringFree(lpszUuid)
END
RETURN '{' & upper(sUuid) & '}'
Notes: You can combine the two procedures into one if you will always want a string version of the GUID.
I have added braces around my GUID just because that is what I need. You may not, and you may also prefer to get the result in lower rather than upper case.