[Mono-devel-list] Best way to use C# from C

Jonathan Pryor jonpryor at vt.edu
Mon Dec 20 18:39:44 EST 2004


On Mon, 2004-12-20 at 12:37 +0000, aza wrote:
> Hi,
> 
> I want to use some managed code components from a C application (that works 
> on Linux and Windows) what would be the most efficient way to do this?

Define "best".  There are the options you specified, and here are three
others:

1.  COM Interop.  This is .NET specific.  Managed classes can be 
    exported as COM classes and created/used in the standard COM manner.
    See MSDN.  This doesn't fit your requirements for Linux+Windows use.

2.  Mono's embedding API.  Allows creating and using managed classes 
    from C, and allows adding additional InternalCalls.  

    See: 
	http://www.go-mono.com/embedded-api.html
	http://mono.myrealbox.com/source/trunk/mono/samples/embed/

    Assuming you can use Mono on both Linux and Windows, this will 
    meet your platform requirements.

3.  Platform Invoke.  This is the only solution portable between Mono 
    and .NET.  Delegates can be marshaled into a function pointer, which
    can then be invoked from C to invoke a managed method.  This doesn't
    permit creation of arbitrary managed objects from C.

    See the recent Mono-list discussion:
	http://lists.ximian.com/archives/public/mono-list/2004-December/024914.html

    If you can live with its limitations, this will also meet your 
    platform requirements.

 - Jon





More information about the Mono-devel-list mailing list