So I was looking at this example code for DirectShow.Net, specifically their PlayCap example under the Capture folder example. You can download the samples here Its in C#. It does some interesting things with casting objects to interfaces. When I tried to recreate it faithfully in F#, the objects would not cast properly.
C#:
IVideoWindow videoWindow = null;
IMediaControl mediaControl = null;
IMediaEventEx mediaEventEx = null;
IGraphBuilder graphBuilder = null;
ICaptureGraphBuilder2 captureGraphBuilder = null;
and then later in GetInterfaces()
:
this.graphBuilder = (IGraphBuilder) new FilterGraph();
this.captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
this.mediaControl = (IMediaControl) this.graphBuilder;
this.videoWindow = (IVideoWindow) this.graphBuilder;
this.mediaEventEx = (IMediaEventEx) this.graphBuilder;
So what I did for my code was this in F#:
let mutable videoWindow: IVideoWindow = null;
let mutable mediaControl: IMediaControl = null;
let mutable mediaEventEx: IMediaEventEx = null;
let mutable graphBuilder: IGraphBuilder = null;
let mutable captureGraphBuilder: ICaptureGraphBuilder2 = null;
And later in GetInterfaces()
:
graphBuilder <- new FilterGraph() :> IGraphBuilder
captureGraphBuilder <- new CaptureGraphBuilder2() :> ICaptureGraphBuilder2
mediaControl <- graphBuilder :> IMediaControl;
videoWindow <- graphBuilder :> IVideoWindow;
mediaEventEx <- graphBuilder :> IMediaEventEx;
It looked like a faithful recreation. Not even using functional style either. I was looking at the msdn on casting in F# to see if I was doing it correctly. It looks like I am, though they have 1 example and it is incredibly minimal in nature.
The problem is I get the error:
Type constraint mismatch. The type
'FilterGraph'
is not compatible with the type'IGraphBuilder'
I get a similar error for each one. I have tried downcasting too as well using :?>