Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
i' ve a serious trouble with a C++ DLL for implement a callback event and use this in C#. Those are the two native function :
C++
long FUNC_RegisterEventHandler(EventHandler handler, BYTE evmask, LONG param);

C++
void EventHandlerFunc(WORD event_id, LPVOID data, LONG param);
My implementation:
C#
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
    public delegate void CCC_EventHandler(string event_id, object data, int param);
    [DllImport(@"QSN.DLL")]
    public static extern int CCC_RegisterEventHandler(CCC_EventHandler handler, byte evmask, int param);
C#
private void RegisterEvent() {
        QSN_Library.CCC_EventHandler delegato = FireEvento();
        IntPtr val = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(delegato);
        //
        QSN_Library.CCC_RegisterEventHandler(delegato, 0xff, 0);
        System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(val, 
        typeof(QSN_Library.CCC_EventHandler)); 
    }

    private QSN_Library.CCC_EventHandler FireEvento() {
        return new QSN_Library.CCC_EventHandler((string a, 
        object b, int c) => { 
        // ....
        });
    }
Nothing to do... Any suggestion ?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900