質問

I'm trying to declare and implement ISampleGrabberCB in C#. I'm coming from a C++ world where something like this is rather trivial (include a header, derive your class from this one and implement required methods)

From qedit.h:

MIDL_INTERFACE("0579154A-2B53-4994-B0D0-E773148EFF85")
ISampleGrabberCB : public IUnknown
{
public:
    virtual HRESULT STDMETHODCALLTYPE SampleCB( 
        double SampleTime,
        IMediaSample *pSample) = 0;

    virtual HRESULT STDMETHODCALLTYPE BufferCB( 
        double SampleTime,
        BYTE *pBuffer,
        long BufferLen) = 0;

};

Since I didn't find a C# declaration for this, I guess I have to do it on my own. Probably the same thing should be repeated for the IMEdiaSample.

I tried something like this:

using System.Runtime.InteropServices;

[Guid("0579154A-2B53-4994-B0D0-E773148EFF85"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface ISampleGrabberCB
{
    // although these methods return long, in C# world it is void (at least it looks like that)
    void SampleCB( double SampleTime, IMediaSample * pSample ); // IMediaSmaple is still undefined!
    void BufferCB( double SampleTime, BYTE *pBuffer, long BufferLen ); // pointer is still the problem
}

Can somebody help with this?

役に立ちましたか?

解決

You already have it with DirectShow.NET:

[ComImport, System.Security.SuppressUnmanagedCodeSecurity,
Guid("0579154A-2B53-4994-B0D0-E773148EFF85"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ISampleGrabberCB
{
    /// <summary>
    /// When called, callee must release pSample
    /// </summary>
    [PreserveSig]
    int SampleCB(double SampleTime, IMediaSample pSample);

    [PreserveSig]
    int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top