GetSystemDirectory function
Retrieves the path of the system directory. The system directory contains system files such as dynamic-link libraries (DLLs) and executables that are essential to the OS.
Syntax
UINT WINAPI GetSystemDirectory(
_Out_ LPTSTR lpBuffer,
_In_ UINT uSize
);
Parameters
Parameter | Type | Description |
---|---|---|
lpBuffer | LPTSTR | Pointer to a buffer that receives the system directory path. |
uSize | UINT | Size of the buffer, in TCHARs. |
Return value
If the function succeeds, the return value is the length of the string copied to lpBuffer
, not including the terminating null character.
If the buffer is too small, the return value is the required size, in characters, for the buffer, including the terminating null character. In this case, the contents of lpBuffer
are undefined.
If the function fails, the return value is zero. Use GetLastError
for extended error information.
Remarks
- The function does not guarantee that the path ends with a backslash.
- On Windows XP and later, the system directory is
C:\Windows\System32
for 32‑bit processes andC:\Windows\SysWOW64
for 64‑bit processes running under WOW64. - To retrieve the path of the Windows directory, use
GetWindowsDirectory
.
Example
#include <windows.h>
#include <stdio.h>
int main(void)
{
TCHAR szPath[MAX_PATH];
UINT len = GetSystemDirectory(szPath, MAX_PATH);
if (len == 0 || len > MAX_PATH) {
printf("Failed to get system directory. Error: %lu\n", GetLastError());
return 1;
}
printf("System Directory: %s\n", szPath);
return 0;
}
Output (example):
System Directory: C:\Windows\System32
System Directory: C:\Windows\System32