]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // dll.hpp --------------------------------------------------------------// |
2 | ||
3 | // Copyright 2010 Vicente J. Botet Escriba | |
4 | // Copyright 2014 Renato Tegon Forti, Antony Polukhin | |
5 | // Copyright 2015 Andrey Semashev | |
6 | // Copyright 2015 Antony Polukhin | |
7 | ||
8 | // Distributed under the Boost Software License, Version 1.0. | |
9 | // See http://www.boost.org/LICENSE_1_0.txt | |
10 | ||
11 | ||
12 | #ifndef BOOST_DETAIL_WINAPI_DLL_HPP | |
13 | #define BOOST_DETAIL_WINAPI_DLL_HPP | |
14 | ||
15 | #include <boost/detail/winapi/basic_types.hpp> | |
16 | ||
17 | #ifdef BOOST_HAS_PRAGMA_ONCE | |
18 | #pragma once | |
19 | #endif | |
20 | ||
21 | #if !defined( BOOST_USE_WINDOWS_H ) | |
22 | extern "C" { | |
23 | namespace boost { namespace detail { namespace winapi { | |
24 | #ifdef _WIN64 | |
25 | typedef INT_PTR_ (WINAPI *FARPROC_)(); | |
26 | typedef INT_PTR_ (WINAPI *NEARPROC_)(); | |
27 | typedef INT_PTR_ (WINAPI *PROC_)(); | |
28 | #else | |
29 | typedef int (WINAPI *FARPROC_)(); | |
30 | typedef int (WINAPI *NEARPROC_)(); | |
31 | typedef int (WINAPI *PROC_)(); | |
32 | #endif // _WIN64 | |
33 | }}} // namespace boost::detail::winapi | |
34 | ||
35 | #if !defined( BOOST_NO_ANSI_APIS ) | |
36 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI | |
37 | LoadLibraryA(boost::detail::winapi::LPCSTR_ lpFileName); | |
38 | ||
39 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI | |
40 | LoadLibraryExA( | |
41 | boost::detail::winapi::LPCSTR_ lpFileName, | |
42 | boost::detail::winapi::HANDLE_ hFile, | |
43 | boost::detail::winapi::DWORD_ dwFlags | |
44 | ); | |
45 | ||
46 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI | |
47 | GetModuleHandleA(boost::detail::winapi::LPCSTR_ lpFileName); | |
48 | ||
49 | BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI | |
50 | GetModuleFileNameA( | |
51 | boost::detail::winapi::HMODULE_ hModule, | |
52 | boost::detail::winapi::LPSTR_ lpFilename, | |
53 | boost::detail::winapi::DWORD_ nSize | |
54 | ); | |
55 | #endif | |
56 | ||
57 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI | |
58 | LoadLibraryW(boost::detail::winapi::LPCWSTR_ lpFileName); | |
59 | ||
60 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI | |
61 | LoadLibraryExW( | |
62 | boost::detail::winapi::LPCWSTR_ lpFileName, | |
63 | boost::detail::winapi::HANDLE_ hFile, | |
64 | boost::detail::winapi::DWORD_ dwFlags | |
65 | ); | |
66 | ||
67 | BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI | |
68 | GetModuleHandleW(boost::detail::winapi::LPCWSTR_ lpFileName); | |
69 | ||
70 | BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI | |
71 | GetModuleFileNameW( | |
72 | boost::detail::winapi::HMODULE_ hModule, | |
73 | boost::detail::winapi::LPWSTR_ lpFilename, | |
74 | boost::detail::winapi::DWORD_ nSize | |
75 | ); | |
76 | ||
77 | BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI | |
78 | FreeLibrary(boost::detail::winapi::HMODULE_ hModule); | |
79 | ||
80 | #if !defined( UNDER_CE ) | |
81 | BOOST_SYMBOL_IMPORT boost::detail::winapi::FARPROC_ WINAPI | |
82 | GetProcAddress(boost::detail::winapi::HMODULE_ hModule, boost::detail::winapi::LPCSTR_ lpProcName); | |
83 | #else | |
84 | // On Windows CE there are two functions: GetProcAddressA (since Windows CE 3.0) and GetProcAddressW. | |
85 | // GetProcAddress is a macro that is _always_ defined to GetProcAddressW. | |
86 | BOOST_SYMBOL_IMPORT boost::detail::winapi::FARPROC_ WINAPI | |
87 | GetProcAddressA(boost::detail::winapi::HMODULE_ hModule, boost::detail::winapi::LPCSTR_ lpProcName); | |
88 | BOOST_SYMBOL_IMPORT boost::detail::winapi::FARPROC_ WINAPI | |
89 | GetProcAddressW(boost::detail::winapi::HMODULE_ hModule, boost::detail::winapi::LPCWSTR_ lpProcName); | |
90 | #endif | |
91 | ||
92 | struct _MEMORY_BASIC_INFORMATION; | |
93 | ||
94 | #if !defined( BOOST_WINAPI_IS_MINGW ) | |
95 | BOOST_SYMBOL_IMPORT boost::detail::winapi::SIZE_T_ WINAPI | |
96 | VirtualQuery( | |
97 | boost::detail::winapi::LPCVOID_ lpAddress, | |
98 | ::_MEMORY_BASIC_INFORMATION* lpBuffer, | |
99 | boost::detail::winapi::ULONG_PTR_ dwLength | |
100 | ); | |
101 | #else // !defined( BOOST_WINAPI_IS_MINGW ) | |
102 | BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI | |
103 | VirtualQuery( | |
104 | boost::detail::winapi::LPCVOID_ lpAddress, | |
105 | ::_MEMORY_BASIC_INFORMATION* lpBuffer, | |
106 | boost::detail::winapi::DWORD_ dwLength | |
107 | ); | |
108 | #endif // !defined( BOOST_WINAPI_IS_MINGW ) | |
109 | } // extern "C" | |
110 | #endif // #if !defined( BOOST_USE_WINDOWS_H ) | |
111 | ||
112 | namespace boost { | |
113 | namespace detail { | |
114 | namespace winapi { | |
115 | ||
116 | typedef struct BOOST_DETAIL_WINAPI_MAY_ALIAS MEMORY_BASIC_INFORMATION_ { | |
117 | PVOID_ BaseAddress; | |
118 | PVOID_ AllocationBase; | |
119 | DWORD_ AllocationProtect; | |
120 | SIZE_T_ RegionSize; | |
121 | DWORD_ State; | |
122 | DWORD_ Protect; | |
123 | DWORD_ Type; | |
124 | } *PMEMORY_BASIC_INFORMATION_; | |
125 | ||
126 | #if defined( BOOST_USE_WINDOWS_H ) | |
127 | typedef ::FARPROC FARPROC_; | |
128 | typedef ::NEARPROC NEARPROC_; | |
129 | typedef ::PROC PROC_; | |
130 | ||
131 | const DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = DONT_RESOLVE_DLL_REFERENCES; | |
132 | const DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = LOAD_WITH_ALTERED_SEARCH_PATH; | |
133 | #else // defined( BOOST_USE_WINDOWS_H ) | |
134 | const DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = 0x00000001; | |
135 | const DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = 0x00000008; | |
136 | #endif // defined( BOOST_USE_WINDOWS_H ) | |
137 | ||
138 | // This one is not defined by MinGW | |
139 | const DWORD_ LOAD_IGNORE_CODE_AUTHZ_LEVEL_ = 0x00000010; | |
140 | ||
141 | #if !defined( BOOST_NO_ANSI_APIS ) | |
142 | using ::LoadLibraryA; | |
143 | using ::LoadLibraryExA; | |
144 | using ::GetModuleHandleA; | |
145 | using ::GetModuleFileNameA; | |
146 | #endif // !defined( BOOST_NO_ANSI_APIS ) | |
147 | using ::LoadLibraryW; | |
148 | using ::LoadLibraryExW; | |
149 | using ::GetModuleHandleW; | |
150 | using ::GetModuleFileNameW; | |
151 | using ::FreeLibrary; | |
152 | ||
153 | #if !defined( UNDER_CE ) | |
154 | // For backward compatibility, don't use directly. Use get_proc_address instead. | |
155 | using ::GetProcAddress; | |
156 | #else | |
157 | using ::GetProcAddressA; | |
158 | using ::GetProcAddressW; | |
159 | #endif | |
160 | ||
161 | BOOST_FORCEINLINE FARPROC_ get_proc_address(HMODULE_ hModule, LPCSTR_ lpProcName) | |
162 | { | |
163 | #if !defined( UNDER_CE ) | |
164 | return ::GetProcAddress(hModule, lpProcName); | |
165 | #else | |
166 | return ::GetProcAddressA(hModule, lpProcName); | |
167 | #endif | |
168 | } | |
169 | ||
170 | BOOST_FORCEINLINE SIZE_T_ VirtualQuery(LPCVOID_ lpAddress, MEMORY_BASIC_INFORMATION_* lpBuffer, ULONG_PTR_ dwLength) | |
171 | { | |
172 | return ::VirtualQuery(lpAddress, reinterpret_cast< ::_MEMORY_BASIC_INFORMATION* >(lpBuffer), dwLength); | |
173 | } | |
174 | ||
175 | #if !defined( BOOST_NO_ANSI_APIS ) | |
176 | BOOST_FORCEINLINE HMODULE_ load_library(LPCSTR_ lpFileName) | |
177 | { | |
178 | return ::LoadLibraryA(lpFileName); | |
179 | } | |
180 | ||
181 | BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags) | |
182 | { | |
183 | return ::LoadLibraryExA(lpFileName, hFile, dwFlags); | |
184 | } | |
185 | ||
186 | BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCSTR_ lpFileName) | |
187 | { | |
188 | return ::GetModuleHandleA(lpFileName); | |
189 | } | |
190 | ||
191 | BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPSTR_ lpFilename, DWORD_ nSize) | |
192 | { | |
193 | return ::GetModuleFileNameA(hModule, lpFilename, nSize); | |
194 | } | |
195 | #endif // #if !defined( BOOST_NO_ANSI_APIS ) | |
196 | ||
197 | BOOST_FORCEINLINE HMODULE_ load_library(LPCWSTR_ lpFileName) | |
198 | { | |
199 | return ::LoadLibraryW(lpFileName); | |
200 | } | |
201 | ||
202 | BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCWSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags) | |
203 | { | |
204 | return ::LoadLibraryExW(lpFileName, hFile, dwFlags); | |
205 | } | |
206 | ||
207 | BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCWSTR_ lpFileName) | |
208 | { | |
209 | return ::GetModuleHandleW(lpFileName); | |
210 | } | |
211 | ||
212 | BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPWSTR_ lpFilename, DWORD_ nSize) | |
213 | { | |
214 | return ::GetModuleFileNameW(hModule, lpFilename, nSize); | |
215 | } | |
216 | ||
217 | } // namespace winapi | |
218 | } // namespace detail | |
219 | } // namespace boost | |
220 | ||
221 | #endif // BOOST_DETAIL_WINAPI_DLL_HPP |