MSDN Documentation

Windows API Reference

ULONG_PTR

The ULONG_PTR type is a pointer-sized unsigned integer type.

Remarks

This type is defined as follows:


#if defined(_WIN64)
    typedef unsigned __int64  ULONG_PTR;
#else
    typedef unsigned long     ULONG_PTR;
#endif
        

The size of ULONG_PTR is the same as the size of a pointer on the target architecture. On a 32-bit system, it is a 32-bit unsigned integer, and on a 64-bit system, it is a 64-bit unsigned integer. This type is often used for casting pointers to integers and vice versa, especially when the value needs to be stored or manipulated as an integer while retaining its pointer-like properties.

Usage Examples

When working with Windows API functions that accept or return pointer-sized values that are conceptually unsigned integers, ULONG_PTR is the appropriate type to use.


#include <windows.h>

// Example of casting a pointer to ULONG_PTR
void* myPointer = (void*)0x12345678;
ULONG_PTR pointerAsInteger = (ULONG_PTR)myPointer;

// Example of casting ULONG_PTR back to a pointer
void* recoveredPointer = (void*)pointerAsInteger;

// Using ULONG_PTR in a function signature (hypothetical)
DWORD GetPointerValue(ULONG_PTR ptr) {
    // ... processing logic ...
    return (DWORD)(ptr & 0xFFFFFFFF); // Example: extracting lower 32 bits
}
        

See Also

Requirements

Header
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header windef.h (include windef.h)
Library N/A
DLL N/A