10

I am attempting to initialise a GUID variable but I not sure this is how you are meant to do it. What I am especially confused about is how to store the last 12 hexadecimal digits in the char array(do I include the "-" character?)

How do I define/initialise a GUID variable?

bool TVManager::isMonitorDevice(GUID id)
{
    // Class GUID for a Monitor is: {4d36e96e-e325-11ce-bfc1-08002be10318}

    GUID monitorClassGuid;
    char* a                = "bfc1-08002be10318"; // do I store the "-" character?
    monitorClassGuid.Data1 = 0x4d36e96e;
    monitorClassGuid.Data2 = 0xe325;
    monitorClassGuid.Data3 = 0x11ce;
    monitorClassGuid.Data4 = a;

    return (bool(id == monitorClassGuid));
}
sazr
  • 24,984
  • 66
  • 194
  • 362
  • Here is the way I did it when I was working with COM. [Create a GUID](http://forums.codeguru.com/showthread.php?280300-create-a-GUID-using-c) – Rob Goodwin Jan 27 '13 at 04:18
  • How does this answer address the OP's question? – Carl Norum Jan 27 '13 at 04:23
  • -1, this is not a useful/relevant answer, since it only creates brand-new GUIDs, rather than defining an existing known GUID, which is what the OP wants. – BrendanMcK Jan 28 '13 at 03:15

2 Answers2

15

The Data4 member is not a pointer, it's an array. You'd want:

monitorClassGuid.Data4 = { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 };

To make your example work. You might find it easier to do all of the initialization along with the definition of your monitorClassGuid variable:

GUID monitorClassGuid = { 0x4d36e96e, 0xe325, 0x11c3, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
6

This question was asked long time ago, but maybe it helps somebody else.

You can use this code to initialize a GUID:

#include <combaseapi.h>;

GUID guid;
CLSIDFromString(L"{4d36e96e-e325-11ce-bfc1-08002be10318}", &guid);
Roman
  • 503
  • 6
  • 10