Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

void com::GetInterfaceNameByIID ( const GUID &  aIID,
BSTR *  aName 
)

Resolves a given interface ID to a string containing the interface name. If, for some reason, the given IID cannot be resolved to a name, a NULL string is returned. A non-NULL string returned by this funciton must be freed using SysFreeString().

Parameters:
aIID ID of the interface to get a name for
aName Resolved interface name or NULL on error

Definition at line 63 of file com.cpp.

References Assert, DWORD, NULL, RT_SUCCESS, SysAllocString(), SysAllocStringLen(), and SysFreeString().

{
    Assert (aName);
    if (!aName)
        return;

    *aName = NULL;

#if !defined (VBOX_WITH_XPCOM)

    LONG rc;
    LPOLESTR iidStr = NULL;
    if (StringFromIID (aIID, &iidStr) == S_OK)
    {
        HKEY ifaceKey;
        rc = RegOpenKeyExW (HKEY_CLASSES_ROOT, L"Interface",
                            0, KEY_QUERY_VALUE, &ifaceKey);
        if (rc == ERROR_SUCCESS)
        {
            HKEY iidKey;
            rc = RegOpenKeyExW (ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey);
            if (rc == ERROR_SUCCESS)
            {
                /* determine the size and type */
                DWORD sz, type;
                rc = RegQueryValueExW (iidKey, NULL, NULL, &type, NULL, &sz);
                if (rc == ERROR_SUCCESS && type == REG_SZ)
                {
                    /* query the value to BSTR */
                    *aName = SysAllocStringLen (NULL, (sz + 1) /
                                                      sizeof (TCHAR) + 1);
                    rc = RegQueryValueExW (iidKey, NULL, NULL, NULL,
                                           (LPBYTE) *aName, &sz);
                    if (rc != ERROR_SUCCESS)
                    {
                        SysFreeString (*aName);
                        aName = NULL;
                    }
                }
                RegCloseKey (iidKey);
            }
            RegCloseKey (ifaceKey);
        }
        CoTaskMemFree (iidStr);
    }

#else /* !defined (VBOX_WITH_XPCOM) */

    nsresult rv;
    nsCOMPtr <nsIInterfaceInfoManager> iim =
        do_GetService (NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
    if (NS_SUCCEEDED (rv))
    {
        nsCOMPtr <nsIInterfaceInfo> iinfo;
        rv = iim->GetInfoForIID (&aIID, getter_AddRefs (iinfo));
        if (NS_SUCCEEDED (rv))
        {
            const char *iname = NULL;
            iinfo->GetNameShared (&iname);
            char *utf8IName = NULL;
            if (RT_SUCCESS (RTStrCurrentCPToUtf8 (&utf8IName, iname)))
            {
                PRTUTF16 utf16IName = NULL;
                if (RT_SUCCESS (RTStrToUtf16 (utf8IName, &utf16IName)))
                {
                    *aName = SysAllocString ((OLECHAR *) utf16IName);
                    RTUtf16Free (utf16IName);
                }
                RTStrFree (utf8IName);
            }
        }
    }

#endif /* !defined (VBOX_WITH_XPCOM) */
}


Generated by  Doxygen 1.6.0   Back to index