Windows API Reference: Kernel Support

This section provides documentation for the core Windows Kernel APIs, enabling you to interact with the operating system at its lowest levels.

Process and Thread Management

CreateProcess

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
);

Creates a new process and its primary thread. The new process runs in the same directory and with the same environment as the calling process.

Parameters:
  • lpApplicationName: The name of the module to be executed.
  • lpCommandLine: The command line for the new process.
  • lpProcessAttributes: Security attributes for the process.
  • lpThreadAttributes: Security attributes for the primary thread.
  • bInheritHandles: Inherit handles from the parent process.
  • dwCreationFlags: Flags that control the priority class and behavior.
  • lpEnvironment: Environment block for the new process.
  • lpCurrentDirectory: The current directory for the new process.
  • lpStartupInfo: Startup information for the new process.
  • lpProcessInformation: Receives information about the new process and its primary thread.
Return Value: Nonzero if successful, zero otherwise.

Example Usage (C++)

#include <windows.h>
#include <iostream>

int main() {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    if (CreateProcess(
        NULL, // lpApplicationName
        "notepad.exe", // lpCommandLine
        NULL, // lpProcessAttributes
        NULL, // lpThreadAttributes
        FALSE, // bInheritHandles
        0, // dwCreationFlags
        NULL, // lpEnvironment
        NULL, // lpCurrentDirectory
        &si, // lpStartupInfo
        &pi ) // lpProcessInformation
    {
        std::cout << "Process created successfully." << std::endl;

        // Wait until child process exits.
        WaitForSingleObject(pi.hProcess, INFINITE);

        // Close process and thread handles.
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
    } else {
        std::cerr << "CreateProcess failed: " << GetLastError() << std::endl;
    }

    return 0;
}

Inter-Process Communication (IPC)

CreatePipe

BOOL CreatePipe(
  PHANDLE hReadPipe,
  PHANDLE hWritePipe,
  LPSECURITY_ATTRIBUTES lpAttribute,
  DWORD nSize
);

Creates an anonymous pipe, a unidirectional data-flow mechanism. Data written to the write end of the pipe is read from the read end.

Parameters:
  • hReadPipe: A pointer to a variable that receives the handle to the read end of the pipe.
  • hWritePipe: A pointer to a variable that receives the handle to the write end of the pipe.
  • lpAttribute: Security attributes for the pipe.
  • nSize: The size of the buffer, in bytes. If 0, uses default.
Return Value: Nonzero if successful, zero otherwise.

System Information

GetSystemInfo

VOID GetSystemInfo(
  LPSYSTEM_INFO lpSystemInfo
);

Populates the supplied SYSTEM_INFO structure with information about the current system.

Parameters:
  • lpSystemInfo: A pointer to a SYSTEM_INFO structure that receives the information.
Return Value: None.

Example Usage (C++)

#include <windows.h>
#include <iostream>

int main() {
    SYSTEM_INFO sysInfo;
    GetSystemInfo(&sysInfo);

    std::cout << "Processor Architecture: " << sysInfo.wProcessorArchitecture << std::endl;
    std::cout << "Number of Processors: " << sysInfo.dwNumberOfProcessors << std::endl;
    std::cout << "Page Size: " << sysInfo.dwPageSize << " bytes" << std::endl;

    return 0;
}