Win32 API Documentation

The Win32 API (Application Programming Interface) is a set of functions and interfaces that allow applications to interact with the Microsoft Windows operating system. It provides access to a wide range of functionalities, from low-level hardware control to high-level user interface elements.

Memory Management

Functions for allocating, deallocating, and managing memory.

VirtualAlloc

Reserves or commits a region of pages in the virtual address space of the calling process.

LPVOID VirtualAlloc(
  LPVOID lpAddress,
  SIZE_T dwSize,
  DWORD  flAllocationType,
  DWORD  flProtect
);

Parameters

Name Type Description
lpAddress LPVOID The starting address of the region of pages to allocate. If this parameter is NULL, the system determines where to allocate the region.
dwSize SIZE_T The size of the region of pages to allocate, in bytes.
flAllocationType DWORD The type of memory allocation. This parameter can be one of the following values: MEM_COMMIT, MEM_RESERVE.
flProtect DWORD The memory protection for the region of pages to be allocated. This parameter can be one of the following values: PAGE_EXECUTE, PAGE_READONLY, PAGE_READWRITE, PAGE_WRITECOPY, etc.

Return Value

If the function succeeds, the return value is the base address of the allocated region. If the function fails, the return value is NULL.

Note: Ensure proper handling of memory leaks by calling VirtualFree when the allocated memory is no longer needed.

Process & Thread Management

Functions for creating, managing, and terminating processes and threads.

CreateProcess

Creates a new process and its primary thread. The new process runs in the same address space of the calling process.

BOOL CreateProcess(
  LPCTSTR               lpApplicationName,
  LPTSTR                lpCommandLine,
  LPSECURITY_ATTRIBUTES lpProcessAttributes,
  LPSECURITY_ATTRIBUTES lpThreadAttributes,
  BOOL                  bInheritHandles,
  DWORD                 dwCreationFlags,
  LPVOID                lpEnvironment,
  LPCTSTR               lpCurrentDirectory,
  LPSTARTUPINFO         lpStartupInfo,
  LPPROCESS_INFORMATION lpProcessInformation
);

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero.

Important: The lpProcessInformation structure receives the handles and identifiers for the new process and its primary thread. These should be closed when no longer needed.

File I/O

Functions for interacting with files and file system objects.

CreateFile

Creates or opens a file or I/O device (such as a disk drive, removable media, or communications resource).

HANDLE CreateFile(
  LPCTSTR               lpFileName,
  DWORD                 dwDesiredAccess,
  DWORD                 dwShareMode,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD                 dwCreationDisposition,
  DWORD                 dwFlagsAndAttributes,
  HANDLE                hTemplateFile
);

Return Value

If the function succeeds, the return value is an open handle to the specified file or device. If the function fails, the return value is INVALID_HANDLE_VALUE.

Always check the return value of CreateFile and handle potential errors.

Window Management

Functions for creating and managing windows, dialog boxes, and controls.

CreateWindowEx

Creates an overlapped, pop-up, or child window. It can be used to create a child window that has the WS_EX_TRANSPARENT style.

HWND CreateWindowEx(
  DWORD     dwExStyle,
  LPCTSTR   lpClassName,
  LPCTSTR   lpWindowName,
  DWORD     dwStyle,
  int       x,
  int       y,
  int       nWidth,
  int       nHeight,
  HWND      hWndParent,
  HMENU     hMenu,
  HINSTANCE hInstance,
  LPVOID    lpParam
);

Return Value

If the function succeeds, the return value is a handle to the new window. Otherwise, it is NULL.

Graphics Device Interface (GDI)

Functions for performing graphics operations such as drawing lines, shapes, text, and images.

CreateSolidBrush

Creates a GDI brush object that is a solid color.

HBRUSH CreateSolidBrush(
  COLORREF color
);

Parameters

Name Type Description
color COLORREF The RGB color value for the brush.

Return Value

If the function succeeds, the return value is a handle to the new GDI brush object. If the function fails, it is NULL.

Remember to delete brush objects using DeleteObject when they are no longer needed to prevent resource leaks.

Common API Categories

This page provides a glimpse into the vast capabilities of the Win32 API. For comprehensive details, please refer to the official Microsoft documentation.