dll.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. #ifndef BOOST_WINAPI_DLL_HPP_INCLUDED_
  11. #define BOOST_WINAPI_DLL_HPP_INCLUDED_
  12. #include <boost/winapi/basic_types.hpp>
  13. #ifdef BOOST_HAS_PRAGMA_ONCE
  14. #pragma once
  15. #endif
  16. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  17. #if !defined( BOOST_USE_WINDOWS_H )
  18. extern "C" {
  19. namespace boost { namespace winapi {
  20. #ifdef _WIN64
  21. typedef INT_PTR_ (BOOST_WINAPI_WINAPI_CC *FARPROC_)();
  22. typedef INT_PTR_ (BOOST_WINAPI_WINAPI_CC *NEARPROC_)();
  23. typedef INT_PTR_ (BOOST_WINAPI_WINAPI_CC *PROC_)();
  24. #else
  25. typedef int (BOOST_WINAPI_WINAPI_CC *FARPROC_)();
  26. typedef int (BOOST_WINAPI_WINAPI_CC *NEARPROC_)();
  27. typedef int (BOOST_WINAPI_WINAPI_CC *PROC_)();
  28. #endif // _WIN64
  29. }} // namespace boost::winapi
  30. #if !defined( BOOST_NO_ANSI_APIS )
  31. BOOST_SYMBOL_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  32. LoadLibraryA(boost::winapi::LPCSTR_ lpFileName);
  33. BOOST_SYMBOL_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  34. LoadLibraryExA(
  35. boost::winapi::LPCSTR_ lpFileName,
  36. boost::winapi::HANDLE_ hFile,
  37. boost::winapi::DWORD_ dwFlags
  38. );
  39. BOOST_SYMBOL_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  40. GetModuleHandleA(boost::winapi::LPCSTR_ lpFileName);
  41. BOOST_SYMBOL_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  42. GetModuleFileNameA(
  43. boost::winapi::HMODULE_ hModule,
  44. boost::winapi::LPSTR_ lpFilename,
  45. boost::winapi::DWORD_ nSize
  46. );
  47. #endif
  48. BOOST_SYMBOL_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  49. LoadLibraryW(boost::winapi::LPCWSTR_ lpFileName);
  50. BOOST_SYMBOL_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  51. LoadLibraryExW(
  52. boost::winapi::LPCWSTR_ lpFileName,
  53. boost::winapi::HANDLE_ hFile,
  54. boost::winapi::DWORD_ dwFlags
  55. );
  56. BOOST_SYMBOL_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  57. GetModuleHandleW(boost::winapi::LPCWSTR_ lpFileName);
  58. BOOST_SYMBOL_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  59. GetModuleFileNameW(
  60. boost::winapi::HMODULE_ hModule,
  61. boost::winapi::LPWSTR_ lpFilename,
  62. boost::winapi::DWORD_ nSize
  63. );
  64. #if !defined( UNDER_CE )
  65. BOOST_SYMBOL_IMPORT boost::winapi::FARPROC_ BOOST_WINAPI_WINAPI_CC
  66. GetProcAddress(boost::winapi::HMODULE_ hModule, boost::winapi::LPCSTR_ lpProcName);
  67. #else
  68. // On Windows CE there are two functions: GetProcAddressA (since Windows CE 3.0) and GetProcAddressW.
  69. // GetProcAddress is a macro that is _always_ defined to GetProcAddressW.
  70. BOOST_SYMBOL_IMPORT boost::winapi::FARPROC_ BOOST_WINAPI_WINAPI_CC
  71. GetProcAddressA(boost::winapi::HMODULE_ hModule, boost::winapi::LPCSTR_ lpProcName);
  72. BOOST_SYMBOL_IMPORT boost::winapi::FARPROC_ BOOST_WINAPI_WINAPI_CC
  73. GetProcAddressW(boost::winapi::HMODULE_ hModule, boost::winapi::LPCWSTR_ lpProcName);
  74. #endif
  75. struct _MEMORY_BASIC_INFORMATION;
  76. #if !defined( BOOST_WINAPI_IS_MINGW )
  77. BOOST_SYMBOL_IMPORT boost::winapi::SIZE_T_ BOOST_WINAPI_WINAPI_CC
  78. VirtualQuery(
  79. boost::winapi::LPCVOID_ lpAddress,
  80. ::_MEMORY_BASIC_INFORMATION* lpBuffer,
  81. boost::winapi::SIZE_T_ dwLength
  82. );
  83. #else // !defined( BOOST_WINAPI_IS_MINGW )
  84. BOOST_SYMBOL_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  85. VirtualQuery(
  86. boost::winapi::LPCVOID_ lpAddress,
  87. ::_MEMORY_BASIC_INFORMATION* lpBuffer,
  88. boost::winapi::DWORD_ dwLength
  89. );
  90. #endif // !defined( BOOST_WINAPI_IS_MINGW )
  91. } // extern "C"
  92. #endif // #if !defined( BOOST_USE_WINDOWS_H )
  93. namespace boost {
  94. namespace winapi {
  95. typedef struct BOOST_MAY_ALIAS MEMORY_BASIC_INFORMATION_ {
  96. PVOID_ BaseAddress;
  97. PVOID_ AllocationBase;
  98. DWORD_ AllocationProtect;
  99. SIZE_T_ RegionSize;
  100. DWORD_ State;
  101. DWORD_ Protect;
  102. DWORD_ Type;
  103. } *PMEMORY_BASIC_INFORMATION_;
  104. #if defined( BOOST_USE_WINDOWS_H )
  105. typedef ::FARPROC FARPROC_;
  106. typedef ::NEARPROC NEARPROC_;
  107. typedef ::PROC PROC_;
  108. BOOST_CONSTEXPR_OR_CONST DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = DONT_RESOLVE_DLL_REFERENCES;
  109. BOOST_CONSTEXPR_OR_CONST DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = LOAD_WITH_ALTERED_SEARCH_PATH;
  110. #else // defined( BOOST_USE_WINDOWS_H )
  111. BOOST_CONSTEXPR_OR_CONST DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = 0x00000001;
  112. BOOST_CONSTEXPR_OR_CONST DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = 0x00000008;
  113. #endif // defined( BOOST_USE_WINDOWS_H )
  114. // This one is not defined by MinGW
  115. BOOST_CONSTEXPR_OR_CONST DWORD_ LOAD_IGNORE_CODE_AUTHZ_LEVEL_ = 0x00000010;
  116. #if !defined( BOOST_NO_ANSI_APIS )
  117. using ::LoadLibraryA;
  118. using ::LoadLibraryExA;
  119. using ::GetModuleHandleA;
  120. using ::GetModuleFileNameA;
  121. #endif // !defined( BOOST_NO_ANSI_APIS )
  122. using ::LoadLibraryW;
  123. using ::LoadLibraryExW;
  124. using ::GetModuleHandleW;
  125. using ::GetModuleFileNameW;
  126. #if !defined( UNDER_CE )
  127. // For backward compatibility, don't use directly. Use get_proc_address instead.
  128. using ::GetProcAddress;
  129. #else
  130. using ::GetProcAddressA;
  131. using ::GetProcAddressW;
  132. #endif
  133. BOOST_FORCEINLINE FARPROC_ get_proc_address(HMODULE_ hModule, LPCSTR_ lpProcName)
  134. {
  135. #if !defined( UNDER_CE )
  136. return ::GetProcAddress(hModule, lpProcName);
  137. #else
  138. return ::GetProcAddressA(hModule, lpProcName);
  139. #endif
  140. }
  141. BOOST_FORCEINLINE SIZE_T_ VirtualQuery(LPCVOID_ lpAddress, MEMORY_BASIC_INFORMATION_* lpBuffer, SIZE_T_ dwLength)
  142. {
  143. return ::VirtualQuery(lpAddress, reinterpret_cast< ::_MEMORY_BASIC_INFORMATION* >(lpBuffer), dwLength);
  144. }
  145. #if !defined( BOOST_NO_ANSI_APIS )
  146. BOOST_FORCEINLINE HMODULE_ load_library(LPCSTR_ lpFileName)
  147. {
  148. return ::LoadLibraryA(lpFileName);
  149. }
  150. BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags)
  151. {
  152. return ::LoadLibraryExA(lpFileName, hFile, dwFlags);
  153. }
  154. BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCSTR_ lpFileName)
  155. {
  156. return ::GetModuleHandleA(lpFileName);
  157. }
  158. BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPSTR_ lpFilename, DWORD_ nSize)
  159. {
  160. return ::GetModuleFileNameA(hModule, lpFilename, nSize);
  161. }
  162. #endif // #if !defined( BOOST_NO_ANSI_APIS )
  163. BOOST_FORCEINLINE HMODULE_ load_library(LPCWSTR_ lpFileName)
  164. {
  165. return ::LoadLibraryW(lpFileName);
  166. }
  167. BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCWSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags)
  168. {
  169. return ::LoadLibraryExW(lpFileName, hFile, dwFlags);
  170. }
  171. BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCWSTR_ lpFileName)
  172. {
  173. return ::GetModuleHandleW(lpFileName);
  174. }
  175. BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPWSTR_ lpFilename, DWORD_ nSize)
  176. {
  177. return ::GetModuleFileNameW(hModule, lpFilename, nSize);
  178. }
  179. } // namespace winapi
  180. } // namespace boost
  181. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  182. //
  183. // FreeLibrary is in a different partition set (slightly)
  184. //
  185. #if BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  186. #if !defined(BOOST_USE_WINDOWS_H)
  187. extern "C" {
  188. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  189. FreeLibrary(boost::winapi::HMODULE_ hModule);
  190. }
  191. #endif
  192. namespace boost {
  193. namespace winapi {
  194. using ::FreeLibrary;
  195. }
  196. }
  197. #endif // BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  198. #endif // BOOST_WINAPI_DLL_HPP_INCLUDED_