初始化GUID变量:如何? [英] Initialise a GUID variable: How?

查看:1403
本文介绍了初始化GUID变量:如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试初始化 GUID 变量,但我不知道这是你是如何做的。我特别困惑的是如何存储最后12个十六进制数字在字符数组(我包括 - 字符?)

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?)

如何我定义/初始化GUID变量?

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));
}


推荐答案

Data4 成员不是一个指针,它是一个数组。您需要:

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

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

使您的示例工作。您可能会发现更容易执行所有初始化以及 monitorClassGuid 变量的定义:

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 } };

这篇关于初始化GUID变量:如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆