[Mono-list] PInvoke Conventions

Fergus Henderson fjh@cs.mu.oz.au
Sat, 28 Jul 2001 00:18:17 +1000


On 26-Jul-2001, Miguel de Icaza <miguel@ximian.com> wrote:
> 
> After reading your message I am reconsidering bloating PInvoke and
> going for a less high-tech solution.
> 
> For the tricky bits that need to interface to the system, we could
> generate the code on the flight from a bunch of scripts that would map
> the actual sizes, layouts and constants for the system.
> 
> So basically we could use an autoconf-like system to probe the system,
> and generate the source code for a `Mono.System' assembly that would
> abstract things out.
> 
> The script could then based on this information spit out all the
> information we need.  It would take care of structures, and would also
> take care of mapping UNIX constants to C# constants.

One way to do this would be to write C programs that generate the C# files.
The C programs can include all the appropriate header files,

	#include <foo.h>

and can then output the values of the constants directly:

	printf("const int FOO = %d\n", FOO);

For structs and other types, the C program can use sizeof() and offsetof()
to ascertain the representation and/or layout, and can then output C# code
accordingly.

If this becomes cumbersome, and you want to get fancy, you can write a program
to generate the C programs that generate the C# files ;-)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.