Hi all.
Trying to generate a UUID/GUID using some of the Windows API functionality following MSDN pages.
So far I can fill the UUID group, but am having an issue converting it to a string, it keeps returning rubbish. Perhaps I have prototyped incorrectly or have completely misunderstood what it is doing?
Below is the code, can someone point me in the right direction or point out where I went wrong?
GenerateUUID FUNCTION ! Declare Procedure
!map
! moved to Inside the Global Map, doesn't work here
! map
! ! used by the UUIDModule
! module('Rpcrt4.dll') ! Rpcrt4.dll
! UuidCreate(*UUIDGT),ULONG,PASCAL,RAW,NAME('UuidCreate')
! UuidToString(*UUIDGT,*CSTRING),ULONG,PASCAL,RAW,NAME('UuidToStringA')
! !RpcStringFree(*LONG),ULONG,PASCAL,RAW,NAME('RpcStringFreeA')
! end
! end
!local variables
! UUID Structure
! GUID: 6B29FC40-CA47-1067-B31D-00DD010662DA
!
! https://msdn.microsoft.com/en-us/library/windows/desktop/aa379358(v=vs.85).aspx
!
UUIDGT GROUP,TYPE
Data1 ULONG ! the first 8 hexadecimal digits
Data2 USHORT ! the first group of 4 hexadecimal digits
Data3 USHORT ! the second group of 4 hexadecimal digits
Data4 BYTE,DIM(8) ! Array of eight elements. The first two elements contain the third group of 4 hexadecimal digits
END ! the remaining six elements contain the final 12 hexadecimal digits.
! NOTE: Data4 is defined as an "unsigned char" of 8 elements.
! An unsigned char is a (unsigned) byte value (0 to 255).
! You may be thinking of "char" in terms of being a "character"
! but it is really a numerical value.
! The regular "char" is signed, so you have 128 values,
! and these values map to characters using ASCII encoding.
! https://stackoverflow.com/questions/75191/what-is-an-unsigned-char
! equates for return value of RPC_STATUS
RPC_S_OK EQUATE(0) !pretty sure it's 0 but can't confirm
!RPC_S_OUT_OF_MEMORY
!RPC_S_UUID_LOCAL_ONLY
!RPC_S_UUID_NO_ADDRESS
UUID LIKE(UUIDGT),AUTO
UUIDCString CSTRING(50) !it should be 37 (numbers and separators) + null terminator
UUIDString STRING(50)
RPC_STATUS LONG
CODE ! Begin processed code
!generate UUID/GUID
! UuidCreate
! https://msdn.microsoft.com/en-us/library/windows/desktop/aa379205(v=vs.85).aspx
! UuidToString
! https://msdn.microsoft.com/en-us/library/windows/desktop/aa379352(v=vs.85).aspx
! RpcStringFree
! https://msdn.microsoft.com/en-us/library/windows/desktop/aa378483(v=vs.85).aspx
! unresolved external for UuidCreate and UuidToString
! requires Rpcrt4.lib to be in folder and added to project.
RPC_STATUS = UuidCreate(UUID)
if RPC_STATUS = RPC_S_OK
DO DisplayDecimalUUID !to see if the GROUP has been populated
RPC_STATUS = UuidToString(UUID,UUIDCstring) !<<<< this fails
if RPC_STATUS = RPC_S_OK
UUIDString = UUIDCstring
message('uuid is: ' & clip(left(uuidstring)))
!RPC_STATUS = RpcStringFree(UUIDCstring) !
return clip(left(uuidstring))
else
message('uuidtostring failed')
return ''
end
else
message('uuid generation failed')
return ''
end
DisplayDecimalUUID ROUTINE
! I think this shows the UUID correctly in decimal format
message('UUID.data1: ' & uuid.data1 & |
'|UUID.data2: ' & uuid.data2 & |
'|UUID.data3: ' & uuid.data3 & |
'|UUID.data4: ' & uuid.data4[1] & '/' & uuid.data4[2] & '/' & uuid.data4[3] & '/' & uuid.data4[4] & '/' & |
uuid.data4[5] & '/' & uuid.data4[6] & '/' & uuid.data4[7] & '/' & uuid.data4[8] )
The MSDN doco states the application is responsible to free the memory for the returned string, not sure how to go about creating a pointer to a pointer for the RpcStringFree function.
FYI, still on C5.5PE
Cheers,
Andrew.