DWORD
Unsigned 32-bit integer
typedef unsigned long DWORD;
On this page
Description
A 32-bit unsigned integer. This data type is defined in WinDef.h
.
The DWORD
type is a fundamental data type used throughout the Windows API to represent unsigned integer values that are 32 bits in size.
Definition
<syntaxhighlight lang="c++">
typedef unsigned long DWORD;
</syntaxhighlight>
Remarks
DWORD
is commonly used for:
- Bit flags: For manipulating individual bits within a 32-bit value.
- Counters and sizes: Representing counts or memory sizes up to 232 - 1.
- Return values: Many functions return a
DWORD
to indicate status or results. - Data buffers: Allocating and managing blocks of memory.
On systems where long
is 64 bits (e.g., some Unix-like systems), the size of DWORD
might not be 32 bits as expected. However, on Windows, long
is typically 32 bits, making DWORD
consistently a 32-bit unsigned integer.
For guaranteed 32-bit unsigned integer behavior across different platforms or compiler settings, you might consider using uint32_t
from the C++ <cstdint> header.
Example Usage
The following snippet demonstrates setting a bit flag using a DWORD
:
<syntaxhighlight lang="c++">
#include <windows.h>
void SetBitFlag(DWORD* flags, DWORD flagToSet) {
*flags |= flagToSet; // Use bitwise OR to set the flag
}
int main() {
DWORD myFlags = 0;
DWORD SPECIFIC_FLAG = 0x00000001; // Example flag
SetBitFlag(&myFlags, SPECIFIC_FLAG);
if (myFlags & SPECIFIC_FLAG) {
// The flag is set
}
return 0;
}
</syntaxhighlight>