DirectShow filters run in the context of the filter graph. The graph manages connections between filters from a source, such as a video capture filter, to a renderer, such as a video window, and any transformation filters in between. DirectShow provides ICaptureGraphBuilder and ICaptureGraphBuilder2 interfaces containing methods for building and controlling a capture graph.
CComPtr< IGraphBuilder > pGraph;
CComPtr< ICaptureGraphBuilder2 > pBuilder;
HRESULT hr = S_OK;
//create filter graph
hr = pGraph.CoCreateInstance( CLSID_FilterGraph );
if( FAILED(hr) )
{
Error( "Failed to create a filter graph." );
return FALSE;
}
//create a capture graph builder
hr = pBuilder.CoCreateInstance( CLSID_CaptureGraphBuilder2 );
if( FAILED(hr) )
{
Error( "Failed to create a capture graph builder." );
return FALSE;
}
//add ActiveGige filter to the graph
hr = pGraph->AddFilter(pFilter, L"GigE Vision camera" );
if( FAILED(hr) )
{
Error( "Failed to add the camera to graph." );
return FALSE;
}
//specify the filter graph to the graph builder
hr = pBuilder->SetFiltergraph (pGraph);