Question

In c++ you call a filters queryinterface method to obtain another interface to the filter. How do you do this in DirectShow.net?

Ok, i found out you can do something like this:

filewriter = new FileWriter() as IBaseFilter;

But what to do if you don't have an interface defined in c#? Do you have to create one yourself? If yes: how does the interface have to look?

Update: I tried defining a c# interface definition as suggested by Roman R:

[ComImport, System.Security.SuppressUnmanagedCodeSecurity,
Guid("21337C80-1D52-44FD-8581-85ED4BBC2FA9"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMyFilter
{
    [PreserveSig]
    int SetIntroText(
        [In, MarshalAs(UnmanagedType.LPWStr)] String text);
    [PreserveSig]
    int SetIntervalText(
        [In, MarshalAs(UnmanagedType.LPWStr)] String text);

 }

The cast work fine but calling of the method always returns 0 and doesn't do anything, so the actual method of the filter is not called.

Here is the filter definition in c++:

static const GUID CLSID_MyFilter64  = 
{ 0x67216de, 0xe6a1, 0x49c9, { 0xa0, 0x16, 0x7, 0x46, 0x24, 0xc2, 0xf, 0xe5 } };


// {21337C80-1D52-44FD-8581-85ED4BBC2FA9}
static const GUID IID_IMyFilter64 = 
{ 0x21337c80, 0x1d52, 0x44fd, { 0x85, 0x81, 0x85, 0xed, 0x4b, 0xbc, 0x2f, 0xa9 } };






DECLARE_INTERFACE_(IMyFilter, IUnknown)
{

    STDMETHOD(GetThePinCount)(int*) PURE;
    STDMETHOD_(IPin*, GetMyPin(int index)) PURE;
    STDMETHOD(GetMediaTypeArgs)(VIDEOINFOHEADER **hdr, int &stride, Gdiplus::PixelFormat** pxFmt)PURE;
    STDMETHOD(SetMediaTypeArgs)(VIDEOINFOHEADER *hdr, int stride, Gdiplus::PixelFormat* pxFmt)PURE;

    STDMETHOD(SetIntroText)(WCHAR* text);
    STDMETHOD_(WCHAR*, GetIntroTExt)()PURE;
    STDMETHOD(SetIntervalText)(WCHAR* text)PURE;
    STDMETHOD_(WCHAR*, GetIntervalText)()PURE;
};

I don't know why it doesn't work. The interface definition in c# must be not correct. But I don't know how it should be.

Was it helpful?

Solution

The interfaces "exist" in certain form regardless of availability of their declaration in your project. That is, if you don't have certain interfaces defined, and then you don't have them from third party component vendor, and you don't have them via reference or type library import - then you need to define that yourself so that your definition matches their original definition.

The same way DirectShow.NET defines interfaces you need and you don't have available for your .NET code out of the box, e.g. in QEdit.cs:

[ComImport, System.Security.SuppressUnmanagedCodeSecurity,
Guid("6B652FFF-11FE-4fce-92AD-0266B5D7C78F"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISampleGrabber
{
    [PreserveSig]
    int SetOneShot(
        [In, MarshalAs(UnmanagedType.Bool)] bool OneShot);

    [PreserveSig]
    int SetMediaType(
        [In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType pmt);

UPD. As CPlusSharp says in comments below, definition needs to be a 100% match. Important in particular is order of methods (as opposed to naming), and types and conventions used. Your definition is not a good match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top