[Mono-list] PInvoke Conventions

Rhys Weatherley rweather@zip.com.au
Wed, 18 Jul 2001 14:18:46 +1000


Bob Salita wrote:

> I can forsee this will require alot of back and forth.

Agreed.  It's a messy area.  I haven't even begun thinking
about marshaling struct's by value yet.  Ick.

> Every DllImport call has to be thunked, right? So wouldn't you thunk int to
> native int, long to native long?

The Windows version of PInvoke doesn't do this.  It always
thunks a numeric type to the same sized type, unless there is
an explicit override.  So, "long" maps to "__int64" under
Win32, not "native long", which is only 32 bits.  I'm following
the same conventions here.

I also want to use roughly the same marshaling conventions
for PInvoke and InternalCall methods, to allow code reuse.
Because InternalCall methods deal with CLR types, "long"
needs to map to "int64".

If there was a general consensus to do it your way, it could
be changed, but I'd like to get feedback from more people first.

> Also, the C compilers definition of int and long are all important, the OS
> or hardware word size are indirect factors. Right?

The C compiler's definitions are typically based on what the
OS or hardware dictates.

The CLR uses specific word sizes (32-bits or 64-bits) for
its values.  It's version of "int" and "long" do not have to
match what the C compiler is using.

Cheers,

Rhys.