Microsoft KB Archive/281316

{|
 * width="100%"|

DOC: GetSystemWindowsDirectory Is Not Supported in Windows NT 4.0 Terminal Server Edition

 * }

Q281316

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), used with:
 * the operating system: Microsoft Windows NT 4.0

-

SUMMARY
The Platform SDK Documentation for the GetSystemWindowsDirectory API contains an error indicating that the function is supported in Windows NT 4.0 Terminal Server Edition for Service Pack 4 and later. This is not accurate. The GetSystemWindowsDirectory API is only supported in Windows 2000. An attempt to call the ANSI version of this function in Windows NT 4.0 will result in the following error:

Entry Point Not Found

The procedure entry point GetSystemWindowsDirectoryA could not be located in the dynamic link library KERNEL32.dll.

Unicode-based applications will get a similar message for GetSystemWindowsDirectoryW.

MORE INFORMATION
GetSystemWindowsDirectory is used to retrieve the path of the shared Windows directory on a multi-user system. This has the same effect as calling the GetWindowsDirectory API on a non-Terminal Server system.

On a system that is running Terminal Server, each user has a unique Windows directory. GetWindowsDirectory returns this unique directory and therefore cannot be used to retrieve the shared Windows directory. To retrieve the shared Windows directory on Windows NT 4.0 Terminal Server Edition, an application can call GetSystemDirectory and trim &quot;System32&quot; from the end of the returned path.

Sample Code
The following sample code demonstrates how to retrieve the shared Windows directory for both Windows NT 4.0 and Windows 2000. If the operating system is Windows 2000 or later, this code makes a call to GetSystemWindowsDirectory. Otherwise, it calls GetSystemDirectory and then trims the last element from the returned path.

#include 
 * 1) include 
 * 2) include 

typedef UINT (STDMETHODCALLTYPE FAR * PFNGETSYSTEMWINDOWSDIRECTORY) (  LPTSTR lpBuffer,   UINT uSize );

PFNGETSYSTEMWINDOWSDIRECTORY fnGetSystemWindowsDirectory = NULL;


 * 1) ifdef UNICODE
 * 2) define GETSYSTEMWINDOWSDIRECTORY &quot;GetSystemWindowsDirectoryW&quot;
 * 3) else
 * 4) define GETSYSTEMWINDOWSDIRECTORY &quot;GetSystemWindowsDirectoryA&quot;
 * 5) endif

void main {

TCHAR szWindowsDir[MAX_PATH]; PTCHAR pBackslash;

// Determine the OS version OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(osvi)); osvi.dwOSVersionInfoSize = sizeof(osvi);

if(!GetVersionEx(&osvi)) { _tprintf(_T(&quot;GetVersionEx failed with error %d\n&quot;),            GetLastError); return; }

if (osvi.dwMajorVersion >= 5) { // On Windows 2000 or later, use GetSystemWindowsDirectory fnGetSystemWindowsDirectory = (PFNGETSYSTEMWINDOWSDIRECTORY) GetProcAddress(            GetModuleHandle(_T(&quot;kernel32.dll&quot;)),            GETSYSTEMWINDOWSDIRECTORY);

fnGetSystemWindowsDirectory(szWindowsDir, MAX_PATH);

} else {

// On earlier systems, use GetSystemDirectory GetSystemDirectory(szWindowsDir, MAX_PATH);

// Locate the last element of the path (the System32 directory) pBackslash = _tcsrchr(szWindowsDir, _T('\\'));

// Truncate the string to exclude the last element *pBackslash = _T('\0'); }

_tprintf(_T(&quot;%s\n&quot;), szWindowsDir); } Additional query words:

Keywords : kbdocerr kbAPI kbKernBase kbOSWinNT400bug kbSDKWin32 kbOSWinNT400sp4bug kbDSupport kbGrpDSKernBase

Issue type : kbbug

Technology : kbAudDeveloper kbWin32sSearch kbWin32API