Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should DWORD map to int or uint?

When translating the Windows API (including data types) into P/Invoke, should I replace DWORD with int or uint?

It's normally unsigned, but I see people using int everywhere instead (is it just because of the CLS warning? even the .NET Framework itself does this), and so I'm never really sure which one is the correct one to use.

like image 459
user541686 Avatar asked Jul 17 '11 17:07

user541686


People also ask

Is a DWORD an integer?

A DWORD is a 32-bit unsigned integer (range: 0 through 4294967295 decimal).

What is the difference between int and UINT?

uint means “unsigned integer” while int means “signed integer”. Unsigned integers only contain positive numbers (or zero).

What is DWORD used for?

A dword, which is short for "double word," is a data type definition that is specific to Microsoft Windows. When defined in the file windows. h, a dword is an unsigned, 32-bit unit of data. It can contain an integer value in the range 0 through 4,294,967,295.


1 Answers

Well according to the MSDN DWORD is an unsigned integer with a range of 0 to 4294967295.

So ideally you should replace it with uint rather than int.

However, as you have spotted uint is non-CLS compliant so if your method is publicly visible you should use int and do the conversion. The corollary to that is that if your method isn't used outside your assembly you should mark it as internal rather than public. Then you'll be able use a uint.

like image 112
ChrisF Avatar answered Sep 20 '22 16:09

ChrisF