A class ID (GUID) is generally specified with a sequence of hex numbers separated by dashes, e.g. {557cf406-1a04-11d3-9a73-0000f81ef32e}
. This is not a literal that can be used to initialize a CLSID structure directly.
I've discovered two ways to initialize the structure, but they're both kind of awkward. The first doesn't allow it to be declared const
and must be done at run time, while the second requires extensive reformatting of the hex constants.
CLSID clsid1;
CLSIDFromString(CComBSTR("{557cf406-1a04-11d3-9a73-0000f81ef32e}"), &clsid1);
const CLSID clsid2 = { 0x557cf406, 0x1a04, 0x11d3, { 0x9a,0x73,0x00,0x00,0xf8,0x1e,0xf3,0x2e } };
I know that Visual Studio can generate one automatically if you have a type that's associated with a UUID, using the __uuidof
operator. Is there a way to do it if you only have the hex string?