[Mono-list] Calling back from unmanaged code to managed code with Mono 1.1.9

Jorge García deriameloman at gmail.com
Wed Oct 12 08:18:09 EDT 2005


Hi,

about one year ago I tried to get working a libjack (Jack Audio
Connection Kit [1]) binding to .Net using mono 1.0.2-1. My attempt had
no success because the Mono runtime couldn't handle unmanaged
petitions from unmanaged to managed code.

I asked to this list [2] but there wasn't an easy solution. Later,
Francis Brosnan had the same problem and also asked to this list [3].
Maybe his explanation of the problem was better than mine:

> I'm trying to make the c# binding for some set of libraries which, in
> sort, makes petitions to a remote server without blocking the caller. In
> this context, the caller must suply a handler to manage the server
> response.
>
> Later, when server response arrives, these libraries initiate a thread
> and execute on it the Caller's handler.
>
> The binding works fine until unmanaged code invoke the caller's handler
> inside the newly thread create.

Luckily, a few days ago I tried it again with Mono 1.1.9 and now all
it's working pretty well. Thanks Mono hackers, you are the best!  This
is very important because soon I will release the binding and it will
be very easy to develop audio apps with Mono. I have also a binding of
libsndfile[4] working.

My questions are:

1) Can I assume that this will this be supported by mono 1.2 and
later? In what architectures?

2) With the garbage collector activated the binding wasn't working
well because some seconds after all where running it freed the
delegate's address. I have solved it using GCHandle. Do you know if
it's the best way to do that?

      private GCHandle handleProcess

      [...]

      public event ProcessEventHandler Process{
                add{
                        handleProcess = GCHandle.Alloc(value);
      [...]

Thanks again. See you,

Jorge


[1] http://jackit.sourceforge.net
[2] http://lists.ximian.com/pipermail/mono-list/2004-November/024236.html
[3] http://lists.ximian.com/archives/public/mono-list/2004-November/024666.html
[4] http://www.mega-nerd.com/libsndfile/


More information about the Mono-list mailing list