Ticket #13545: dll.hpp

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