C++生成GUID

 #include <objbase.h>
#include <stdio.h> //--生成GUID
const char* newGUID()
{
static char buf[] = {};
GUID guid;
if (S_OK == ::CoCreateGuid(&guid))
{
_snprintf(buf, sizeof(buf)
, "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X"
, guid.Data1
, guid.Data2
, guid.Data3
, guid.Data4[], guid.Data4[]
, guid.Data4[], guid.Data4[], guid.Data4[], guid.Data4[]
, guid.Data4[], guid.Data4[]
);
}
return (const char*)buf;
} int main(int argc, char* argv[])
{
//--COM
CoInitialize(NULL); printf(newGUID());
printf("\r\n"); //--COM
CoUninitialize(); return ;
}
上一篇:两句话概括“sql外键”


下一篇:iOS 之URL schemes