InvalidCastException when calling COM interface on Windows Mobile.
I am trying to build a DirectShow source filter on Windows Mobile 5 based on the Generic Sample Source Filter (GSSF) sample from DirectShowLib. It uses C# configuration and callback functions with a C++ DirectShow filter. I have this working in .Net CF on Windows XP but when I run it on my Windows Mobile device I get an InvalidCastException when getting the configuration interface on the filter's output pin.
Please can someone suggest a solution?
C# Code
public void Test()
{
int hr = 0;
IBaseFilter ipsb = (IBaseFilter)new GenericSampleSourceFilter();
IPin ipin = null;
Log("FindPin");
hr = ipsb.FindPin("1", out ipin);
DsError.ThrowExceptionForHR( hr );
string id = null;
hr = ipin.QueryId(out id);
DsError.ThrowExceptionForHR( hr );
Log("Id=" + id);
IGenericSampleConfig icfg = (IGenericSampleConfig)ipin; // InvalidCastException on WM5
}
[ComImport, Guid("6F7BCF72-D0C2-4449-BE0E-B12F580D056D")]
public class GenericSampleSourceFilter
{
}
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("33B9EE57-1067-45fa-B12D-C37517F09FC0")]
public interface IGenericSampleCB
{
[PreserveSig]
int SampleCallback(IMediaSample pSample);
}
[Guid("CE50FFF9-1BA8-4788-8131-BDE7D4FFC27F"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IGenericSampleConfig
{
[PreserveSig]
int SetMediaTypeFromBitmap(BitmapInfoHeader bmi, long lFPS);
[PreserveSig]
int SetMediaType([MarshalAs(UnmanagedType.LPStruct)] AMMediaType amt);
[PreserveSig]
int SetMediaTypeEx([MarshalAs(UnmanagedType.LPStruct)] AMMediaType amt, int lBufferSize);
[PreserveSig]
int SetBitmapCB(IGenericSampleCB pfn);
}
C++ code
// {6F7BCF72-D0C2-4449-BE0E-B12F580D056D}
DEFINE_GUID(CLSID_GenericSampleSourceFilter,
0x6f7bcf72, 0xd0c2, 0x4449, 0xbe, 0xe, 0xb1, 0x2f, 0x58, 0xd, 0x5, 0x6d);
// {CE50FFF9-1BA8-4788-8131-BDE7D4FFC27F}
DEFINE_GUID(IID_IGenericSampleConfig,
0xce50fff9, 0x1ba8, 0x4788, 0x81, 0x31, 0xbd, 0xe7, 0xd4, 0xff, 0xc2, 0x7f);
// {33B9EE57-1067-45fa-B12D-C37517F09FC0}
DEFINE_GUID(IID_IGenericSampleCB,
0x33b9ee57, 0x1067, 0x45fa, 0xb1, 0x2d, 0xc3, 0x75, 0x17, 0xf0, 0x9f, 0xc0);
DECLARE_INTERFACE_(IGenericSampleCB, IUnknown) {
STDMETHOD(SampleCallback)(THIS_
IMediaSample *pSample
) PURE;
};
DECLARE_INTERFACE_(IGenericSampleConfig, IUnknown) {
STDMETHOD(SetMediaTypeFromBitmap) (THIS_
BITMAPINFOHEADER *bmi,
LONGLONG lFPS
) PURE;
STDMETHOD(SetMediaType) (THIS_
AM_MEDIA_TYPE *amt
) PURE;
STDMETHOD(SetMediaTypeEx) (THIS_
AM_MEDIA_TYPE *amt,
long lBufferSize
) PURE;
STDMETHOD(SetBitmapCB) (THIS_
IGenericSampleCB *pfn
) PURE;
};