[Mono-list] PInvoke Conventions

Jay Freeman (saurik) saurik@saurik.com
Tue, 17 Jul 2001 23:34:11 -0500


Even easier than your SysInt marshalling it to just use the right data type
to begin with.  If you use the value type IntPtr the C# compiler is supposed
to compile that as "native int" (which is a valid datatype at the CLR
level), just as if you use Int32 the C# compiler compiles that as "int"; so
it isn't as if the code is working with a value type and doing strange
things with it at runtime.  That way you aren't hit with a marshalling cost
between the managed code that is treating it as one size and the PInvoke'd
call which is treating it as another.

Once again, that still doesn't help you with longs or shorts.

Jay Freeman (saurik)
----- Original Message -----
From: "Rhys Weatherley" <rweather@zip.com.au>
To: <mono-list@ximian.com>
Sent: Tuesday, July 17, 2001 9:02 PM
Subject: [Mono-list] PInvoke Conventions

> I've been investigating PInvoke support for Portable.NET,
> and I've come across some icky issues that will probably
> affect Mono's VM as well.
> In particular, because "int" and "long" have different types
> on different CPU's, it is difficult to write PInvoke declarations
> in C# that will work with all Unix libc's.  The result would
> be libraries and applications that need to be compiled
> separately for 32-bit and 64-bit systems.
> To avoid duplication of effort, I propose we come up with a
> common way of solving these problems.  Towards that end,
> I have placed the following document on my Web site that
> describes how I think this can be resolved:
> http://www.southern-storm.com.au/pinvoke.html
> Comments are welcome.
> Cheers,
> Rhys.
> P.S. Thanks to the person who mentioned "libffi" as a way
> of doing PInvoke.  That is a very nice library.