Windows Data Types

This section details the fundamental data types used throughout the Windows API. Understanding these types is crucial for effective interaction with the operating system and its services.

Basic Data Types

The Windows API utilizes standard C/C++ data types, often with platform-specific definitions for size and signedness to ensure consistency across different architectures.

Type Description Common Usage
INT Signed integer. Typically 32 bits. Counts, sizes, general-purpose integers.
UINT Unsigned integer. Typically 32 bits. Flags, counts, resource identifiers.
LONG Signed 32-bit integer. Similar to INT, often used in older APIs.
ULONG Unsigned 32-bit integer. Similar to UINT.
SHORT Signed 16-bit integer. Smaller values, specific hardware registers.
USHORT Unsigned 16-bit integer. Flags, resource identifiers.
CHAR Signed or unsigned 8-bit integer (platform-dependent). Individual characters, small byte values.
BYTE Unsigned 8-bit integer. Raw byte data, buffer elements.
BOOL Boolean value. TRUE (non-zero) or FALSE (zero). Return values indicating success/failure, status flags.
FLOAT Single-precision floating-point number. Calculations requiring decimal precision.
DOUBLE Double-precision floating-point number. Higher precision calculations.

Pointer and Handle Types

Pointers and handles are fundamental for referencing memory and system objects.

Type Description Common Usage
LPVOID Generic pointer to any type of data. Equivalent to void*. Passing generic data buffers, memory addresses.
PVOID Same as LPVOID.
HANDLE A generic handle to an object managed by the operating system. File handles, process handles, thread handles, window handles.
HMODULE Handle to a module (DLL or executable). Loading and managing modules.
HWND Handle to a window. Interacting with UI elements.

String Types

Windows supports both ANSI (ASCII) and Unicode (UTF-16) character sets. It's highly recommended to use Unicode for new development.

Type Description Character Set Common Usage
LPSTR Pointer to a null-terminated ANSI string. ANSI Legacy string operations.
LPCTSTR Pointer to a null-terminated string (char* or wchar_t* depending on build settings). TCHAR (ANSI or Unicode) Code that can compile for either character set.
LPCWSTR Pointer to a null-terminated Unicode (UTF-16) string. Unicode Modern string operations, internationalization.
LPWSTR Pointer to a modifiable null-terminated Unicode (UTF-16) string. Unicode Modifying Unicode strings.

Structure and Union Types

Structures (struct) and unions (union) are used to group related data items together. Many Windows API functions operate on specific structure types.

Examples include:

  • POINT: Represents a 2D point (X, Y coordinates).
  • RECT: Represents a rectangle defined by two points (top-left, bottom-right).
  • MSG: Contains message information for window messages.
  • SYSTEMTIME: Represents date and time information.

Refer to specific API documentation for the definitions of these structures.

Important Note on Data Type Size

On 64-bit Windows systems, pointers and the SIZE_T type (which represents sizes) are 64 bits. While many integer types remain 32 bits, it's essential to be aware of potential size differences when dealing with memory addresses and large quantities.

Understanding and correctly using these data types is fundamental to developing robust and efficient Windows applications.