Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The parameter type of the function in windows api is DWORD_PTR. What type is this in c#?
The parameter type of the function in windows api is DWORD_PTR. What type is this in c#?
You'd better not use unsigned int directly for the following reasons:

You should pay attention to the compatibility of 32-bit and 64-bit about this DWORD_PTR.

DWORD was originally defined as an unsigned long integer, which means double word, one word is 2 bytes, and the double word is 32 bytes.

But in C/C++, it is often used to convert a pointer into a number to store, and then call it as a pointer. Then in a 32-bit system, the pointer is 32 bits long, and in a 64-bit system, the pointer is 64 bits long, so Microsoft has introduced types with _PTR, such as DWORD_PTR and INT_PTR. These types are guaranteed as follows: the original pointer can be obtained by converting the pointer to a type with _PTR and then back again without truncation. In the implementation, 32-bit programs and 64-bit programs have different definitions of DWORD_PTR, with 32-bit defined as unsigned long integer and 64-bit defined as unsigned __int64.

Based on this requirement, you'd better use similar functions provided by C#:

System. UIntPtr

This data type corresponds to the type with _PTR in C language, which ensures that the program can run normally on 32-bit platforms and 64-bit platforms, as well as the 128-bit platforms that will appear in the future.