* -- returns a Globally Unique IDentifier (GUID)
local cData1, cData2, cData3, cData4, cData5, cDataAll
private PGuid
store "" to cData1, cData2, cData3, cData4, cData5, cDataAll
* -- declare external function
DECLARE INTEGER CoCreateGuid IN OLE32.DLL STRING @pGuid
* -- Initialize the buffer that will hold the GUID with nulls
pGuid = REPLICATE(CHR(0),17)
* -- Call CoCreateGuid
IF CoCreateGuid(@pGuid) = 0 && success
* -- Store the first eight characters of the GUID in data1
cData1 = RIGHT(TRANSFORM(strtolong(LEFT(pGuid,4)),"@0"),8)
* -- Store the first group of four characters of the GUID in data2
cData2 = RIGHT(TRANSFORM(strtolong(SUBSTR(pGuid,5,2)),"@0"),4)
* -- Store the second group of four characters of the GUID in data3
cData3 = RIGHT(TRANSFORM(strtolong(SUBSTR(pGuid,7,2)),"@0"),4)
* -- Store the third group of four characters of the GUID in data4
cData4 = RIGHT(TRANSFORM(strtolong(SUBSTR(pGuid,9,1)),"@0"),2) + ;
RIGHT(TRANSFORM(strtolong(SUBSTR(pGuid,10,1)),"@0"),2)
* -- Initialize data5 to a null string
cData5 = ""
* -- Convert the final 12 characters of the GUID and store in data5
FOR nGuidLen = 1 TO 6
cData5=cData5+RIGHT(TRANSFORM(strtolong(SUBSTR(pGuid,10+nGuidLen,1))),2)
ENDFOR
* -- Check the length of data5. If less than 12, the final 12-len(data5)
* -- characters are '0'
IF LEN(cData5) < 12
cData5=cData5+REPLICATE("0",12-LEN(cData5))
ENDIF
* -- Assemble the GUID into a string
cDataAll = cData1+"-"+cData2+"-"+cData3+"-"+cData4+"-"+cData5
ENDIF
* -- Done with the call to CoCreateGuid, so clear the DLLs from memory
CLEAR DLLS
return cDataAll
*******************
FUNCTION strtolong
* -- Passed: 4-byte character string (lcLongstr) in low-high ASCII format
* -- Returns: long integer value
* -- Example:
* -- m.longstr = "1111"
* -- m.longval = strtolong(m.longstr)
PARAMETERS lcLongstr
LOCAL lnByte, lnRetval
lnRetval = 0
FOR lnByte = 0 TO 24 STEP 8
lnRetval = lnRetval + (ASC(lcLongstr) * (2^lnByte))
lcLongstr = RIGHT(lcLongstr, LEN(lcLongstr) - 1)
NEXT
RETURN lnRetval