如何获取GUID的名称
How to get name of GUID
我正在使用 C++ 中的 DirectX。结果,我调用的函数给了我一个 GUID 结构。现在 directx header 的 GUID 分配如下:
DEFINE_GUID(D3D11_DECODER_PROFILE_MPEG2_MOCOMP, 0xe6a9f44b, 0x61b0, 0x4563,0x9e,0xa4,0x63,0xd2,0xa3,0xc6,0xfe,0x66);
我的问题是如何从 GUID 获取 name(在本例中为 D3D11_DECODER_PROFILE_MPEG2_MOCOMP)?
D3D11_DECODER_PROFILE_MPEG2_MOCOMP
只是 GUID 的别名。您可以选择任何您喜欢的别名,但不要选择容易重复的简单别名。
Each coclass and interface has its guid, which is a 128-bit number. For easy use by the programmer, an easy-remember manifest constant is defined for each guid.
Source : http://progtutorials.tripod.com/COM.htm
据我所知,没有这样的名称,或仅定义特定视频配置文件的此类 GUID 的人类可读名称。
您可以创建一个包含字符串和 GUID 的结构数组来转换它。但请记住,名称本身只是 GUID 的定义。所以它只在 C++ 代码中有效。
struct S_GUID_DECODER {
char* pName;
const GUID *pGuid;
}
aValues[] =
{
...
{" D3D11_DECODER_PROFILE_MPEG2_MOCOMP", &D3D11_DECODER_PROFILE_MPEG2_MOCOMP },
...
};
现在您可以使用循环并找到 "your" 名称。
PS:您的问题不是很清楚,如果您指的是像界面 GUID 或 class ID 之类的 GUID,还是只是视频配置文件的这个特殊标识符组。
对于搜索类似结果的人,代码片段来自 Microsoft directshow 示例,但已更改以满足现代 visual studio 要求 (vs2019),
主要代码,
Blockquote
#include <iostream>
#include <guiddef.h>
//#include <initguid.h> --- dont use it, use guiddef.h instead.
#include <cguid.h>
/* Stuff for printing out our GUID names */
typedef struct {
const char* szName;
GUID guid;
} GUID_STRING_ENTRY;
GUID_STRING_ENTRY g_GuidNames[] = {
#define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) { #name, { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } },
#include <myuuids.h>
};
class CGuidNameList {
public:
const char* operator [] (const GUID& guid);
};
extern CGuidNameList GuidNames;
CGuidNameList GuidNames;
int g_cGuidNames = sizeof(g_GuidNames) / sizeof(g_GuidNames[0]);
const char* CGuidNameList::operator [] (const GUID& guid)
{
for (int i = 0; i < g_cGuidNames; i++) {
if (g_GuidNames[i].guid == guid) {
return g_GuidNames[i].szName;
}
}
if (guid == GUID_NULL) {
return "GUID_NULL";
}
// !!! add something to print FOURCC guids?
// shouldn't this print the hex CLSID?
return "Unknown GUID Name";
}
int main() {
// --- what is guid ----
unsigned long Data1 = 0xea36eb8e;
const GUID MEDIASUBTYPE_None = { 0xe436eb8e, 0x524f, 0x11ce, 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 };
std::cout << MEDIASUBTYPE_None.Data1 << std::endl;
// --- now get the guid names ----
std::cout << GuidNames[MEDIASUBTYPE_None] << std::endl;
}
Blockquote
uuid.h 只是 windows SDK 的一个副本,对我来说它安装在我的电脑上,
C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared\uuids
此文件中唯一的变化是
OUR_GUID_ENTRY(CLSID_SBE2FileScan,
0x3e458037, 0xca6, 0x41aa, 0xa5, 0x94, 0x2a, 0xa6, 0xc0, 0x2d, 0x70, 0x9b) ;
已更改为(去掉最后一个“;”,会给出错误信号)
OUR_GUID_ENTRY(CLSID_SBE2FileScan,
0x3e458037, 0xca6, 0x41aa, 0xa5, 0x94, 0x2a, 0xa6, 0xc0, 0x2d, 0x70, 0x9b)
希望这对您有所帮助。
我正在使用 C++ 中的 DirectX。结果,我调用的函数给了我一个 GUID 结构。现在 directx header 的 GUID 分配如下:
DEFINE_GUID(D3D11_DECODER_PROFILE_MPEG2_MOCOMP, 0xe6a9f44b, 0x61b0, 0x4563,0x9e,0xa4,0x63,0xd2,0xa3,0xc6,0xfe,0x66);
我的问题是如何从 GUID 获取 name(在本例中为 D3D11_DECODER_PROFILE_MPEG2_MOCOMP)?
D3D11_DECODER_PROFILE_MPEG2_MOCOMP
只是 GUID 的别名。您可以选择任何您喜欢的别名,但不要选择容易重复的简单别名。
Each coclass and interface has its guid, which is a 128-bit number. For easy use by the programmer, an easy-remember manifest constant is defined for each guid. Source : http://progtutorials.tripod.com/COM.htm
据我所知,没有这样的名称,或仅定义特定视频配置文件的此类 GUID 的人类可读名称。
您可以创建一个包含字符串和 GUID 的结构数组来转换它。但请记住,名称本身只是 GUID 的定义。所以它只在 C++ 代码中有效。
struct S_GUID_DECODER {
char* pName;
const GUID *pGuid;
}
aValues[] =
{
...
{" D3D11_DECODER_PROFILE_MPEG2_MOCOMP", &D3D11_DECODER_PROFILE_MPEG2_MOCOMP },
...
};
现在您可以使用循环并找到 "your" 名称。
PS:您的问题不是很清楚,如果您指的是像界面 GUID 或 class ID 之类的 GUID,还是只是视频配置文件的这个特殊标识符组。
对于搜索类似结果的人,代码片段来自 Microsoft directshow 示例,但已更改以满足现代 visual studio 要求 (vs2019),
主要代码,
Blockquote
#include <iostream>
#include <guiddef.h>
//#include <initguid.h> --- dont use it, use guiddef.h instead.
#include <cguid.h>
/* Stuff for printing out our GUID names */
typedef struct {
const char* szName;
GUID guid;
} GUID_STRING_ENTRY;
GUID_STRING_ENTRY g_GuidNames[] = {
#define OUR_GUID_ENTRY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) { #name, { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } },
#include <myuuids.h>
};
class CGuidNameList {
public:
const char* operator [] (const GUID& guid);
};
extern CGuidNameList GuidNames;
CGuidNameList GuidNames;
int g_cGuidNames = sizeof(g_GuidNames) / sizeof(g_GuidNames[0]);
const char* CGuidNameList::operator [] (const GUID& guid)
{
for (int i = 0; i < g_cGuidNames; i++) {
if (g_GuidNames[i].guid == guid) {
return g_GuidNames[i].szName;
}
}
if (guid == GUID_NULL) {
return "GUID_NULL";
}
// !!! add something to print FOURCC guids?
// shouldn't this print the hex CLSID?
return "Unknown GUID Name";
}
int main() {
// --- what is guid ----
unsigned long Data1 = 0xea36eb8e;
const GUID MEDIASUBTYPE_None = { 0xe436eb8e, 0x524f, 0x11ce, 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 };
std::cout << MEDIASUBTYPE_None.Data1 << std::endl;
// --- now get the guid names ----
std::cout << GuidNames[MEDIASUBTYPE_None] << std::endl;
}
Blockquote
uuid.h 只是 windows SDK 的一个副本,对我来说它安装在我的电脑上, C:\Program Files (x86)\Windows Kits\Include.0.18362.0\shared\uuids
此文件中唯一的变化是
OUR_GUID_ENTRY(CLSID_SBE2FileScan,
0x3e458037, 0xca6, 0x41aa, 0xa5, 0x94, 0x2a, 0xa6, 0xc0, 0x2d, 0x70, 0x9b) ;
已更改为(去掉最后一个“;”,会给出错误信号)
OUR_GUID_ENTRY(CLSID_SBE2FileScan,
0x3e458037, 0xca6, 0x41aa, 0xa5, 0x94, 0x2a, 0xa6, 0xc0, 0x2d, 0x70, 0x9b)
希望这对您有所帮助。