简体   繁体   中英

C# ULONG_PTR Equivalent

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!

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM