Generate a random 36-character Global Unique IDentifier (GUID) string.
Public Declare Function RNG_Guid Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal nOptions As Long) As Long
nRet = RNG_Guid(strOutput, nOutChars, nOptions)
long __stdcall RNG_Guid(char *szOutput, long nOutChars, long nOptions);
If successful, the return value is the number of characters in or required for the output string (always 36); otherwise it returns a negative error code.
Public Function rngGuid
() As String
static std::string dipki::Rng::Guid ()
static Rng.guid()
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
A Global Unique IDentifier (GUID) is also called a version 4 Universally Unique IDentifier (UUID) and is defined in section 4.4 of [RFC4122].
The output is always a 36-character string of the form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" where 'x' is a hexadecimal digit [0-9a-f]
.
The constant PKI_RNG_GUID_CHARS equal to 36 is defined for convenience.
It is an error (SHORT_BUF_ERROR) if the output buffer is too short.
Dim strGuid As String
strGuid = String(PKI_RNG_GUID_CHARS, " ")
Call RNG_Guid(strGuid, Len(strGuid), 0)
Debug.Print strGuid
The output will be different each time. For example
9d67804a-4d8f-40c2-8f7d-5f05f90cb228 85291113-b97f-4d30-8892-76d556801372 fc4272a5-c731-4b96-9c7c-450fad9a29c0
Dim i As Integer
For i = 1 To 5
Debug.Print rngGuid()
Next