다음을 통해 공유


IFilterGraph2::AddSourceFilterForMoniker

 
Microsoft DirectShow 9.0

IFilterGraph2::AddSourceFilterForMoniker

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 ICreateDevEnuminterface.)

Syntax

  HRESULT AddSourceFilterForMoniker(
  IMoniker *pMoniker,
  IBindCtx *pCtx,
  LPCWSTR lpcwstrFilterName,
  IBaseFilter **ppFilter
);

Parameters

pMoniker

[in] Pointer to an IMoniker interface.

pCtx

[in] Pointer to an IBindCtx bind context interface.

lpcwstrFilterName

[in]  Name for the filter.

ppFilter

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

Return Values

Returns and HRESULT value. Possible values include the following.

Value 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.

Example Code

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

Header: Declared in Strmif.h; include Dshow.h.

Library: Use Strmiids.lib.

See Also