Here is the required function to generate UUID in powerbuilder
// External function
FUNCTION long uuidCreate(ref sr_uuid astr_uuid) LIBRARY "Rpcrt4.dll" ALIAS FOR "UuidCreate"
// Function to generate UUID
Function of_generate_uuid(string as_type)
Long ll_rc
sr_uuid lstr_uuid
string ls_guid = ""
constant long RPC_S_OK = 0
constant long RPC_S_UUID_LOCAL_ONLY = 1824
constant long RPC_S_UUID_NO_ADDRESS = 1739
ll_rc = uuidCreate(lstr_uuid)
IF ll_rc <> RPC_S_OK THEN
setNull(ls_GUID)
ELSE
If as_type = 'F' Then
ls_GUID = right("00000000" + of_tohex(lstr_uuid.data1), 8)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data2), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data3), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data4[1]), 4)
ls_GUID += "-" + right("0000" + of_tohex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// output example : 00003B93-2641-477A-C99E-A2FFEBEB214A
Elseif as_type = 'R' Then
ls_GUID = right("00000000" + of_tohex(lstr_uuid.data1), 8)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data2), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data3), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data4[1]), 4)
ls_GUID += right("0000" + of_tohex(lstr_uuid.data4[2]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[3]), 4) &
+ right("0000" + of_tohex(lstr_uuid.data4[4]), 4)
ls_GUID = upper(ls_GUID)
// output example : 00003B932641477AC99EA2FFEBEB214A
End If
End If
Return ls_guid
// How to call
String ls_uuid
ls_uuid = of_generate_uuid('R') // Returns 00003B932641477AC99EA2FFEBEB214A
ls_uuid = of_generate_uuid('F') // Returns 00003B93-2641-477A-C99E-A2FFEBEB214A
It works from PB 10.5, PB 11.5 & PB 2017 R3, which I've tested.
Happiness Always
BKR Sivaprakash