Process and Thread Management
This section covers functions related to creating, managing, and terminating processes and threads on Windows.
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
);
Description: Creates a new process and its primary thread. The new process is launched under the security context of 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 thread.bInheritHandles
: Whether to inherit handles from the parent.dwCreationFlags
: Flags that control the execution priority and state of the new process.lpEnvironment
: Pointer to the environment block for the new process.lpCurrentDirectory
: The full path of the current directory.lpStartupInfo
: A pointer to a STARTUPINFO structure that specifies how to create the main window for the new process.lpProcessInformation
: A pointer to a PROCESS_INFORMATION structure that receives identification information for the new process and its primary thread.
Return Value: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
See Also: ExitProcess, TerminateProcess, CreateThread
GetCurrentProcessId
DWORD GetCurrentProcessId(void);
Description: Retrieves the identifier of the current process.
Return Value: The return value is the process identifier.
See Also: GetCurrentThreadId
CreateThread
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);
Description: Creates a thread to execute within the virtual address space of the calling process.
Parameters:
lpThreadAttributes
: Security attributes for the thread.dwStackSize
: The initial size, in bytes, of the stack for the new thread.lpStartAddress
: A pointer to the application-defined function to be executed by the thread.lpParameter
: The argument to be passed to the thread function.dwCreationFlags
: Flags that control the creation of the thread.lpThreadId
: A pointer to a 32-bit value that receives the thread identifier.
Return Value: If the function succeeds, the return value is a handle to the new thread. If the function fails, the return value is NULL.
See Also: CreateProcess, ExitThread, TerminateThread
ExitProcess
VOID ExitProcess(UINT uExitCode);
Description: Terminates the calling process and all of its threads.
Parameters:
uExitCode
: The exit code for the process.
Note: This function does not return.