Share via


Retrieving the Content Types Supported by a Device

banner art

Previous Next

Retrieving the Content Types Supported by a Device

As noted in the Retrieving the Functional Categories Supported by a Device topic, Windows Portable Devices may support one or more functional categories. Any given functional category may support one or more content types. For example, the storage category may support content types of folder, audio, and image.

For a description of the content types supported by WPD, see the WPD_CONTENT_TYPE_ALL topic.

The ListSupportedContentTypes function in the DeviceCapabilities.cpp module demonstrates the retrieval of content types for the functional categories supported by a selected device.

Your application can retrieve the functional categories supported by a device using the interfaces described in the following table.

Interface Description
IPortableDeviceCapabilities Interface Provides access to the functional-category retrieval methods.
IPortableDevicePropVariantCollection Interface Used to enumerate and store functional-category data.

The code found in the ListSupportedContentTypes function is almost identical to the code found in the ListFunctionalCategories function. (See the Retrieving Functional Categories Supported by a Device topic.) The one difference is the call to the IPortableDeviceCapabilities::GetSupportedContentTypes method, which appears within the loop that iterates through the functional categories.

HRESULT hr = S_OK;
CComPtr<IPortableDeviceCapabilities>            pCapabilities;
CComPtr<IPortableDevicePropVariantCollection>   pCategories;
CComPtr<IPortableDevicePropVariantCollection>   pContentTypes;
if (SUCCEEDED(hr))
{
    for (DWORD dwIndex = 0; dwIndex < dwNumCategories; dwIndex++)
    {
        PROPVARIANT pv = {0};
        PropVariantInit(&pv;);
        hr = pCategories->GetAt(dwIndex, &pv;);
        if (SUCCEEDED(hr))
        {
            // We have a functional category.  It is assumed that
            // functional categories are returned as VT_CLSID
            // VarTypes.

            if ((pv.puuid != NULL)      &&
                (pv.vt    == VT_CLSID))
            {
                // Display the functional category name
                printf("Functional Category: ");
                DisplayFunctionalCategory(*pv.puuid);
                printf("\n");

                // Display the content types supported for this category
                hr = pCapabilities->GetSupportedContentTypes(*pv.puuid, &pContentTypes;);
                if (SUCCEEDED(hr))
                {
                    printf("Supported Content Types: ");
                    DisplayContentTypes(pContentTypes);
                    printf("\n\n");
                }
                else
                {
                    printf("! Failed to get supported content types from the device, hr = 0x%lx\n",hr);
                }
            }
            else
            {
                printf("! Invalid functional category found\n");
            }
        }

        PropVariantClear(&pv;);
    }
}

See Also

Previous Next