IFilterGraph2::AddSourceFilterForMoniker method (strmif.h)

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(
  IMoniker    *pMoniker,
  IBindCtx    *pCtx,
  LPCWSTR     lpcwstrFilterName,
  IBaseFilter **ppFilter
);

Parameters

pMoniker

Pointer to the IMoniker interface.

pCtx

Pointer to an IBindCtx bind context interface.

lpcwstrFilterName

Name for the filter.

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

   
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