- #include "stdafx.h"
- #include <guiddef.h>
- #include <xstring>
- #include <ObjBase.h>
- void Guid2String(const GUID& guid, std::basic_string<TCHAR>& outputString)
- {
- TCHAR buf[39];
- swprintf(buf, sizeof(buf)/sizeof(TCHAR), _T("{%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]);
- outputString = buf;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- GUID guid;
- HRESULT hr = CoCreateGuid(&guid);
- std::basic_string<TCHAR> guidString;
- Guid2String(guid, guidString);
- return 0;
- }