[Mono-list] System.Data.OracleClient on z/Linux
cdhowie at gmail.com
Fri Feb 15 11:19:04 EST 2008
On Fri, Feb 15, 2008 at 9:56 AM, Jonathan Pryor <jonpryor at vt.edu> wrote:
> On Fri, 2008-02-15 at 15:18 +0100, Andreas Färber wrote:
> > Am 15.02.2008 um 02:28 schrieb Daniel Morgan:
> > > I'm not sure the proper way to marshal a
> > > size_t that will work on 32-bit and 64-bits systems.
> > > Perhaps someone reading this can shed some light.
> > What about IntPtr?
> Use UIntPtr, as size_t is unsigned. The only places that would fail are
> 64-bit platforms that define size_t as a 32-bit value, which is *broken*
> (and non-standard, iirc).
> - Jon
I use this technique in a project of mine too. To properly use this
technique, you are going to need to use the C# ulong type to represent
the value in your own code (not in the p/invoke declaration, but where
you use this value in your code) and use UIntPtr.ToUInt64() to obtain
the value, and then UIntPtr..ctor(UInt64) to pass values back.
Note that this raises an important issue: don't use hardcoded values
to raise the value of your ulong above uint.MaxValue -- if run on a
32-bit platform this will cause an overflow. (The
UIntPtr..ctor(UInt64) constructor will throw an exception in this
This is one of the most annoying things about p/invoke: handling 32-
and 64-bit platforms intelligently with the same code. Usually it's
not that difficult but sometimes it can be a royal PITA.
More information about the Mono-list