Compartilhar via


Remove All the Filters in the Graph

 
Microsoft DirectShow 9.0

Remove All the Filters in the Graph

The easiest way to remove all of the filters in a filter graph is simply to release the Filter Graph Manager and create a new one. Make sure to release every pointer that your application has to any interfaces on the Filter Graph Managers, as well as pointers to objects in the graph, including filters, pins, the reference clock, and so forth.

Alternatively, you can remove the filters one at a time, using the IFilterGraph::RemoveFilter method:

// Stop the graph.
pControl->Stop();

// Enumerate the filters in the graph.
IEnumFilters *pEnum = NULL;
HRESULT hr = pGraph->EnumFilters(&pEnum);
if (SUCCEEDED(hr))
{
    IBaseFilter *pFilter = NULL;
    while (S_OK == pEnum->Next(1, &pFilter, NULL))
     {
         // Remove the filter.
         pGraph->RemoveFilter(pFilter);
         // Reset the enumerator.
         pEnum->Reset();
         pFilter->Release();
    }
    pEnum->Release();
}

This example uses the IFilterGraph::EnumFilters method to enumerate the filters in the graph. Removing a filter causes the enumerator object to become out of sync with the graph. Use the IEnumFilters::Reset method to reset the enumerator. Otherwise, any subsequent call to IEnumFilters::Next will fail.