5

Short of writing a function manually that translates a few known REFIID to names, such as:

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

Is there a system call that would return a reasonable debugging string for well-known (or even all) REFIIDs?

4

2 回答 2

6

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

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;
}
于 2009-10-27T17:48:30.520 回答
3

您可以在 HKCR\Interface 注册表子树中查找预定义的接口。如果愿意,任何组件都可以在那里注册其接口。但是,这不是强制性的 - 组件可能会跳过此注册。

于 2009-10-27T15:08:27.347 回答