]> sourceware.org Git - newlib-cygwin.git/blame - winsup/utils/loadlib.h
* dcrt0.cc (_dll_crt0): Fix formatting.
[newlib-cygwin.git] / winsup / utils / loadlib.h
CommitLineData
71d8f118
CV
1/* loadlib.h
2
d7d8e7ce 3 Copyright 2010, 2011 Red Hat, Inc.
71d8f118
CV
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11#ifndef _LOADLIB_H
12#define _LOADLIB_H
13
14#include <windows.h>
15#include <wchar.h>
16
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++). */
d7d8e7ce
CV
21static HMODULE _load_sys_library (const wchar_t *dll) __attribute__ ((used));
22
71d8f118
CV
23static HMODULE
24_load_sys_library (const wchar_t *dll)
25{
26 static BOOL (*set_dll_directory)(LPCWSTR);
27 static WCHAR sysdir[MAX_PATH];
28 static UINT sysdir_len;
29
30 WCHAR dllpath[MAX_PATH];
31
32 if (!sysdir_len)
33 {
34 sysdir_len = GetSystemDirectoryW (sysdir, MAX_PATH);
35 sysdir[sysdir_len++] = L'\\';
36 sysdir[sysdir_len] = L'\0';
37 }
38 if (!set_dll_directory)
39 {
40 HMODULE k32 = GetModuleHandleW (L"kernel32.dll");
41 if (k32)
42 set_dll_directory = (BOOL (*)(LPCWSTR))
43 GetProcAddress (k32, "SetDllDirectoryW");
44 if (!set_dll_directory)
45 set_dll_directory = (BOOL (*)(LPCWSTR)) -1;
46 else
47 set_dll_directory (L"");
48 }
49
50 if (wcscmp (dll, L"cygwin1.dll") == 0)
51 return LoadLibraryExW (L"cygwin1.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
52
53 wcscpy (dllpath, sysdir);
54 wcscpy (dllpath + sysdir_len, dll);
55 return LoadLibraryExW (dllpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
56}
57
58#define LoadLibraryW(d) _load_sys_library(d)
59#define LoadLibraryA(d) _load_sys_library(L##d)
60
61#endif /* _LOADLIB_H */
This page took 0.046797 seconds and 5 git commands to generate.