请教,C语言如何获取GUID字符串!
真心求教,急用,万分感谢!
#include <objbase.h> #include <stdio.h> #pragma comment(lib,"ole32.lib") //需要链接ole32.lib 需要引用objbase.h const char* newGUID() { static char buf[64] = {0}; 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[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[]) { CoInitialize(NULL); printf(newGUID()); printf("\n"); CoUninitialize(); return 0; } /* 输出样例: {C71C1680-91B8-47cc-8A10-E69577A18F1A} */