擷取裝置支援的內容類型
如 擷取裝置支援的功能類別 主題所述,Windows 可攜式裝置可能支援一或多個功能類別。 任何指定的功能類別都可能支援一或多個內容類型。 例如,儲存類別可支援資料夾、音訊和影像的內容類型。
如需 WPD 所支援之內容類型的描述,請參閱 WPD_CONTENT_TYPE_ALL 主題。
DeviceCapabilities.cpp 模組中的 ListSupportedContentTypes 函式示範如何擷取所選裝置所支援之功能類別的內容類型。
您的應用程式可以使用下表所述的介面,擷取裝置所支援的功能類別。
介面 | 描述 |
---|---|
IPortableDeviceCapabilities 介面 | 提供功能類別擷取方法的存取權。 |
IPortableDevicePropVariantCollection 介面 | 用來列舉和儲存功能類別資料。 |
在 ListSupportedContentTypes 函式中找到的程式碼幾乎與 ListFunctionalCategories 函式中找到的程式碼完全相同。 (請參閱裝置主題支援的擷 取功能類別 。) 其中一個差異在於 呼叫 IPortableDeviceCapabilities::GetSupportedContentTypes 方法,此方法會出現在逐一查看功能類別的迴圈內。
HRESULT hr = S_OK;
CComPtr<IPortableDeviceCapabilities> pCapabilities;
CComPtr<IPortableDevicePropVariantCollection> pCategories;
DWORD dwNumCategories = 0;
if (pDevice == NULL)
{
printf("! A NULL IPortableDevice interface pointer was received\n");
return;
}
// Get an IPortableDeviceCapabilities interface from the IPortableDevice interface to
// access the device capabilities-specific methods.
hr = pDevice->Capabilities(&pCapabilities);
if (FAILED(hr))
{
printf("! Failed to get IPortableDeviceCapabilities from IPortableDevice, hr = 0x%lx\n",hr);
}
// Get all functional categories supported by the device.
// We will use these categories to enumerate functional objects
// that fall within them.
if (SUCCEEDED(hr))
{
hr = pCapabilities->GetFunctionalCategories(&pCategories);
if (FAILED(hr))
{
printf("! Failed to get functional categories from the device, hr = 0x%lx\n",hr);
}
}
// Get the number of functional categories found on the device.
if (SUCCEEDED(hr))
{
hr = pCategories->GetCount(&dwNumCategories);
if (FAILED(hr))
{
printf("! Failed to get number of functional categories, hr = 0x%lx\n",hr);
}
}
printf("\n%d Functional Categories Found on the device\n\n", dwNumCategories);
// Loop through each functional category and display its name and supported content types.
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
CComPtr<IPortableDevicePropVariantCollection> pContentTypes;
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);
}
}
相關主題