Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an OS function to translate a REFIID to a helpful name?

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?

like image 812
Mordachai Avatar asked Oct 27 '09 14:10

Mordachai


1 Answers

Thanks for the responses. Below is what I came up with based on your feedback - much appreciated!

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;
}
like image 76
Mordachai Avatar answered Oct 01 '22 04:10

Mordachai