共用方式為


擷取裝置的功能物件識別碼

擷取裝置支援的功能類別 主題所述,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);
    }
}

IPortableDevice 介面

IPortableDeviceCapabilities 介面

IPortableDevicePropVariantCollection 介面

程式設計指南