我正在尝试使用函数将字符串转换为 GUID UuidFromString
。
我的问题:生成的 GUID 不正确。当我使用IsEqualGUID
该函数比较 GUID 时,它应该说 2 个 GUID 相同时总是返回零。
看看这个显示错误的例子:
// NOTE: MONITOR_CLASS and MONITOR_CLASS_STR are EXACTLY the same GUID
// except that one is in string version. When I convert the string
// to a GUID then compare both of them, the comparison says they
// AREN'T the same?? Whats going wrong?
GUID id;
GUID MONITOR_CLASS = { 0x4d36e96e, 0xe325, 0x11c3, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
LPTSTR MONITOR_CLASS_STR = L"4d36e96e-e325-11ce-bfc1-08002be10318";
UuidFromString((RPC_WSTR)MONITOR_CLASS_STR, &id);
_tprintf(_T("String: {%s}\nuID: {%x-%x-%x-%2x%2x-%2x%2x%2x%2x%2x%2x}\n"), MONITOR_CLASS_STR, id.Data1, id.Data2, id.Data3, id.Data4[0],
id.Data4[1], id.Data4[2], id.Data4[3], id.Data4[4], id.Data4[5], id.Data4[6], id.Data4[7]);
_tprintf(_T("IsEqualGUID: %d\n"), IsEqualGUID(id, MONITOR_CLASS));
输出是:
字符串:{4d36e96e-e325-11ce-bfc1-08002be10318}
uID:{4d36e96e-e325-11ce-bfc1-8 02be1 318}
IsEqualGUID:0