c++ - 是否有将 REFIID 转换为有用名称的操作系统功能?

标签 c++ windows com windows-shell

缺少手动编写函数将一些已知的 REFIID 转换为名称,例如:

if (riid == IID_IUnknown) return "IUnknown";
if (riid == IID_IShellBrowser) return "IShellBrowser";
...

是否有系统调用可以为众所周知的(甚至所有)REFIID 返回合理的调试字符串?

最佳答案

感谢您的回复。以下是我根据您的反馈得出的结论 - 非常感谢!

CString ToString(const GUID & guid)
{
    // could use StringFromIID() - but that requires managing an OLE string
    CString str;
    str.Format(_T("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"),
        guid.Data1,
        guid.Data2,
        guid.Data3,
        guid.Data4[0],
        guid.Data4[1],
        guid.Data4[2],
        guid.Data4[3],
        guid.Data4[4],
        guid.Data4[5],
        guid.Data4[6],
        guid.Data4[7]);
    return str;
}

CString GetNameOf(REFIID riid)
{
    CString name(ToString(riid));
    try
    {
        // attempt to lookup the interface name from the registry
        RegistryKey::OpenKey(HKEY_CLASSES_ROOT, "Interface", KEY_READ).OpenSubKey("{"+name+"}", KEY_READ).GetDefaultValue(name);
    }
    catch (...)
    {
        // use simple string representation if no registry entry found
    }
    return name;
}

关于c++ - 是否有将 REFIID 转换为有用名称的操作系统功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1631375/

相关文章:

c++ - 在 C++ 中创建多行文本框/文本字段,而不是 VC++

c# - 如何使用word interop判断两个word文档是否相同

com - 将 CComSafeArray 传递给需要 SAFEARRAY 的方法时,正确的语法是什么**

c++ - 类型转换运算符不用于强制转换,编译器不同

c++ - 仅对具有显式构造函数的类的对象进行相等性检查

php - 奇怪的重写(Apache mod_rewrite)

c++ - 无法从 C++ 连接到 MySQL

android - 在 Android 之外实现 Wifi 感知应用程序

c++ - CString 到 _bstr_t 转换 C++

c++ - std::function 在移动后是否重置其内部功能