检索设备支持的内容类型
如 检索设备支持的功能类别 主题中所述,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);
}
}
相关主题