[Mono-list] Re: Calling back from unmanaged code to managed code.

Nigel Benns nigel_benns@rogers.com
Thu, 16 Dec 2004 13:32:19 -0500 (EST)

Ok, this is a little different, I think anyway,
mabey I just don't have it in my head right, so I'll give the example I'm
working on.

I'm trying to bind EWL (Enlightenment Widget Library) to C#.

I've got the windows working, but no events.
I've read your email... seems easy enough, but I think it does it a little

Here is a C example to do a DeleteEvent:

void delete_cb(Ewl_Widget *w, void *event, void *data) {

int main(int argc, char **argv) {
   win = ewl_window_new();
   /*Where this function appends the callback to a calback list read
     by ewl_main().
   ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW, delete_cb, NULL);
   /*The NULL is for the Data to pass */

Ok, so what I'm trying figure out is how to add the ewl_callback_append as
a delegate in C#.

It doesn't seem write to me that I could pass a C# function to C, even if
I could figure out how to do that?

Is that where I need to add the "glue", or is this different.

my C# Lib looks kinda like this:

namespace Ewl {

   public class Window : Embed {

      IntPtr Handle;

      public override IntPtr Raw {

         get {

            return Handle;



      //I'm guessing I can't do this
      static extern int ewl_callback_append(IntPtr wid, CallType
CallType.DeleteEvent, //however you would give a function?)


Any one with a suggestion on this would be GREATLY appreciated.

I REALLY HATE C, it makes my head hurt, and managed code to C is even
worse :).  But the challenge is half the reason I'm doing this.