擷取裝置的功能對象標識碼
如 擷取裝置 支援的功能類別主題所述,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);
}
}
相關主題