GetSystemDirectory

3.0

  UINT GetSystemDirectory(lpszSysPath, cbSysPath)    
  LPSTR lpszSysPath; /* address of buffer for system directory */
  UINT cbSysPath; /* size of directory buffer */

The GetSystemDirectory function retrieves the path of the Windows system directory. The system directory contains such files as Windows libraries, drivers, and font files.

Parameters

lpszSysPath

Points to the buffer that is to receive the null-terminated string containing the path of the system directory.

cbSysPath

Specifies the maximum size, in bytes, of the buffer. This value should be set to at least 144 to allow sufficient room in the buffer for the path.

Return Value

The return value is the length, in bytes, of the string copied to the lpszSysPath parameter, not including the terminating null character. If the return value is greater than the size specified in the cbSysPath parameter, the return value is the size of the buffer required to hold the path. The return value is zero if the function fails.

Comments

Applications should not create files in the system directory. If the user is running a shared version of Windows, the application will not have write access to the system directory. Applications should create files only in the directory returned by the GetWindowsDirectory function.

The path that this function retrieves does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named WINDOWS\SYSTEM on drive C, the path of the system directory retrieved by this function is C:\WINDOWS\SYSTEM.

A similar function, GetSystemDir, is intended for use by MS-DOS applications that set up Windows applications. Windows applications should use GetSystemDirectory, not GetSystemDir.

Example

The following example uses the GetSystemDirectory function to determine the path of the Windows system directory:

WORD wReturn;
char szBuf[144];

wReturn = GetSystemDirectory((LPSTR) szBuf, sizeof(szBuf));



if (wReturn == 0)
    MessageBox(hwnd, "function failed",
        "GetSystemDirectory", MB_ICONEXCLAMATION);

else if (wReturn > sizeof(szBuf))
    MessageBox(hwnd, "buffer is too small",
        "GetSystemDirectory", MB_ICONEXCLAMATION);

else
    MessageBox(hwnd, szBuf, "GetSystemDirectory", MB_OK);

See Also

GetWindowsDirectory