'Comparing two GUIDs for equality in C++
I am looking for the easiest way to compare two GUIDs for equality in C++. Surely there is a predefined function for that.
The solution needs to work with Visual C++ 2010.
I am talking of GUID as defined in Guiddef.h:
typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
} GUID;
Solution 1:[1]
Is the == operator not overloaded to do this for you? Or use IsEqualGUID.
Solution 2:[2]
Wine implementation in here: https://source.winehq.org/source/dlls/ole32/compobj.c
Is fast simple and obvious:
/***********************************************************************
* IsEqualGUID [OLE32.@]
*
* Compares two Unique Identifiers.
*
* PARAMS
* rguid1 [I] The first GUID to compare.
* rguid2 [I] The other GUID to compare.
*
* RETURNS
* TRUE if equal
*/
#undef IsEqualGUID
BOOL WINAPI IsEqualGUID(
REFGUID rguid1, REFGUID rguid2) {
return !memcmp(rguid1, rguid2, sizeof(GUID));
}
That will compile with any Visual Studio version out there. That also is C so C++ aficionado might wrap it up in extern "C" { }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Science_Fiction |
| Solution 2 |
