Pass a C# function to a COM interface that wants a function pointe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Travis

    #1

    Pass a C# function to a COM interface that wants a function pointe

    I have a Directshow filter I wrote in C++. I've created an interface to set
    a callback function. The app I want to use the filter in is in C#. How do I
    pass a function pointer from C# to a COM interface?

    I have not been able to find much in the way of examples but I have tried
    this:

    //COM Object
    typdef HRESULT (*MYCALLBACK) (IMediaSample * pSample);
    DECLARE_INTERFA CE_(IMyFilter, IUknown)
    {
    STDMETHOD(SetCa llbackPointer)( LPVOID FnAddress);
    }
    MYCALLBACK m_callback;
    STDMETHODIMP SetCallbackPoin ter(LPVOID FnAddress)
    {
    m_callback = (MYCALLBACK)FnA ddress;
    }
    void InvokeCallback( IMediaSample * pSample)
    {
    (m_callback)(pS ample);
    }
    HRESULT Transform(IMedi aSample *pSample)
    {
    InvokeCallback( pSample);
    }

    //C#
    public delegate int CallBackDelegat e(ref IMediaSample mediaSample);
    public class MyClass
    {
    public CallBackDelegat e myDelegate;
    public MyClass()
    {
    myDelegate = new CallBackDelegat e(CallbackFunct ion);

    //all the stuff to create the COM object and get the interface
    myInterface.Set CallbackPointer (myDelegate);
    }
    public int CallbackFunctio n(ref IMediaSample mediaSample)
    {
    //my intention is get a copy of the mediaSample
    MessageBox.Show ("Here");
    return 0;
    }
    }

Working...