Skip to content

Instantly share code, notes, and snippets.

@607011
Last active August 29, 2015 14:17
Show Gist options
  • Save 607011/05e09c0d0a7c5510125c to your computer and use it in GitHub Desktop.
Save 607011/05e09c0d0a7c5510125c to your computer and use it in GitHub Desktop.
Create new Windows-GUID as std::string
std::string createGUIDString(void) {
GUID guid;
HRESULT hCreateGuid = CoCreateGuid(&guid);
std::stringstream strBuf;
strBuf << std::hex << std::setw(8) << std::setfill('0')
<< guid.Data1 << "-" << guid.Data2 << "-" << guid.Data3 << "-";
for (int i = 0; i < 2; ++i)
strBuf << std::hex << std::setw(2) << std::setfill('0') << short(guid.Data4[i]);
strBuf << "-";
for (int i = 2; i < 8; ++i)
strBuf << std::hex << std::setw(2) << std::setfill('0') << short(guid.Data4[i]);
return strBuf.str();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment