Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialise a GUID variable: How?

Tags:

c++

winapi

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));
}
like image 333
sazr Avatar asked Jan 27 '13 04:01

sazr


1 Answers

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 } };
like image 156
Carl Norum Avatar answered Oct 12 '22 02:10

Carl Norum