共用方式為


IWMDMDevice3::GetProperty 方法 (mswmdm.h)

GetProperty 方法會擷取特定的裝置元數據屬性。

語法

HRESULT GetProperty(
  [in]  LPCWSTR     pwszPropName,
  [out] PROPVARIANT *pValue
);

參數

[in] pwszPropName

要擷取之屬性的寬字元 Null 終止字串名稱。 元數據常數中會提供標準屬性名稱常數的清單。

[out] pValue

屬性的傳回值。 應用程式必須使用 PropVariantClear 釋放此記憶體。

傳回值

方法會傳回 HRESULT。 Windows Media 裝置管理員 中的所有介面方法都可以傳回下列任何一種錯誤碼類別:

  • 標準 COM 錯誤碼
  • 轉換成 HRESULT 值的 Windows 錯誤碼
  • Windows Media 裝置管理員 錯誤碼
如需可能錯誤碼的廣泛清單,請參閱 錯誤碼

備註

若要取得支援的裝置屬性清單,用戶端會呼叫此函式並指定 g_wszWMDMSupportedDeviceProperties。 如需標準裝置屬性名稱的清單,請參閱 元數據常數

客戶端應該在 pValue 參數中傳入空 PROPVARIANT 的指標。 傳回時, pValue 會包含 屬性的值。

這個方法類似於 記憶體的 GetMetadataGetSpecifiedMetadata 方法,但此方法一次只能取得一個屬性。

範例

下列 C++ 程式代碼會查詢 g_wszWMDMFormatsSupported 屬性,這會傳回裝置所支援之格式的 SAFEARRAY 清單。


// Query a device for supported configurations for each media or format type. 
HRESULT GetCaps(IWMDMDevice3* pDevice)
{
    HRESULT hr = S_OK;

    // Request the "formats supported" property to get a list of supported formats.
    PROPVARIANT pvFormatsSupported;
    PropVariantInit(&pvFormatsSupported);
    hr = pDevice->GetProperty(g_wszWMDMFormatsSupported, &pvFormatsSupported);
    HANDLE_HR(hr, "Got a property list in GetCaps", "Couldn't get a property list in GetCaps.");

    // Loop through the retrieved format list.
    // For each format, get a list of format configurations.
    SAFEARRAY* formatList = pvFormatsSupported.parray;
    WMDM_FORMATCODE formatCode = WMDM_FORMATCODE_NOTUSED;
    for(LONG iCap = 0; iCap < formatList->rgsabound[0].cElements; iCap++)
    { 
        // Get a format from the SAFEARRAY of retrieved formats.
        SafeArrayGetElement(formatList, &iCap, &formatCode);

        // Call a custom function to see the specifics of device support for 
       // each format.
        if (formatCode != WMDM_FORMATCODE_NOTUSED)
            myGetFormatCaps(formatCode, pDevice);
    }

e_Exit:
    // Clear out the memory we used.
    PropVariantClear(&pvFormatsSupported);
    return hr;
}

規格需求

需求
目標平台 Windows
標頭 mswmdm.h
程式庫 Mssachlp.lib

另請參閱

列舉裝置

IWMDMDevice3 介面

IWMDMDevice3::SetProperty

IWMDMStorage3::GetMetadata

IWMDMStorage4::GetSpecifiedMetadata

在檔案上設定元數據