Récupération des identificateurs d’objets fonctionnels pour un appareil
Article
Comme indiqué dans la rubrique Récupération des catégories fonctionnelles prises en charge par un appareil , les appareils portables Windows peuvent prendre en charge une ou plusieurs catégories fonctionnelles. Toute catégorie fonctionnelle donnée peut prendre en charge un ou plusieurs objets fonctionnels. Par exemple, la catégorie de stockage peut prendre en charge trois objets de stockage fonctionnels, chacun d’entre eux étant identifié par une chaîne d’identificateur unique. Le premier objet de stockage peut ensuite être identifié par la chaîne « Storage1 », le second par la chaîne « Storage2 » et le troisième par la chaîne « Storage3 ».
La fonction ListFunctionalObjects dans le module DeviceCapabilities.cpp illustre la récupération des types de contenu pour les catégories fonctionnelles prises en charge par un appareil sélectionné.
Votre application peut récupérer les catégories fonctionnelles prises en charge par un appareil à l’aide des interfaces décrites dans le tableau suivant.
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);
}
}
Apprenez à créer du matériel standard plus accessible pour les jeux, notamment les consoles de jeu, les manettes et les casques. Découvrez les moyens de concevoir des emballages de matériel qui comportent des composants accessibles afin d’améliorer l’expérience de déballage d’un plus grand nombre de clients.