title: How do I check if my DirectShow Renderer filter is being used?
body: <p>In my DirectShow project I create a filter (derived from <code>CBaseVideoRenderer</code>) to render to a block of memory. This works in most cases perfectly well, with me adding the filter</p>
  
  <pre><code>    mGraphBuilder-&gt;AddFilter(pInterfaceInfo, MemoryRendererName);
  </code></pre>
  
  <p>and relying on GraphBuilder to do the rest. However in some cases the graph builder and my filter cannot agree on a common format and it creates a new ActiveMovie window, bypassing my filter.</p>
  
  <p>I would like to detect when this occurs so that I know my filter is not being used, but cannot work out how.</p>
  
  <p>I enumerate all filters in my graph, looking for my filter, using the following method:</p>
  
  <p>(EDIT: I pass my my GraphBuilder object as the pGraph parameter when I call this)</p>
  
  <pre><code>HRESULT MediaPlayer::CheckFilterGraphFor(IFilterGraph *pGraph, IBaseFilter* pFilterToLookFor)
  {
      IEnumFilters *pEnum = NULL;
      IBaseFilter *pFilter;
      ULONG cFetched;
  
      HRESULT enumeratedFilterCount = 0;
  
      FILTER_INFO pRefFilterInfo;
      pFilterToLookFor-&gt;QueryFilterInfo(&amp;pRefFilterInfo);
  
      HRESULT hr = pGraph-&gt;EnumFilters(&amp;pEnum);
      if (SUCCEEDED(hr))
      {
          while(pEnum-&gt;Next(1, &amp;pFilter, &amp;cFetched) == S_OK)
          {
              enumeratedFilterCount--;
  
              FILTER_INFO FilterInfo;
              hr = pFilter-&gt;QueryFilterInfo(&amp;FilterInfo);
              if (SUCCEEDED(hr))
              {   
                  if(wcscmp(FilterInfo.achName, pRefFilterInfo.achName) == 0)
                  {
                      pRefFilterInfo.pGraph-&gt;Release();
                      return S_OK;    
                  }
  
                  // The FILTER_INFO structure holds a pointer to the Filter Graph
                  // Manager, with a reference count that must be released.
                  if (FilterInfo.pGraph != NULL)
                  {
                      FilterInfo.pGraph-&gt;Release();
                  }
                  pFilter-&gt;Release();
  
              }
          }
  
          pEnum-&gt;Release();
      }
  
      pRefFilterInfo.pGraph-&gt;Release();
      return enumeratedFilterCount;
  }
  </code></pre>
  
  <p>But it does not work as expected, as my filter is always found regardless of whether it is in use or not.</p>
  
  <p><strong>How can I tell when my filter is in use as the video renderer for my DirectShow graph, and when it is not?</strong></p>