以下说明的仅限windows平台下的定义
1 简要说明
GUID UUID CLSID IID是同一个结构体, 区别只是对应的字符串格式不同
UUID : "B8AAE3C3-7134-4BE9-90FF-1CD555A1417D"
GUID : "{B8AAE3C3-7134-4BE9-90FF-1CD555A1417D}"
CLSID: "{B8AAE3C3-7134-4BE9-90FF-1CD555A1417D}"
IID: "{B8AAE3C3-7134-4BE9-90FF-1CD555A1417D}"
2 结构体
typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
} GUID;
typedef GUID CLSID;
typedef GUID IID;
typedef GUID UUID;
3 相关函数
构造GUID
ExUuidCreate 内核层
CoCreateGuid 用户层
string与uuid互转
UuidFromString
UuidToString
guid 转string
StringFromGUID2
CLSID与string互转
CLSIDFromString
StringFromCLSID
IID与string互转
IIDFromString
StringFromIID
4 部分代码
const GUID hehe ={ 0x2f4d1f7a, 0xf01, 0x45c8,{ 0x93, 0x4a, 0xca, 0xa0, 0x83, 0x6b, 0x7b, 0x94 } }; RPC_WSTR buffer0 = NULL; RPC_STATUS ret0 = UuidToString(&hehe, &buffer0); if (ret0 == RPC_S_OK) { wprintf(L"uuid: %ws\n",(wchar_t*)buffer0); RpcStringFree(&buffer0); } WCHAR buffer[MAX_PATH] = {0}; int ret =StringFromGUID2(hehe, buffer, MAX_PATH); if (ret > 0) { wprintf(L"guid: %ws\n", buffer); } LPOLESTR buffer1 = NULL; HRESULT ret1 = StringFromCLSID(hehe, &buffer1); if (ret1 == S_OK) { wprintf(L"clsid: %ws\n", buffer1); CoTaskMemFree(buffer1); } StringFromIID(hehe, &buffer1); if (ret1 == S_OK) { wprintf(L"IID: %ws\n", buffer1); CoTaskMemFree(buffer1); }