Win32 API Data Types
This section details the fundamental data types used in the Windows API. Understanding these types is crucial for effective interaction with the operating system.
Primitive Data Types
These are the most basic building blocks for data representation in the Win32 API.
INT
A signed integer. Typically 32 bits on 32-bit systems and 64 bits on 64-bit systems.
Equivalent to int in C/C++.
UINT
An unsigned integer. Typically 32 bits on 32-bit systems and 64 bits on 64-bit systems.
Equivalent to unsigned int in C/C++.
BOOL
A boolean value. Can be TRUE (non-zero) or FALSE (zero).
Internally represented as an INT.
CHAR
A character. Typically 8 bits. Can be signed or unsigned depending on the compiler.
Equivalent to char in C/C++.
BYTE
An unsigned 8-bit integer. Used for byte-level operations.
Equivalent to unsigned char in C/C++.
WORD
An unsigned 16-bit integer.
Equivalent to unsigned short in C/C++.
DWORD
An unsigned 32-bit integer.
Equivalent to unsigned long in C/C++ (on most Win32 systems).
LONG
A signed 32-bit integer.
Equivalent to long in C/C++ (on most Win32 systems).
LONGLONG
A signed 64-bit integer.
Equivalent to long long in C/C++.
ULONGLONG
An unsigned 64-bit integer.
Equivalent to unsigned long long in C/C++.
FLOAT
A single-precision floating-point number (32-bit IEEE 754).
Equivalent to float in C/C++.
DOUBLE
A double-precision floating-point number (64-bit IEEE 754).
Equivalent to double in C/C++.
Pointer and Handle Types
Pointers and handles are fundamental for referencing memory and system objects.
LPVOID
A generic pointer to any type. Often used when a function can accept a pointer to various data structures.
Defined as void*.
PVOID
Synonym for LPVOID. Preferred in modern Windows programming.
HANDLE
A system-defined handle. Handles are abstract references to system objects like files, processes, threads, windows, etc. They are opaque and should not be directly manipulated.
Often defined as PVOID or an integer type, but its specific implementation is internal to the kernel.
HWND
Handle to a window.
HMODULE
Handle to a module (DLL or executable).
HPEN
Handle to a pen.
HBRUSH
Handle to a brush.
String Types
Windows supports both ANSI (ASCII) and Unicode (UTF-16) character sets for strings.
LPCSTR
Pointer to a constant C-style string of ANSI characters. (Long Pointer to Constant STRing)
Defined as const char*.
LPSTR
Pointer to a C-style string of ANSI characters. (Long Pointer to STRing)
Defined as char*.
LPCWSTR
Pointer to a constant C-style string of Unicode (UTF-16) characters. (Long Pointer to Constant Wide STRing)
Defined as const wchar_t*.
LPWSTR
Pointer to a C-style string of Unicode (UTF-16) characters. (Long Pointer to Wide STRing)
Defined as wchar_t*.
LPTSTR
Generic pointer to a string that can be either ANSI or Unicode, depending on the preprocessor definition of UNICODE. If UNICODE is defined, it maps to LPWSTR; otherwise, it maps to LPSTR.
LPCTSTR
Generic pointer to a constant string that can be either ANSI or Unicode.
If UNICODE is defined, it maps to LPCWSTR; otherwise, it maps to LPCSTR.
TEXT()
A macro used to define string literals that are compatible with both ANSI and Unicode builds. If UNICODE is defined, it converts the string literal to the wide-character form (e.g., L"MyString"); otherwise, it remains a normal string literal (e.g., "MyString").
Example: TCHAR szBuffer[100]; lstrcpy(szBuffer, TEXT("Hello, Windows!"));
Common Win32 Specific Types
These types are specific to the Windows operating system and are frequently encountered.
SIZE_T
An unsigned integer type large enough to hold the size of any object in bytes. Used for memory allocation sizes and object sizes.
On 32-bit systems, it's equivalent to unsigned long (DWORD). On 64-bit systems, it's equivalent to unsigned __int64 (ULONGLONG).
RECT
A structure representing the coordinates of the upper-left and lower-right corners of a rectangle.
Contains members: left, top, right, bottom (all LONG).
POINT
A structure representing a point in two-dimensional space.
Contains members: x, y (both LONG).
SECURITY_ATTRIBUTES
A structure that describes the security attributes of an object.
Used for specifying permissions and inheritance when creating objects like files or processes.
Type Prefixes and Conventions
The naming conventions for Win32 types follow a pattern:
Pprefix: Pointer (e.g.,PCHARis a pointer toCHAR).LPprefix: Long Pointer (historically used for 32-bit pointers, now often synonymous withP).Csuffix (on pointers): Constant (e.g.,LPCSTRis a Pointer to a Constant STRing).Wsuffix (on pointers): Wide character (Unicode) string (e.g.,LPWSTR).Tsuffix (on pointers): Generic text (ANSI/Unicode) string (e.g.,LPTSTR).Hprefix: Handle (e.g.,HWND,HANDLE).Ssuffix: Structure (e.g.,RECT,POINT).