以下函数创建一个具有指定类标识符(CLSID)的过滤器,并将其添加到过滤器图形中:
// Create a filter by CLSID and add it to the graph.
HRESULT AddFilterByCLSID(
IGraphBuilder *pGraph, // Pointer to the Filter Graph Manager.
REFGUID clsid, // CLSID of the filter to create.
IBaseFilter **ppF, // Receives a pointer to the filter.
LPCWSTR wszName // A name for the filter (can be NULL).
)
{
*ppF = 0;
IBaseFilter *pFilter = NULL;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pFilter));
if (FAILED(hr))
{
goto done;
}
hr = pGraph->AddFilter(pFilter, wszName);
if (FAILED(hr))
{
goto done;
}
*ppF = pFilter;
(*ppF)->AddRef();
done:
SafeRelease(&pFilter);
return hr;
}
该函数调用CoCreateInstance创建过滤器,然后调用IFilterGraph ::