I am attempting to convert a string to a GUID using the function UuidFromString.
My Problem: The resulting GUID is not correct. When I go to compare the GUID using IsEqualGUID the function always returns zero when it should say that the 2 GUID’s are the same.
Take a look at this example that shows the error:
// 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));
The output is:
String: {4d36e96e-e325-11ce-bfc1-08002be10318}
uID: {4d36e96e-e325-11ce-bfc1- 8 02be1 318}
IsEqualGUID: 0
They are different: GUID MONITOR_CLASS has 0x11c3, whereas your _STR version has “11ce“.