GetWindowsDirectory

3.0

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

The GetWindowsDirectory function retrieves the path of the Windows directory. The Windows directory contains such files as Windows applications, initialization files, and help files.

Parameters

lpszSysPath

Points to the buffer that will receive the null-terminated string containing the path.

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 number specified in the cbSysPath parameter, it is the size of the buffer required to hold the path. The return value is zero if the function fails.

Comments

The Windows directory is the only directory where an application should create files. If the user is running a shared version of Windows, the Windows directory is the only directory guaranteed private to the user.

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

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

Example

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

WORD wReturn;
char szBuf[144];

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

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

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

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

See Also

GetSystemDirectory