I want to play video using dxshow, but the method pVideoWindow->put_Owner() returns E_NOINTERFACE. I'm trying to solve this problem in two days, but have not found a solution. Anybody help me ?

Qt Code:
  1. void UltraVision::PlayVideo()
  2. {
  3. // DirectShow interfaces
  4. IGraphBuilder *pGraphBuilder;
  5. IMediaControl *pMediaControl;
  6. IMediaEventEx *pMediaEvent;
  7. IVideoWindow *pVideoWindow;
  8. IBasicAudio *pBasicAudio;
  9. IBasicVideo *pBasicVideo;
  10. IMediaSeeking *pMediaSeeking;
  11. IMediaPosition *pMediaPosition;
  12. IVideoFrameStep *pFrameStep;
  13. IBaseFilter *pBaseFilter;
  14. IVMRWindowlessControl* pWindowlessControl;
  15.  
  16. HRESULT hr;
  17.  
  18. QAxWidget* mpVideoPlayer = new QAxWidget( ui.axWidget );
  19.  
  20. hr = CoInitialize( NULL );
  21. hr = CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void **) &pGraphBuilder );
  22. hr = pGraphBuilder->QueryInterface( IID_IMediaControl, (void**) &pMediaControl );
  23. hr = pGraphBuilder->QueryInterface( IID_IMediaEvent, (void **) &pMediaEvent);
  24. hr = pGraphBuilder->QueryInterface( IID_IMediaSeeking, (void **) &pMediaSeeking );
  25. hr = pGraphBuilder->QueryInterface( IID_IMediaPosition, (void **) &pMediaPosition);
  26. hr = pGraphBuilder->QueryInterface( IID_IVideoWindow, (void **) &pVideoWindow );
  27.  
  28. if( pVideoWindow )
  29. {
  30. hr = pVideoWindow->put_Owner( (OAHWND) ui.axWidget->winId() ) );
  31. hr = pVideoWindow->put_WindowStyle( WS_CHILD | WS_CLIPCHILDREN );
  32. }
  33.  
  34. hr = InitWindowlessVMR( (HWND) mpVideoPlayer->winId( ), pGraphBuilder, &pWindowlessControl );
  35.  
  36. if( SUCCEEDED( hr ) )
  37. {
  38. // Build the graph. For example:
  39. hr = pGraphBuilder->RenderFile( L"E:\\Video\\12\\Spartacus.S03E08.HDTVRip.avi", NULL );
  40. }
  41.  
  42.  
  43. // Find the native video size.
  44. long lWidth, lHeight;
  45. hr = pWindowlessControl->GetNativeVideoSize( &lWidth, &lHeight, NULL, NULL );
  46.  
  47. if ( SUCCEEDED( hr ) )
  48. {
  49. RECT rcSrc, rcDest;
  50. // Set the source rectangle.
  51. SetRect( &rcSrc, 0, 0, lWidth, lHeight );
  52.  
  53. // Get the window client area.
  54. GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcDest );
  55. // Set the destination rectangle.
  56. SetRect(&rcDest, 1, 1, 558, 349);
  57.  
  58. // Set the video position.
  59. hr = pWindowlessControl->SetVideoPosition( &rcSrc, &rcDest );
  60.  
  61. // Add this code to make the video initially show up once opening the file
  62. PAINTSTRUCT ps;
  63. HDC hdc;
  64. RECT rcClient;
  65. GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcClient );
  66. hdc = BeginPaint( (HWND) mpVideoPlayer->winId( ), &ps );
  67. if( pWindowlessControl != NULL )
  68. {
  69. // Find the region where the application can paint by subtracting
  70. // the video destination rectangle from the client area.
  71. // (Assume that g_rcDest was calculated previously.)
  72. HRGN rgnClient = CreateRectRgnIndirect( &rcClient );
  73. HRGN rgnVideo = CreateRectRgnIndirect( &rcDest );
  74. CombineRgn( rgnClient, rgnClient, rgnVideo, RGN_DIFF );
  75.  
  76. // Paint on window.
  77. HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE );
  78. FillRgn( hdc, rgnClient, hbr );
  79.  
  80. // Clean up.
  81. DeleteObject( hbr );
  82. DeleteObject( rgnClient );
  83. DeleteObject( rgnVideo );
  84.  
  85. // Request the VMR to paint the video.
  86. HRESULT hr = pWindowlessControl->RepaintVideo( (HWND) mpVideoPlayer->winId( ), hdc );
  87. }
  88. }
  89.  
  90. getFrameStepInterface(pGraphBuilder, pFrameStep);
  91.  
  92. pMediaControl->Run( );
  93.  
  94. }
To copy to clipboard, switch view to plain text mode