This article will cover the general use of
DWORD in C++, and it’s fundamentally different from
unsigned int even though they currently have the same value.
unsigned int in C++
By definition, the
unsigned int is at least 16 bits long. The
unsigned int is usually platform-specific.
WORD is 16 bits long,
DWORD is 32 bits across all platforms. Furthermore,
DWORD is not a type in C++; it is instead defined in
DWORD whenever the code is expecting a
DWORD, even though (as of writing this article) the
unsigned int would work just as well.
Future versions of C++ could have a slightly different definition of the
unsigned int (which would still adhere to the C++ guidelines), whereas the
DWORD is unlikely to change.
Microsoft chose to define its
DWORD and why many other API developers choose to define their types.
Microsoft had to work around the issues of different CPU architectures, i.e., having 16-bit and 32-bit processors, and lately, 64-bit processors.
In the 1980s, C++ compilers were not standardized as well. There was a certain degree of compatibility needed between different OSes.
Furthermore, the same development API (now known as
WinAPI) was used for desktops, mobile chips, embedded systems, and servers.
Hence, having type definitions like
DWORD helped when working between different systems, programming languages, compilers, etc.