ULONG
The ULONG type is an unsigned integer that is the same size as a pointer on the target platform.
Type Definition
Defined in the Windows headers as:
typedef unsigned long ULONG;
Description
The ULONG type is an unsigned integral type. Its size is platform-dependent, meaning it will be 32 bits on a 32-bit system and 64 bits on a 64-bit system. This makes it a versatile type for storing counts, sizes, or identifiers where the value is guaranteed to be non-negative and might need to adapt to different architectures.
It is commonly used for:
- Resource identifiers
- Counts of items
- Sizes of data buffers
- Flags that represent distinct states or options
When dealing with values that could potentially exceed the range of a signed integer or when the mathematical representation naturally involves only non-negative numbers, ULONG is the appropriate choice.
Usage Examples
Example 1: Storing a handle
#include <windows.h>
// Assume some function returns a ULONG handle
ULONG hFile = 0x1A2B3C4D;
if (hFile != 0) {
// Use the handle
// ...
}
Example 2: Iterating with a counter
#include <windows.h>
ULONG itemCount = 10;
for (ULONG i = 0; i < itemCount; ++i) {
// Process item i
// ...
}