Data Types

This section provides detailed information about the fundamental data types used in the Windows API. Understanding these types is crucial for correctly interacting with Windows system services and programming robust applications.

Basic Data Types

These are the building blocks for most data manipulation within the Windows ecosystem.

INT

Represents a signed integer. The size of INT can vary depending on the architecture, but it is typically 32 bits on 32-bit systems and 64 bits on 64-bit systems. Use INT32 or INT64 for explicit sizing.

typedef int INT;

Example Use: Loop counters, variable storage.

UINT

Represents an unsigned integer. Similar to INT, its size is architecture-dependent. Use UINT32 or UINT64 for explicit sizing.

typedef unsigned int UINT;

Example Use: Bit flags, sizes, indices.

BOOL

A boolean type, typically represented as an integer. TRUE evaluates to 1, and FALSE evaluates to 0. Non-zero values are also treated as true.

typedef int BOOL;

Example Use: Return values for success/failure, flags.

CHAR

Represents a single character, typically 8 bits. Can be signed or unsigned depending on the compiler's default.

typedef char CHAR;

Example Use: Character manipulation, small data buffers.

BYTE

An unsigned 8-bit integer. Guaranteed to be 8 bits.

typedef unsigned char BYTE;

Example Use: Raw byte data, binary streams.

WORD

An unsigned 16-bit integer.

typedef unsigned short WORD;

Example Use: Hardware registers, specific data formats.

DWORD

An unsigned 32-bit integer. Very commonly used in the Windows API.

typedef unsigned long DWORD;

Example Use: Error codes, flags, sizes, handles.

LONG

A signed 32-bit integer.

typedef long LONG;

Example Use: Signed integer values where 32 bits are required.

LONGLONG

A signed 64-bit integer.

typedef signed __int64 LONGLONG;

Example Use: Large numeric values, timestamps.

ULONGLONG

An unsigned 64-bit integer.

typedef unsigned __int64 ULONGLONG;

Example Use: Large unsigned numeric values, memory sizes.

String Types

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

LPSTR (or PSTR)

A pointer to a null-terminated string of ANSI characters (char*).

typedef char *LPSTR, *PSTR;

Note: Use LPCSTR for pointers to constant ANSI strings.

LPWSTR (or PWSTR)

A pointer to a null-terminated string of Unicode characters (wchar_t*). This is the preferred type for strings.

typedef wchar_t *LPWSTR, *PWSTR;

Note: Use LPCWSTR for pointers to constant Unicode strings.

TCHAR

A generic character type that can be either char or wchar_t, depending on the UNICODE preprocessor macro definition. Use this for code that needs to be portable between ANSI and Unicode builds.

#ifdef UNICODE
    typedef wchar_t TCHAR;
#else
    typedef char TCHAR;
#endif

Note: Use LPTSTR and LPCTSTR for pointers to TCHAR strings.

Pointer and Handle Types

Pointers and handles are fundamental for memory management and object referencing.

LPVOID (or VOID*)

A generic pointer to any type. Equivalent to void*.

typedef void *LPVOID;

Example Use: Passing generic data buffers to functions.

HANDLE

A generic handle type. A handle is an identifier that represents a system object such as a process, thread, file, or registry key. The actual data structure it points to is opaque to the application.

typedef void *HANDLE; // Simplified representation; actual type is usually void*

Example Use: Interacting with kernel objects (e.g., CreateFile returns a HANDLE).

Commonly Used Fixed-Size Types

For explicit control over data size, Windows defines specific types:

Type Description C/C++ Equivalent
INT8 8-bit signed integer signed char
UINT8 8-bit unsigned integer unsigned char
INT16 16-bit signed integer short
UINT16 16-bit unsigned integer unsigned short
INT32 32-bit signed integer long
UINT32 32-bit unsigned integer unsigned long
INT64 64-bit signed integer long long
UINT64 64-bit unsigned integer unsigned long long