Skip to content

Instantly share code, notes, and snippets.

@pmachapman
Created July 7, 2017 08:08
Show Gist options
  • Save pmachapman/32943d3cc56c2fa7f7d980e9308c53d0 to your computer and use it in GitHub Desktop.
Save pmachapman/32943d3cc56c2fa7f7d980e9308c53d0 to your computer and use it in GitHub Desktop.
Generates a UUID
#include <rpc.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
/* Declare variables */
UUID uuid;
RPC_STATUS result;
/* Display a help message */
if (argc == 2 && (!strcmp(argv[1], "/?") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
{
printf("Generates and displays a uuid\n");
printf("\n");
printf("UUID\n");
exit(1);
}
// Generate the uuid
result = UuidCreate(&uuid);
// Display the uuid in the format we love
printf("%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
uuid.Data1, uuid.Data2, uuid.Data3, uuid.Data4[0], uuid.Data4[1], uuid.Data4[2],
uuid.Data4[3], uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]);
// Return the result of the uuid generation
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment