IFilterGraph2::AddSourceFilterForMoniker method (strmif.h)

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The AddSourceFilterForMoniker method creates a source filter from an IMoniker pointer and adds the filter to the graph. For example, you can obtain a moniker for a system device, such as a video capture device, and add a video capture filter for that device. (For more information about system device monikers, see the ICreateDevEnum interface.)

Syntax

HRESULT AddSourceFilterForMoniker(
  [in]  IMoniker    *pMoniker,
  [in]  IBindCtx    *pCtx,
  [in]  LPCWSTR     lpcwstrFilterName,
  [out] IBaseFilter **ppFilter
);

Parameters

[in] pMoniker

Pointer to the IMoniker interface.

[in] pCtx

Pointer to an IBindCtx bind context interface.

[in] lpcwstrFilterName

Name for the filter.

[out] ppFilter

Receives a pointer to the source filter's IBaseFilter pointer. The caller must release the interface.

Return value

Returns and HRESULT value. Possible values include the following.

Return code Description
S_OK
Success.
VFW_S_DUPLICATE_NAME
Success; but the specified name was a duplicate, so the Filter Graph Manager modified the name.
E_FAIL
Failure.
E_OUTOFMEMORY
Insufficient memory.
VFW_E_DUPLICATE_NAME
Failed to add a filter with a duplicate name.
VFW_E_CANNOT_LOAD_SOURCE_FILTER
The source filter for could not be loaded.
VFW_E_UNKNOWN_FILE_TYPE
The media type of this file is not recognized.

Remarks

The Filter Graph Manager holds a reference count on the filter until the filter is removed from the graph or the Filter Graph Manager is released.

Examples

C++
IBaseFilter *pSource = NULL;
IMoniker *pMoniker = NULL;

// Use IEnumMonikers to get the IMoniker pointer. (Not shown.)

// Create a bind context for working with the moniker. IBindCtx pContext=0; hr = CreateBindCtx(0, &pContext); if (SUCCEEDED(hr)) { // Query the Filter Graph Manager for IFilterGraph2. IFilterGraph2 pFG2 = NULL; hr = pGraph->QueryInterface(IID_IFilterGraph2, (void)&pFG2); if (SUCCEEDED(hr)) { // Create the source filter. hr = pFG2->AddSourceFilterForMoniker(pMoniker, pContext, L"Source", &pSource); pFG2->Release(); } pContext->Release(); } pMoniker->Release();

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header strmif.h (include Dshow.h)
Library Strmiids.lib

See also

Error and Success Codes

IFilterGraph2 Interface