I have a C library. It has many function calls like the following:
void init_foo( unsigned long x, unsigned long y );
The library itself is dynamically loaded at runtime (rather like a plugin). The headers are consistent across all platforms.
My problem is that on windows and 32bit linux, unsigned long is 32bits, yet on 64bit linux this is 64bits.
The various implementations of this library all accept this, you need to build your C program for the right target platform (as expected).
My interop method will need to be one of these depending on the architecture.
#if lin64
[DllImport("libfoo")]
public static void init_foo( Uint64 x, Uint64 y );
#else
[DllImport("libfoo")]
public static void init_foo( Uint32 x, Uint32 y );
#endif
The C# types I can use are fixed size on all platforms (as they should be). So my managed long passed from .Net/Mono will always be an unmanaged uint64_t.
How can I cope with this variable integer size yet have a single assembly that will run on .Net or mono in either 32bit or 64bit mode?