System Functions
This section provides documentation for Win32 API functions related to system-level operations, including process and thread management, system information retrieval, and time services.
Core System Functions
- GetCurrentProcessId
- GetCurrentThreadId
- GetTickCount
- GetSystemTimes
- GetComputerName
- GetUserName
- GetWindowsDirectory
- GetSystemDirectory
GetCurrentProcessId
Syntax
DWORD GetCurrentProcessId();
Parameters
This function has no parameters.
Return Value
The return value is the process identifier of the calling process.
Remarks
The process identifier is a 32-bit value that uniquely identifies the calling process on the system. This value is not guaranteed to be contiguous and can be reused after the process terminates.
See Also
GetCurrentThreadId
Syntax
DWORD GetCurrentThreadId();
Parameters
This function has no parameters.
Return Value
The return value is the thread identifier of the calling thread.
Remarks
The thread identifier is a 32-bit value that uniquely identifies the calling thread on the system. This value is not guaranteed to be contiguous and can be reused after the thread terminates.
See Also
GetTickCount
Syntax
DWORD GetTickCount();
Parameters
This function has no parameters.
Return Value
The return value is the number of milliseconds that have elapsed since the system was started. This function returns approximately every 49.7 days.
Remarks
Do not use the return value of GetTickCount
to calculate elapsed time. The value wraps around to 0 every 49.7 days. For time intervals longer than a few minutes, use the GetSystemTimeAsFileTime
function.
See Also
GetSystemTimes
Syntax
BOOL GetSystemTimes(
LPFILETIME lpIdleTime,
LPFILETIME lpKernelTime,
LPFILETIME lpUserTime
);
Parameters
lpIdleTime
: A pointer to aFILETIME
structure that receives the amount of time the system has been idle.lpKernelTime
: A pointer to aFILETIME
structure that receives the amount of time the system has spent in kernel mode.lpUserTime
: A pointer to aFILETIME
structure that receives the amount of time the system has spent in user mode.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
The FILETIME
structures receive values representing the total time the CPU has spent in each mode since the system was started. These values are independent of the GetTickCount
rollover.
See Also
GetComputerName
Syntax
BOOL GetComputerName(
LPTSTR lpBuffer,
LPDWORD nSize
);
Parameters
lpBuffer
: A pointer to a buffer that receives the null-terminated string specifying the computer name.nSize
: A pointer to aDWORD
variable that specifies the size, in characters, of the buffer pointed to bylpBuffer
. On input, this is the size of the buffer. On output, this is the number of characters copied to the buffer, not including the terminating null character.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
The computer name is the name assigned to the local computer. If the computer is a node in a domain, the name returned is the NetBIOS name of the computer.
See Also
GetUserName
Syntax
BOOL GetUserName(
LPTSTR lpBuffer,
LPDWORD pcbBuffer
);
Parameters
lpBuffer
: A pointer to a buffer that receives the null-terminated string specifying the user name.pcbBuffer
: A pointer to aDWORD
variable that specifies the size, in characters, of the buffer pointed to bylpBuffer
. On input, this is the size of the buffer. On output, this is the number of characters copied to the buffer, not including the terminating null character.
Return Value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
The user name is the name of the user who is currently logged on to the system. The name is typically in the form "DomainName\UserName" or "ComputerName\UserName".
See Also
GetWindowsDirectory
Syntax
UINT GetWindowsDirectory(
LPTSTR lpBuffer,
UINT uSize
);
Parameters
lpBuffer
: A pointer to a buffer that receives the null-terminated string specifying the path to the Windows directory.uSize
: The size, in characters, of the buffer pointed to bylpBuffer
.
Return Value
If the function succeeds, the return value is the length, in characters, of the string copied to lpBuffer
, not including the terminating null character. If the buffer is not large enough for the path, the return value is the size of the buffer required to hold the path, in characters, including the terminating null character. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
This function retrieves the full path to the Windows directory. The path does not end with a backslash.
See Also
GetSystemDirectory
Syntax
UINT GetSystemDirectory(
LPTSTR lpBuffer,
UINT uSize
);
Parameters
lpBuffer
: A pointer to a buffer that receives the null-terminated string specifying the path to the system directory.uSize
: The size, in characters, of the buffer pointed to bylpBuffer
.
Return Value
If the function succeeds, the return value is the length, in characters, of the string copied to lpBuffer
, not including the terminating null character. If the buffer is not large enough for the path, the return value is the size of the buffer required to hold the path, in characters, including the terminating null character. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
This function retrieves the full path to the system directory. The system directory contains files that are necessary for the operating system to run, such as device drivers and system DLLs. The path does not end with a backslash.