IntPtr in 32 Bit OS, UInt64 in 64 bit OS

Posted by Ngu Soon Hui on Stack Overflow See other posts from Stack Overflow or by Ngu Soon Hui
Published on 2010-05-17T04:26:45Z Indexed on 2010/05/17 4:30 UTC
Read the original article Hit count: 341

Filed under:
|

I'm trying to do an interop to a C++ structure from C#. The structure ( in C# wrapper) is something like this

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SENSE4_CONTEXT
{


    public System.IntPtr dwIndex; //or UInt64, depending on platform.
    }

The underlying C++ structure is a bit abnormal. In 32 bit OS, dwIndex must be IntPtr in order for the interop to work, but in 64 bit OS, it must be UInt64 in order for the interop to work.

Any idea how to modify the above structure to make it work on both 32 and 64 bit OS?

© Stack Overflow or respective owner

Related posts about c#

Related posts about interop