IGraphBuilder vs FilgraphManager

I am trying to get a HD mpeg file to play in DirectShow using C++.
I have two different applications one in C# and one in C++. The C# 
application renders the HD mpeg file just fine and the C++ programs gives me 
the following error "An invalid media type was specified.".  I the 
documentation is said that IGraphBuilder was the same or similiar to the 
FilgraphManager.

Here is the C# code that works:

 m_objFilterGraph = new FilgraphManager();
            m_objFilterGraph.RenderFile(openFileDialog.FileName);

            m_objBasicAudio = m_objFilterGraph as IBasicAudio;
            
            try
            {
               m_objVideoWindow = m_objFilterGraph as IVideoWindow;
               m_objVideoWindow.Owner = (int) panel1.Handle;
               m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
               
m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                  panel1.ClientRectangle.Top,
                  panel1.ClientRectangle.Width,
                  panel1.ClientRectangle.Height);
            }
            catch (Exception)
            {
               m_objVideoWindow = null;
            }

            m_objMediaEvent = m_objFilterGraph as IMediaEvent;

            m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
            m_objMediaEventEx.SetNotifyWindow((int) 
this.Handle,WM_GRAPHNOTIFY, 0);

            m_objMediaPosition = m_objFilterGraph as IMediaPosition;

            m_objMediaControl = m_objFilterGraph as IMediaControl;

            this.Text = "DirectShow - [" + openFileDialog.FileName + "]";

            m_objMediaControl.Run();

Here is the C++ code that does not. It dies on the RenderFile call

 // Instantiate filter graph interface
   JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, 
                   IID_IGraphBuilder, (void **)&pGB));

   // Get interfaces to control playback & screensize
   JIF(pGB->QueryInterface(IID_IMediaControl,  (void **)&pMC));
   JIF(pGB->QueryInterface(IID_IVideoWindow,  (void **)&pVW));

   // Get interface to allow the app to wait for completion of playback
   JIF(pGB->QueryInterface(IID_IMediaEventEx,  (void **)&pME));

   HRESULT hr = pGB->RenderFile(lpszMovie, NULL);
   if (FAILED(hr)) 
   {
		TCHAR *buffer = new TCHAR[1024];
		DWORD length = AMGetErrorText(hr, buffer, 1024);


Answer this question

IGraphBuilder vs FilgraphManager

  • Hormoz

    This might seem obvious - in the C# code you get the interfaces after RenderFile and in the C++ you get them before although that does not explain your error. Query interfaces for control after RenderFile.

  • IGraphBuilder vs FilgraphManager