在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
关注
打赏
热门博文
- 对CSDN网站关于抄袭的投诉的处理建议
- Tesseract OCR训练时碰到的问题和解决方案
- VSCODE在Jetson Nano上打不上断点,无法调试python源码
- ROS2进阶:在windows10上用vs2019编译rviz2
- ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
- ROS2 error: can‘t find examples_rclcpp_minimal_subscriber/Release/wait_set_subscriber_library.lib
- 在windows上安装 chocolatey.1.1.0.nupkg
- Qt开发高级进阶:如何在显示时适合视窗宽度和高度(fitWidth+fitHeight)
- PySpark ERROR: Python in worker has different version 3.9 than that in driver 3.8
- cv2.imshow error: The function is not implemented. Rebuild the library with Windows...