Skip to content

Instantly share code, notes, and snippets.

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