]> sourceware.org Git - newlib-cygwin.git/blame - winsup/utils/loadlib.h
Cygwin: add 3.2.1 release file and add fixes up to this point
[newlib-cygwin.git] / winsup / utils / loadlib.h
CommitLineData
71d8f118
CV
1/* loadlib.h
2
71d8f118
CV
3 This file is part of Cygwin.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9#ifndef _LOADLIB_H
10#define _LOADLIB_H
11
12#include <windows.h>
13#include <wchar.h>
14
15/* Load all system libs from the windows system directory by prepending the
16 full path. This doesn't work for loadling cygwin1.dll. For this case,
17 instead of prepending the path, make sure that the CWD is removed from
18 the DLL search path, if possible (XP SP1++, Vista++). */
d7d8e7ce
CV
19static HMODULE _load_sys_library (const wchar_t *dll) __attribute__ ((used));
20
71d8f118
CV
21static HMODULE
22_load_sys_library (const wchar_t *dll)
23{
29413f06 24 static BOOL WINAPI (*set_dll_directory)(LPCWSTR);
71d8f118
CV
25 static WCHAR sysdir[MAX_PATH];
26 static UINT sysdir_len;
27
28 WCHAR dllpath[MAX_PATH];
29
30 if (!sysdir_len)
31 {
32 sysdir_len = GetSystemDirectoryW (sysdir, MAX_PATH);
33 sysdir[sysdir_len++] = L'\\';
34 sysdir[sysdir_len] = L'\0';
35 }
36 if (!set_dll_directory)
37 {
38 HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
39 if (k32)
29413f06 40 set_dll_directory = (BOOL WINAPI (*)(LPCWSTR))
71d8f118
CV
41 GetProcAddress (k32, "SetDllDirectoryW");
42 if (!set_dll_directory)
29413f06 43 set_dll_directory = (BOOL WINAPI (*)(LPCWSTR)) -1;
71d8f118
CV
44 else
45 set_dll_directory (L"");
46 }
47
48 if (wcscmp (dll, L"cygwin1.dll") == 0)
49 return LoadLibraryExW (L"cygwin1.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
1b23b30b 50
71d8f118
CV
51 wcscpy (dllpath, sysdir);
52 wcscpy (dllpath + sysdir_len, dll);
53 return LoadLibraryExW (dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
54}
55
56#define LoadLibraryW(d) _load_sys_library(d)
57#define LoadLibraryA(d) _load_sys_library(L##d)
58
59#endif /* _LOADLIB_H */
This page took 0.128342 seconds and 5 git commands to generate.