none
app. exits when callback received from unmanaged code RRS feed

  • Question

  • I have some problem with receiving unmanaged callback in C#. Actually I do receive the callback, but after receiving it, the application immediately quits. If I modify my code, so that callback function is received in unmanaged c++ instead of c# (but still prepared in C#),  the application works fine and the app. does not quit by itself.  So the problem may be marshalling definitions, parameter missmatch, or ... ?? But I do not see it. Anybody has some idea?

     

    Monika

     

     

    Callback function declaration:

     

    extern "C" __declspec(dllexport) __int32 burnSetJobDoneEventCallback(

    JobDoneEvent JobDoneEventCallback,

    void *pUserData);

     

    typedef void      (*JobDoneEvent)                     (void* pUserData);

     

    My c# code:

     

    public class CDBurn

        {

    [DllImport("burnDLL.dll")]

            public static extern int burnSetJobDoneEventCallback(

                [MarshalAs(UnmanagedType.FunctionPtr)]JobDoneDelegate callback, IntPtr pUserData);

     

     

    }

     

    public delegate void JobDoneDelegate(IntPtr data);

     

     

    public static void OnJobDone(IntPtr ptr)

            {

                MessageBox.Show("Job Done.");

            }

     

     

    private void StartCDBurn(object sender, RoutedEventArgs e)

            {

    ...some code...

     

                IntPtr dummy = new IntPtr(10);

     

                JobDoneDelegate delJobDone = new JobDoneDelegate(Window1.OnJobDone);

                int r = CDBurn.burnSetJobDoneEventCallback(delJobDone, dummy);

     

               

     

    Tuesday, March 4, 2008 5:44 PM

Answers

All replies