CoCreateGuid

今天在代碼中看到下面一個函數:

CString CConnectManager::newGUID()
{
   CString buf;
   GUID guid;
   if (S_OK == ::CoCreateGuid(&guid))
   {
     buf.Format("{%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;
}

用來返回一個系統自動生成的32位字符串。

關於CoCreateGuid()函數,MSDN如下解釋:

   Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers.

   HRESULT CoCreateGuid(
    GUID * pguid
   );

  如果函數執行成功,返回S_OK,

  GUID是一個結構體,MSDN解釋如下:

 

The GUID structure stores a GUID.

 

typedef struct _GUID {
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8]; } GUID;

Members

Data1

Specifies the first 8 hexadecimal digits of the GUID.

Data2

Specifies the first group of 4 hexadecimal digits.

Data3

Specifies the second group of 4 hexadecimal digits.

Data4

Array of 8 bytes. The first 2 bytes contain the third group of 4 hexadecimal digits. The remaining 6 bytes contain the final 12 hexadecimal digits.

Remarks

GUIDs are the Microsoft implementation of the distributed computing environment (DCE) universally unique identifier ( UUID). The RPC run-time libraries use UUIDs to check for compatibility between clients and servers and to select among multiple implementations of an interface. The Windows access-control functions use GUIDs to identify the type of object that an object-specific ACE in an access-control list (ACL) protects.

函數用來返回一個唯一的表示字符串。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章