- typedef struct _GUID {
- unsigned long Data1;
- unsigned short Data2;
- unsigned short Data3;
- unsigned char Data4[ 8 ];
- } GUID;
-
-
-
- #include "stdafx.h"
- #include "objbase.h"
- #include <string>
- using namespace std;
- std::string GuidToString(const GUID &guid)
- {
- char buf[64] = {0};
- sprintf_s(buf,sizeof(buf),"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
- 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 std::string(buf);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- GUID guid;
- CoCreateGuid(&guid);
- std::string s = GuidToString(guid);
- printf(s.c_str());
- system("pause");
- return 0;
- }