Table of contents
Collapse the table of content
Expand the table of content

Supported Property Retrieval

Last Updated: 1/24/2017

When a WPD application calls the IPortableDeviceProperties::GetSupportedProperties method, this method, in turn, triggers a call to the WpdObjectProperties::OnGetSupportedProperties method in the sample driver. The latter method creates an IPortableDeviceKeyCollection object into which the driver stores property keys for the properties supported by a given object.

HRESULT WpdObjectProperties::OnGetSupportedProperties(
    IPortableDeviceValues*  pParams,
    IPortableDeviceValues*  pResults)
    HRESULT hr          = S_OK;
    LPWSTR  wszObjectID = NULL;
    CComPtr<IPortableDeviceKeyCollection> pKeys;

    // First get ALL parameters for this command.  If we cannot get ALL parameters
    // then E_INVALIDARG should be returned and no further processing should occur.

    // Get the object identifier whose supported properties have been requested
    hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID);
    if (hr != S_OK)
        hr = E_INVALIDARG;
        CHECK_HR(hr, "Missing string value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID");

    // CoCreate a collection to store the supported property keys.
    if (hr == S_OK)
        hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection,
                              (VOID**) &pKeys);
        CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection");

    // Add supported property keys for the specified object to the collection
    if (hr == S_OK)
        hr = AddSupportedPropertyKeys(wszObjectID, pKeys);
        CHECK_HR(hr, "Failed to add supported property keys for object &#39;%ws&#39;", wszObjectID);

    // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS value in the results.
    if (hr == S_OK)
        hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys);

    // Free the memory.  CoTaskMemFree ignores NULLs so no need to check.

    return hr;

Send comments about this topic to Microsoft

© 2017 Microsoft