您当前的位置: 首页 >  ui
  • 1浏览

    0关注

    483博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

如何枚举所有的GUID,并获取GUID的字符串名称

高精度计算机视觉 发布时间:2019-10-31 10:48:11 ,浏览量:1

在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             
关注
打赏
1661664439
查看更多评论
0.0459s