Exemple #1
0
STDMETHODIMP CShellExt::Initialize (LPCITEMIDLIST pidlFolder,
                                    LPDATAOBJECT lpdobj,
                                    HKEY hkeyProgID)
{
    UNREFERENCED_PARAMETER(pidlFolder);
    UNREFERENCED_PARAMETER(hkeyProgID);

    LONG lType = 0;
    HRESULT hr = NOERROR;
    if (!lpdobj)
    {
        return E_INVALIDARG;
    }


    // For singular selections, the WIA namespace should always provide a
    // dataobject that also supports IWiaItem

    if (FAILED(lpdobj->QueryInterface (IID_IWiaItem, reinterpret_cast<LPVOID*>(&m_pItem))))
    {
        // failing that, get the list of selected items from the data object
        UINT uItems = 0;
        LPWSTR szName;
        LPWSTR szToken;

        szName = GetNamesFromDataObject (lpdobj, &uItems);
        // we only support singular objects
        if (uItems != 1)
        {
            hr = E_FAIL;
        }
        else
        {
            // The name is of this format: <device id>::<item name>
            szToken = wcstok (szName, L":");
            if (!szToken)
            {
                hr = E_FAIL;
            }
            // Our extension only supports root items, so make sure there's no item
            // name
            else if (wcstok (NULL, L":"))
            {
                hr = E_FAIL;
            }
            else
            {
                hr = CreateDeviceFromId (szToken, &m_pItem);
            }
        }
        if (szName)
        {
            delete [] szName;
        }
    }
    if (SUCCEEDED(hr))
    {

        m_pItem->GetItemType (&lType);
        if (!(lType & WiaItemTypeRoot))
        {
            hr = E_FAIL; // we only support changing the property on the root item
        }
    }
    return hr;
}