创建一个新的guid,并且转换成cstring类型

 //创建一个guid
 OleInitialize(NULL);
 GUID  pguid;
 int p = GetLastError();
 HRESULT hr = CoCreateGuid(&pguid);
 OleUninitialize( );
 
 PTREESECOND gropuInfo = new TREESECOND/*PGroupInfo*/;
 strncpy((char*)&gropuInfo->tag_Guid , (const char*)&pguid,sizeof(GUID));

 

 

tvwall
GUID CreateGuid()
{
 GUID id;
 memset(&id,0,sizeof(GUID));
 HRESULT hr=::CoCreateGuid(&id);
 if(FAILED(hr))
  ASSERT(FALSE);
 return id;
}

CString GuidToString(const GUID & id)
{
 BSTR bs;
 StringFromCLSID(id,&bs);
 CString str=(LPCTSTR)_bstr_t(bs);
 if(!str.CollateNoCase("{00000000-0000-0000-0000-000000000000}"))
  str.Empty();
 return str;
}

GUID StringToGuid(LPCTSTR szGuid)
{
 GUID id;
 memset(&id,0,sizeof(GUID));
 CLSIDFromString(_bstr_t(szGuid),&id);
 return id;
}

 

你可能感兴趣的:(null)