全球唯一标识GUID

void CreateGuidValue()
{
 GUID objGUID = { 0 };

 if ( S_OK != CoCreateGuid( &objGUID ))
 {
  srand( GetTickCount());

  int* pGuid = ( int* )&objGUID;

  pGuid[0] = rand() % 100000000;
  pGuid[1] = rand() % 100000000;
 }

 sprintf( g_szGUIDString, "%08x%04x%04x", objGUID.Data1, objGUID.Data2, objGUID.Data3 );
}

创建失败后用随机数代替

(也可以时间+n位随机数)创建

你可能感兴趣的:(全球唯一标识GUID)