3 Copyright 2010 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
17 /* Load all system libs from the windows system directory by prepending the
18 full path. This doesn't work for loadling cygwin1.dll. For this case,
19 instead of prepending the path, make sure that the CWD is removed from
20 the DLL search path, if possible (XP SP1++, Vista++). */
22 _load_sys_library (const wchar_t *dll)
24 static BOOL (*set_dll_directory)(LPCWSTR);
25 static WCHAR sysdir[MAX_PATH];
26 static UINT sysdir_len;
28 WCHAR dllpath[MAX_PATH];
32 sysdir_len = GetSystemDirectoryW (sysdir, MAX_PATH);
33 sysdir[sysdir_len++] = L'\\';
34 sysdir[sysdir_len] = L'\0';
36 if (!set_dll_directory)
38 HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
40 set_dll_directory = (BOOL (*)(LPCWSTR))
41 GetProcAddress (k32, "SetDllDirectoryW");
42 if (!set_dll_directory)
43 set_dll_directory = (BOOL (*)(LPCWSTR)) -1;
45 set_dll_directory (L"");
48 if (wcscmp (dll, L"cygwin1.dll") == 0)
49 return LoadLibraryExW (L"cygwin1.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
51 wcscpy (dllpath, sysdir);
52 wcscpy (dllpath + sysdir_len, dll);
53 return LoadLibraryExW (dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
56 #define LoadLibraryW(d) _load_sys_library(d)
57 #define LoadLibraryA(d) _load_sys_library(L##d)
59 #endif /* _LOADLIB_H */