ISampleGrabberCB声明&在C#中实现

时间:2014-01-18 15:51:26

标签: c# directshow.net

我正在尝试在C#中声明和实现ISampleGrabberCB。我来自一个C ++世界,这样的东西相当简单(包括一个标题,从这一个派生你的类并实现所需的方法)

来自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;

};

由于我没有为此找到C#声明,我想我必须自己做。 IMEdiaSample可能会重复同样的事情。

我试过这样的事情:

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
}

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您已经拥有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);
}