IMFCollection::GetElement method (mfobjects.h)

Retrieves an object in the collection.

Syntax

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

Parameters

[in] dwElementIndex

Zero-based index of the object to retrieve. Objects are indexed in the order in which they were added to the collection.

[out] ppUnkElement

Receives a pointer to the object's IUnknown interface. The caller must release the interface. The retrieved pointer value might be NULL.

Return value

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

This method does not remove the object from the collection. To remove an object, call IMFCollection::RemoveElement.

Examples

//  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;
}

Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header mfobjects.h (include Mfidl.h)
Library Mfuuid.lib

See also

IMFCollection