打印一个GUID变量 [英] Print a GUID variable

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

问题描述

我有一个GUID变量,我想在文本文件中写入其值. GUID的定义是:

I have a GUID variable and I want to write inside a text file its value. GUID definition is:

typedef struct _GUID {          // size is 16
    DWORD Data1;
    WORD   Data2;
    WORD   Data3;
    BYTE  Data4[8];
} GUID;

但是我想这样写它的值:

But I want to write its value like:

CA04046D-0000-0000-0000-504944564944

我观察到:

  • Data1保留CA04046D的十进制值
  • Data2保留0的十进制值
  • Data3保留下一个0的十进制值
  • Data1 holds the decimal value for CA04046D
  • Data2 holds the decimal value for 0
  • Data3 holds the decimal value for next 0

但是其他人呢?

为了获得该输出,我必须自己解释这些值,还是有一个更直接的方法来打印这样的变量?

I have to interpret myself this values in order to get that output or is there a more direct method to print such a variable?

推荐答案

使用 StringFromCLSID 函数将其转换为字符串

Use the StringFromCLSID function to convert it to a string

例如:

GUID guid;
CoCreateGuid(&guid);

OLECHAR* guidString;
StringFromCLSID(guid, &guidString);

// use guidString...

// ensure memory is freed
::CoTaskMemFree(guidString);

另请参见 GUID的MSDN定义描述data4,它是一个包含GUID的后8个字节的数组

Also see the MSDN definition of a GUID for a description of data4, which is an array containing the last 8 bytes of the GUID

这篇关于打印一个GUID变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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