IMFCollection::GetElement 方法 (mfobjects.h)

擷取集合中的物件。

語法

HRESULT GetElement(
  [in]  DWORD    dwElementIndex,
  [out] IUnknown **ppUnkElement
);

參數

[in] dwElementIndex

要擷取之物件的以零起始索引。 物件會依新增至集合的順序編製索引。

[out] ppUnkElement

接收物件的 IUnknown 介面指標。 呼叫端必須釋放 介面。 擷取的指標值可能是 NULL

傳回值

如果此方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。

備註

這個方法不會從集合中移除物件。 若要移除物件,請呼叫 IMFCollection::RemoveElement

範例

//  Gets an interface pointer from a collection (IMFCollection).
//
//  Q: Interface type

template <class Q>
HRESULT GetCollectionObject(IMFCollection *pCollection, 
    DWORD dwIndex, Q **ppObject)
{
    *ppObject = NULL;   // zero output

    IUnknown *pUnk = NULL;
    HRESULT hr = pCollection->GetElement(dwIndex, &pUnk);
    if (SUCCEEDED(hr))
    {
        hr = pUnk->QueryInterface(IID_PPV_ARGS(ppObject));
        pUnk->Release();
    }
    return hr;
}

規格需求

需求
最低支援的用戶端 Windows Vista [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2008 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 mfobjects.h (include Mfidl.h)
程式庫 Mfuuid.lib

另請參閱

IMFCollection