在stackoverflow上查资料,顺便回复了一个问题,直接上代码,
地址,https://stackoverflow.com/questions/36325106/how-to-get-name-of-guid/58636235#58636235
问题:如何枚举所有的GUID,并获取GUID的名称(即:把定义名称变成字符串名称)
本人的回复如下(注意:在c++中,#在宏中表示把参数变为字符串,##在宏中表示连接两个参数,不要弄混了),
For those who are searching for similar results, the code snippet is from microsoft directshow samples, but changed to satisfy modern visual studio requirements (vs2019),
Main Code,
#include
#include
//#include --- dont use it, use guiddef.h instead.
#include
/* 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
};
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
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?