Pointer to callback function from C# to C++

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

    Pointer to callback function from C# to C++

    Hi

    I'm trying to Pass pointer to a callback function from C# to C++ it's
    working ok for a few minuts and then it's stops.

    can anyone help with that ?

    public class PA_Client

    {

    private int lHandle;

    public delegate int pPAEvent( int lEventCode,int lOperationCode, string
    sData);

    //PAHandShake

    [DllImport(@"\PA Api.dll" ,CallingConvent ion=CallingConv ention.Winapi

    ,CharSet=CharSe t.None, EntryPoint = "PAMultiHandSha ke")]

    private static extern int _PAHandShake(re f int lClientHandle,i nt
    lOperationCode, string sServerAddress, pPAEvent pEventFunc);

    //PARequest

    [DllImport(@"\PA Api.dll",Callin gConvention=Cal lingConvention. Winapi

    ,CharSet=CharSe t.None,EntryPoi nt = "PAMultiRequest ")]

    private static extern int PARequest(int lClientHandle, int lOperationCode,
    string sInputData);

    //PAControl

    [DllImport(@"\PA Api.dll",Callin gConvention=Cal lingConvention. Winapi

    ,CharSet=CharSe t.None, EntryPoint = "PAMultiControl ")]

    private static extern int PAControl(int lClientHandle,s tring sInputData);

    {





    public void Run_PA()

    {



    int Success = _PAHandShake(re f lHandle,1,addre ss, new pPAEvent( Callback));

    }

    private int Callback(int opCode, int eventCode, string InputData)

    {

    //Do some thing

    }



    }


  • Mattias Sjögren

    #2
    Re: Pointer to callback function from C# to C++

    [color=blue]
    >I'm trying to Pass pointer to a callback function from C# to C++ it's
    >working ok for a few minuts and then it's stops.
    >
    >can anyone help with that ?[/color]

    You have to keep a reference to the delegate to prevent if from being
    garbage colelcted.





    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org

    Please reply only to the newsgroup.

    Comment

    Working...