出處:http://www.cnblogs.com/wubiyu/archive/2008/12/03/1346348.html
1//–生成GUID的代碼 2//–相關程序/微軟guidgen.exe
3
4#include “stdafx.h”
5#include <objbase.h>
6#include <stdio.h>
7 8//–生成GUID
9const char* newGUID()10{11 static char buf[64] = {0};12 GUID guid;13 if (S_OK == ::CoCreateGuid(&guid))14 {15 _snprintf(buf, sizeof(buf)16 , “{%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}”
17 , guid.Data118 , guid.Data219 , guid.Data320 , guid.Data4[0], guid.Data4[1]21 , guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5]22 , guid.Data4[6], guid.Data4[7]23 );24 }
25 return (const char*)buf;26}
2728int main(int argc, char* argv[])29{30 //–COM
31 CoInitialize(NULL);3233 printf(newGUID());34 printf(“rn”);3536 //–COM
37 CoUninitialize();3839 return 0;40}
4142