I'm working with DirectShow framework and trying to capture video from my webcam. Using the "ComImport" and "Guid" attributes, I import COM interfaces. When accessing the put_Owner() method of the IVideoWindow interface, I get an exception. In other interfaces, methods are called and return the S_OK result. Why can't it find a method with the given name?
Interface declaration:
[ComVisible(true)]
[ComImport]
[Guid(Constants.IVideoWindowGuid)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IVideoWindow {
[PreserveSig]
public HResult put_Owner(IntPtr owner);
}
I call the method as follows:
hResult = _videoWindow.put_Owner(Window);
if(hResult != HResult.S_OK)
throw new Exception(hResult.ToString());
I tried to capture a video in a console application, but there was no result, so I decided to create a WPF application from which I get a HWND handle. According to my logic, the video should be displayed in the WPF window, but the put_Owner method cannot be found.
Thanks
Edited.
_videoWindow
is a member of the IVideoWindow
interface (the declaration is described above), which in my case is a private field.
private IMediaControl _mediaControl;
private IMediaEventEx _mediaEvent;
private IVideoWindow _videoWindow;
Initialization occurs as follows:
_graphBuilder = (IGraphBuilder)(new FilterGraph());
_captureGraphBuilder = (ICaptureGraphBuilder2)(new CaptureGraphBuilder2());
_mediaControl = (IMediaControl) _graphBuilder;
_mediaEvent = (IMediaEventEx) _graphBuilder;
_videoWindow = (IVideoWindow) _graphBuilder;
For comparison, the methods of the objects _mediaControl
and _mediaEvent
are called successfully and return HRESULT S_OK result.
IntPtr Owner { get; set; }
. Documenting properties as methods with get and put prefixes is not terribly uncommon but only works in client code that uses the interface, can't work in the interface declaration.