1 #include <objbase.h> 2 #include <stdio.h> 3 4 //--生成GUID 5 const char* newGUID() 6 { 7 static char buf[64] = {0}; 8 GUID guid; 9 if (S_OK == ::CoCreateGuid(&guid)) 10 { 11 _snprintf(buf, sizeof(buf) 12 , "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X" 13 , guid.Data1 14 , guid.Data2 15 , guid.Data3 16 , guid.Data4[0], guid.Data4[1] 17 , guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5] 18 , guid.Data4[6], guid.Data4[7] 19 ); 20 } 21 return (const char*)buf; 22 } 23 24 int main(int argc, char* argv[]) 25 { 26 //--COM 27 CoInitialize(NULL); 28 29 printf(newGUID()); 30 printf("\r\n"); 31 32 //--COM 33 CoUninitialize(); 34 35 return 0; 36 }