C++ guid
作者:互联网
百科:https://baike.baidu.com/item/GUID/3352285?fr=aladdin
// guid.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <objbase.h>
#include <stdio.h>
//生成GUID
const char* newGUID()
{
static char buf[64] = { 0 };
GUID guid;
if (S_OK == ::CoCreateGuid(&guid))
{
sprintf_s(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 (const char*)buf;
}
int main(int argc,char* argv[])
{
//--COM
CoInitialize(NULL);
printf(newGUID());
printf("\n");
CoUninitialize();
return 0;
}
//85996634-E447-4F41-8A27-49A3CDCF5B7C
//9E6008FC-BB34-431A-A655-21E486AAFB9A
标签:guid,C++,char,include,Data4,02X%,GUID 来源: https://blog.csdn.net/qq_24127015/article/details/88975131