Skip to content

Instantly share code, notes, and snippets.

@mrousavy
Created April 28, 2017 09:27
Show Gist options
  • Save mrousavy/c1d5ddda0f49ce945369a79613a7252f to your computer and use it in GitHub Desktop.
Save mrousavy/c1d5ddda0f49ce945369a79613a7252f to your computer and use it in GitHub Desktop.
Create a random GUID - C
#include <stdio.h>
#include <unknwn.h>
void wmain(int argc, wchar_t* argv[])
{
GUID guid;
wchar_t wzGuid[39] = { 0 };
int count = (1 < argc) ? _wtoi(argv[1]) : 1;
for (int i = 0; i < count; ++i)
{
if (SUCCEEDED(CoCreateGuid(&guid)) && StringFromGUID2(&guid, wzGuid, sizeof(wzGuid) / sizeof(wzGuid[0])))
{
_putws(wzGuid);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment