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

aza aza at azaclauson.com
Mon Dec 20 19:33:29 EST 2004


Hi,

The two criteria I am using to define best are:

1. Fairly speedy. Able to get back and forth from C -> C# -> C in under a 
second. This could potentially rule out web services,

2. Requires the least amount of "integration" work. I know what I want to do 
in the C and C# pieces and it would be nice to avoid a lot of work in the 
interface between the two. And also when I change the method signatures in a 
months time I don't have to spend a couple of days wiring it all back up. 
This is where web services would be nice.

I may be wrong but I don't think PInvoke and COM Interop (aren't these the 
same under the hood anyway?) are options. The initial process is a C 
application and in order to use a managed assembly it is going to have to 
load the runtime. PInvoke can only be used for managed to unmanaged and not 
vice-versa?

The embedded mono option was exactly the information my first question was 
hoping to unearth. I'd imagine once the AppDomain is loaded calls back and 
forth between the C and C# code are down into a millisecond range.

Thanks,

aza

----- Original Message ----- 
From: "Jonathan Pryor" <jonpryor at vt.edu>
To: "aza" <aza at azaclauson.com>
Cc: <mono-devel-list at lists.ximian.com>
Sent: Monday, December 20, 2004 11:39 PM
Subject: Re: [Mono-devel-list] Best way to use C# from C


> 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
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 





More information about the Mono-devel-list mailing list