Core APIs

The Core APIs are the foundational building blocks for developing applications on the Windows platform. They provide access to fundamental operating system services, including process and thread management, memory allocation, file system operations, and inter-process communication.

Key Subsystems

Commonly Used Core APIs

API Function Description Header File
CreateProcess Creates a new process and its primary thread. windows.h
VirtualAlloc Reserves, commits, or changes the state of a region of pages in the virtual address space of the calling process. windows.h
CreateFile Creates or opens a file or I/O device. windows.h
GetLastError Retrieves the last error code set by a failed function call. windows.h
ExitProcess Terminates the current process. windows.h
MapViewOfFile Maps a view of a file mapping into the address space of the calling process. windows.h

CreateProcess

The CreateProcess function is fundamental for launching new applications or processes. It allows you to specify the executable to run, command-line arguments, environment variables, and security attributes.

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
);
Note: Understanding the various flags and structures passed to CreateProcess is crucial for robust process management.

VirtualAlloc

Memory management is handled by functions like VirtualAlloc, which provides granular control over the virtual address space. This is essential for efficient resource utilization and implementing complex memory allocation strategies.

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

CreateFile

Interact with the file system using CreateFile. This versatile function can open existing files, create new ones, and access various device drivers, providing the gateway to persistent storage.

HANDLE CreateFile(
  LPCTSTR               lpFileName,
  DWORD                 dwDesiredAccess,
  DWORD                 dwShareMode,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD                 dwCreationDisposition,
  DWORD                 dwFlagsAndAttributes,
  HANDLE                hTemplateFile
);
Tip: Always check the return value of file operations and use GetLastError to diagnose any issues.

GetLastError

Error reporting is critical for debugging and system stability. GetLastError is the primary mechanism for retrieving detailed error information after a Windows API function fails.

DWORD GetLastError(void);

ExitProcess

Gracefully terminate a process using ExitProcess. This function ensures that cleanup routines are called before the process terminates.

VOID ExitProcess(UINT uExitCode);

MapViewOfFile

For efficient data sharing and large file access, memory-mapped files are indispensable. MapViewOfFile maps a section of a file mapping into the process's address space.

LPVOID MapViewOfFile(
  HANDLE hFileMappingObject,
  DWORD  dwDesiredAccess,
  DWORD  dwFileOffsetHigh,
  DWORD  dwFileOffsetLow,
  SIZE_T dwNumberOfBytesToMap
);
Warning: Improper use of memory mapping can lead to security vulnerabilities and data corruption. Ensure proper synchronization and access control.

Explore the documentation for each subsystem to gain a deeper understanding of the vast capabilities provided by the Windows Core APIs.