views:

244

answers:

2

Hi there,

I am having to pass a ULONG_PTR in unsafe code in C#.

I understand that the reason for ULONG_PTR is to allow for a single codebase for both 32bit and 64bit operating systems.

Is this a case for C#'s UIntPtr? Can I be confident when passing a .Net UIntPtr as an ULONG_PTR parameter?

Thanks!

+1  A: 

Based on the MSDN description of it I would say that it should be:

The UIntPtr type is designed to be an integer whose size is platform-specific. That is, an instance of this type is expected to be 32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit hardware and operating systems.

Adam Gritt
A: 

From MSDN:

The IntPtr type is CLS-compliant, while the UIntPtr type is not. Only the IntPtr type is used in the common language runtime. The UIntPtr type is provided mostly to maintain architectural symmetry with the IntPtr type

Both types are capable of storing 32-bit and 64-bit pointers. The preferred type is IntPtr.

Darin Dimitrov