Last active
August 29, 2015 14:17
-
-
Save 607011/05e09c0d0a7c5510125c to your computer and use it in GitHub Desktop.
Create new Windows-GUID as std::string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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