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

Paolo Molaro lupus at ximian.com
Wed Oct 12 10:28:09 EDT 2005


On 10/12/05 Jorge García wrote:
> 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?

Yes and it should work on all the architectures (if not, file a bug).

> 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?

It's your duty to keep a delegate object alive if you pass it as a
callback to unmanaged code and if the callback may be called after the
pinvoked function returns.
To keep the object alive you can use a handle, or you can save it in a
field of an object that lasts long enough, or in a static field...

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better


More information about the Mono-list mailing list