VC++ GUID随机字符串生成

#include "stdafx.h"

#include 

#include 

 

char* GuidToString(const GUID &guid);

 

int _tmain(int argc, _TCHAR* argv[])

{

     GUID guid;

     CoCreateGuid(&guid);

     printf( "GUID: %s", GuidToString( guid ) );
	 return 0;
}

  

char* GuidToString(const GUID &guid)

{

     static char buf[64] = {0};

     _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 buf;

}

你可能感兴趣的:(VC++)