[Mono-list] Re: interesting discussion regarding managed dynamic libraries

Jonathan Pryor jonpryor@vt.edu
Thu, 16 Dec 2004 20:38:35 -0500


On Thu, 2004-12-16 at 12:20 +0000, Gregory Bowyer wrote:

<snip what="Inverse P/Invoke"/>

> Isn't this what was being talked about in Miguels blog here
> http://primates.ximian.com/~miguel/archive/2004/Dec-13.html

Inverse P/Invoke and cilc are similar in that they are both answers to
the question: how should unmanaged code invoke managed code?  How they
answer this question is wildly different ways.

Inverse P/Invoke allows unmanaged programs to link "normally" against a
managed assembly.  Put another way, the managed assembly exports a
function symbol that unmanaged code can execute, as if it were an
'extern "C"' function.  This allows unmanaged code to use managed
libraries without actually needing to know that they're managed.  It is
also fraught with difficulties: when unmanaged code invokes one of these
exports, which AppDomain should it hit?  How should  potential deadlock
with the Win32 library loader lock be handled?  The list goes on.

As mentioned elsewhere, Inverse P/Invoke is really only useful if the PE
format is the default object file format for your platform (read:
Windows only); the runtime linker of other platforms (Linux/ELF,
Mac/Mach-O) won't allow unmanaged programs to link against a managed
assembly due to the different object formats.

Cilc instead attempts to integrate the managed objects with the GObject
type system (see http://www.gtk.org).  Instead of requiring IL round-
tripping, Cilc generates a new unmanaged library which does two things:
(1) creates and exports a GObject-based API to create and use the
managed objects, and (2) uses the Mono embedded API to create and use
the managed objects "behind the scenes".  As such it's portable across
operating systems and is also tied to Mono's embedding API (and thus
isn't portable to .NET).

 - Jon