[C++]C++ Create GUID
GUID *pguid = new GUID;
CoCreateGuid(pguid);
// Convert the GUID to a string
UuidToString(pguid, (RPC_WSTR*)&guidStr);
delete pguid;
return wstring(guidStr);
}
#include “stdafx.h” #include <objbase.h> #include <string>
using namespace std;
wstring GetGUID() { _TUCHAR *guidStr = NULL;
GUID *pguid = new GUID;
CoCreateGuid(pguid);
// Convert the GUID to a string
UuidToString(pguid, (RPC_WSTR*)&guidStr);
delete pguid;
return wstring(guidStr);
}
int _tmain(int argc, _TCHAR* argv[]) { wstring guid = GetGUID(); wprintf(guid.c_str()); return 0; }