On 03/25/10 Alan McGovern wrote:
> If you don't want to do that, there's really very little - if anything
> - you can do other than guess and write multiple P/Invokes for each
> case. For example you could write two p/invoke signatues, one which
> maps a C long to a .NET int and one which maps it to a .NET long. Then
> at runtime you can detect what platform you're on and whether it's
> 64bit or 32bit and then make a guess as to which function will not
> blow up when you call it. This isn't a great approach unless you're
> positive you know all the platforms you're going to run on ;)

Using two p/invoke methods is actually the only sensible way if support
for windows64 is needed (in the other cases using U/IntPtr is the correct
thing to do). As for having to know all the platforms: it's not a real
issue, since it's very likely that MS will remain the only stupid company
that made that choice.

In either case, I suggest having a frontend method that takes
(C#)long/ulong types and invokes the appropriate p/invoke method.
Use a 

        static readonly bool use_long_signature = detection_logic ();

flag, so the jit will completely optimize away the flag check at
runtime.

lupus

-- 
-----------------------------------------------------------------
[email protected]                                     debian/rules
[email protected]                             Monkeys do it better
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to