GetCurrentProcessId

The GetCurrentProcessId function retrieves the identifier of the current process. The process identifier is a system-wide unique value that you can use to identify a process.

Syntax

DWORD GetCurrentProcessId();

This function takes no parameters.

Return Value

The return value is the process identifier of the calling process. This identifier is unique for each process.

Remarks

The process identifier is a 32-bit value that uniquely identifies a process. It can be used for various purposes, such as:

Note that the process identifier is only guaranteed to be unique while the process is running. Once a process terminates, its identifier may be reused by a new process.

Example

The following example demonstrates how to use GetCurrentProcessId to retrieve and display the current process's ID.

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

int main() {
    DWORD processId = GetCurrentProcessId();
    std::wcout << L"The current process ID is: " << processId << std::endl;
    return 0;
}