The problem is that on 64-bit Windows C there is still 32-bit for a long time, unlike Linux, where it is 64-bit, and this causes a little pain.
If you do not plan to support 64-bit Windows, this is easy - you can match the long one with IntPtr in the definition of DllImport. IntPtr 32bit on both 32-bit windows and linux, which is just as long. Long on 64-bit Linux is also 64-bit, as well as IntPtr, however on Windows 64bit, while IntPtr is 64-bit 32-bit.
If you want to support 64-bit Windows, you can define two signatures at the same time - one for 64-bit and one for 32-bit:
[DllImport("libfoo", EntryPoint="init_foo")] public static void init_foo_64bit( Uint64 x, Uint64 y ); [DllImport("libfoo", EntryPoint="init_foo")] public static void init_foo_32bit( Uint32 x, Uint32 y );
Then, in your code, you can dynamically select at run time, which can be invoked as follows:
public void InvokeFoo(long x, long y) { if (Environment.Is64BitProcess) return init_foo_64bit(x, y); return init_foo_32bit((int)x, (int)y); }
PS: If you are not using .NET 4, another way to check if you are a 64-bit process would be bool is64Bit = IntPtr.Size == 8
Ivan Zlatev
source share