Core Services API
This section details the fundamental Windows APIs that provide essential services for applications, enabling interaction with the operating system, managing processes, handling memory, and more.
Process Management
CreateProcess
BOOL CreateProcess(
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
Parameters
- lpApplicationName: The name of the module to be executed.
- lpCommandLine: The command line string for the executable.
- lpProcessAttributes: Security attributes for the new process.
- lpThreadAttributes: Security attributes for the new thread.
- bInheritHandles: If TRUE, inherits handles from the parent process.
- dwCreationFlags: Flags that control the execution.
- lpEnvironment: Pointer to the environment block.
- lpCurrentDirectory: The current directory for the new process.
- lpStartupInfo: Structure containing information about the new process's window.
- lpProcessInformation: Structure that receives information about the new process.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
Remarks
- Used to create a new process and its primary thread.
- The new process inherits handles from the calling process.
Memory Management
VirtualAlloc
LPVOID VirtualAlloc(
_In_opt_ LPVOID lpAddress,
_In_ SIZE_T dwSize,
_In_ DWORD flAllocationType,
_In_ DWORD flProtect
);
Parameters
- lpAddress: The desired starting address of the region to allocate.
- dwSize: The size of the region, in bytes.
- flAllocationType: The type of memory allocation.
- flProtect: Memory protection for the region of pages.
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.
Remarks
- Allocates a region of memory in the virtual address space of the calling process.
- Supports various allocation types and protection flags.
Inter-Process Communication (IPC)
CreatePipe
BOOL CreatePipe(
_Out_ PHANDLE hReadPipe,
_Out_ PHANDLE hWritePipe,
_In_opt_ LPSECURITY_ATTRIBUTES lpPipeAttributes,
_In_ DWORD nSize
);
Parameters
- hReadPipe: Pointer to a variable that receives the handle to the read end of the pipe.
- hWritePipe: Pointer to a variable that receives the handle to the write end of the pipe.
- lpPipeAttributes: Security attributes for the pipe.
- nSize: The size, in bytes, of the buffer for the pipe.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
Remarks
- Creates an anonymous pipe, which is a unidirectional data streaming mechanism.
- Useful for redirecting standard input/output between processes.
System Information
GetComputerName
BOOL GetComputerName(
_Out_ LPTSTR lpBuffer,
_Inout_ LPDWORD nSize
);
Parameters
- lpBuffer: A buffer that receives the name of the computer.
- nSize: A pointer to a variable that specifies the size of the buffer pointed to by lpBuffer, in characters.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
Remarks
- Retrieves the name of the local computer.
- The buffer size should be sufficient to hold {@code MAX_COMPUTERNAME_LENGTH + 1} characters.