检索设备的功能对象标识符
如 检索设备支持的功能类别 主题中所述,Windows 便携设备可能支持一个或多个功能类别。 任何给定的功能类别都可能支持一个或多个功能对象。 例如,存储类别可能支持三个功能存储对象,每个对象都由唯一标识符字符串标识。 然后,第一个存储对象可由字符串“Storage1”标识,第二个存储对象由字符串“Storage2”标识,第三个对象由字符串“Storage3”标识。
DeviceCapabilities.cpp 模块中的 ListFunctionalObjects 函数演示了如何检索所选设备支持的功能类别的内容类型。
应用程序可以使用下表中所述的接口检索设备支持的功能类别。
接口 | 说明 |
---|---|
IPortableDeviceCapabilities 接口 | 提供对功能类别检索方法的访问。 |
IPortableDevicePropVariantCollection 接口 | 用于枚举和存储功能类别数据。 |
在 ListFunctionalObjects 函数中找到的代码几乎与 ListFunctionalCategories 函数中找到的代码相同。 (请参阅 检索设备支持的功能类别 主题。) 一个区别是调用 IPortableDeviceCapabilities::GetFunctionalObjects 方法,该方法显示在循环访问函数类别的循环中。
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 get the list of
// functional object identifiers associated with a particular
// category.
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 object identifiers for all
// functional objects within this category
CComPtr<IPortableDevicePropVariantCollection> pFunctionalObjectIds;
hr = pCapabilities->GetFunctionalObjects(*pv.puuid, &pFunctionalObjectIds);
if (SUCCEEDED(hr))
{
printf("Functional Objects: ");
DisplayFunctionalObjectIDs(pFunctionalObjectIds);
printf("\n\n");
}
else
{
printf("! Failed to get functional objects, hr = 0x%lx\n", hr);
}
}
else
{
printf("! Invalid functional category found\n");
}
}
PropVariantClear(&pv);
}
}
相关主题