dll.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // dll.hpp --------------------------------------------------------------//
  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. // Distributed under the Boost Software License, Version 1.0.
  7. // See http://www.boost.org/LICENSE_1_0.txt
  8. #ifndef BOOST_DETAIL_WINAPI_DLL_HPP
  9. #define BOOST_DETAIL_WINAPI_DLL_HPP
  10. #include <boost/detail/winapi/basic_types.hpp>
  11. #ifdef BOOST_HAS_PRAGMA_ONCE
  12. #pragma once
  13. #endif
  14. #if !defined( BOOST_USE_WINDOWS_H )
  15. extern "C" {
  16. namespace boost { namespace detail { namespace winapi {
  17. #ifdef _WIN64
  18. typedef INT_PTR_ (WINAPI *FARPROC_)();
  19. typedef INT_PTR_ (WINAPI *NEARPROC_)();
  20. typedef INT_PTR_ (WINAPI *PROC_)();
  21. #else
  22. typedef int (WINAPI *FARPROC_)();
  23. typedef int (WINAPI *NEARPROC_)();
  24. typedef int (WINAPI *PROC_)();
  25. #endif // _WIN64
  26. }}} // namespace boost::detail::winapi
  27. #if !defined( BOOST_NO_ANSI_APIS )
  28. BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI
  29. LoadLibraryA(boost::detail::winapi::LPCSTR_ lpFileName);
  30. BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI
  31. LoadLibraryExA(
  32. boost::detail::winapi::LPCSTR_ lpFileName,
  33. boost::detail::winapi::HANDLE_ hFile,
  34. boost::detail::winapi::DWORD_ dwFlags
  35. );
  36. BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI
  37. GetModuleHandleA(boost::detail::winapi::LPCSTR_ lpFileName);
  38. BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI
  39. GetModuleFileNameA(
  40. boost::detail::winapi::HMODULE_ hModule,
  41. boost::detail::winapi::LPSTR_ lpFilename,
  42. boost::detail::winapi::DWORD_ nSize
  43. );
  44. #endif
  45. BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI
  46. LoadLibraryW(boost::detail::winapi::LPCWSTR_ lpFileName);
  47. BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI
  48. LoadLibraryExW(
  49. boost::detail::winapi::LPCWSTR_ lpFileName,
  50. boost::detail::winapi::HANDLE_ hFile,
  51. boost::detail::winapi::DWORD_ dwFlags
  52. );
  53. BOOST_SYMBOL_IMPORT boost::detail::winapi::HMODULE_ WINAPI
  54. GetModuleHandleW(boost::detail::winapi::LPCWSTR_ lpFileName);
  55. BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI
  56. GetModuleFileNameW(
  57. boost::detail::winapi::HMODULE_ hModule,
  58. boost::detail::winapi::LPWSTR_ lpFilename,
  59. boost::detail::winapi::DWORD_ nSize
  60. );
  61. BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI
  62. FreeLibrary(boost::detail::winapi::HMODULE_ hModule);
  63. #if !defined( UNDER_CE )
  64. BOOST_SYMBOL_IMPORT boost::detail::winapi::FARPROC_ WINAPI
  65. GetProcAddress(boost::detail::winapi::HMODULE_ hModule, boost::detail::winapi::LPCSTR_ lpProcName);
  66. #else
  67. // On Windows CE there are two functions: GetProcAddressA (since Windows CE 3.0) and GetProcAddressW.
  68. // GetProcAddress is a macro that is _always_ defined to GetProcAddressW.
  69. BOOST_SYMBOL_IMPORT boost::detail::winapi::FARPROC_ WINAPI
  70. GetProcAddressA(boost::detail::winapi::HMODULE_ hModule, boost::detail::winapi::LPCSTR_ lpProcName);
  71. BOOST_SYMBOL_IMPORT boost::detail::winapi::FARPROC_ WINAPI
  72. GetProcAddressW(boost::detail::winapi::HMODULE_ hModule, boost::detail::winapi::LPCWSTR_ lpProcName);
  73. #endif
  74. struct _MEMORY_BASIC_INFORMATION;
  75. #if !defined( BOOST_WINAPI_IS_MINGW )
  76. BOOST_SYMBOL_IMPORT boost::detail::winapi::SIZE_T_ WINAPI
  77. VirtualQuery(
  78. boost::detail::winapi::LPCVOID_ lpAddress,
  79. ::_MEMORY_BASIC_INFORMATION* lpBuffer,
  80. boost::detail::winapi::ULONG_PTR_ dwLength
  81. );
  82. #else // !defined( BOOST_WINAPI_IS_MINGW )
  83. BOOST_SYMBOL_IMPORT boost::detail::winapi::DWORD_ WINAPI
  84. VirtualQuery(
  85. boost::detail::winapi::LPCVOID_ lpAddress,
  86. ::_MEMORY_BASIC_INFORMATION* lpBuffer,
  87. boost::detail::winapi::DWORD_ dwLength
  88. );
  89. #endif // !defined( BOOST_WINAPI_IS_MINGW )
  90. } // extern "C"
  91. #endif // #if !defined( BOOST_USE_WINDOWS_H )
  92. namespace boost {
  93. namespace detail {
  94. namespace winapi {
  95. typedef struct BOOST_DETAIL_WINAPI_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. const DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = DONT_RESOLVE_DLL_REFERENCES;
  109. const DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = LOAD_WITH_ALTERED_SEARCH_PATH;
  110. #else // defined( BOOST_USE_WINDOWS_H )
  111. const DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = 0x00000001;
  112. const DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = 0x00000008;
  113. #endif // defined( BOOST_USE_WINDOWS_H )
  114. // This one is not defined by MinGW
  115. 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. using ::FreeLibrary;
  127. #if !defined( UNDER_CE )
  128. // For backward compatibility, don't use directly. Use get_proc_address instead.
  129. using ::GetProcAddress;
  130. #else
  131. using ::GetProcAddressA;
  132. using ::GetProcAddressW;
  133. #endif
  134. BOOST_FORCEINLINE FARPROC_ get_proc_address(HMODULE_ hModule, LPCSTR_ lpProcName)
  135. {
  136. #if !defined( UNDER_CE )
  137. return ::GetProcAddress(hModule, lpProcName);
  138. #else
  139. return ::GetProcAddressA(hModule, lpProcName);
  140. #endif
  141. }
  142. BOOST_FORCEINLINE SIZE_T_ VirtualQuery(LPCVOID_ lpAddress, MEMORY_BASIC_INFORMATION_* lpBuffer, ULONG_PTR_ dwLength)
  143. {
  144. return ::VirtualQuery(lpAddress, reinterpret_cast< ::_MEMORY_BASIC_INFORMATION* >(lpBuffer), dwLength);
  145. }
  146. #if !defined( BOOST_NO_ANSI_APIS )
  147. BOOST_FORCEINLINE HMODULE_ load_library(LPCSTR_ lpFileName)
  148. {
  149. return ::LoadLibraryA(lpFileName);
  150. }
  151. BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags)
  152. {
  153. return ::LoadLibraryExA(lpFileName, hFile, dwFlags);
  154. }
  155. BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCSTR_ lpFileName)
  156. {
  157. return ::GetModuleHandleA(lpFileName);
  158. }
  159. BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPSTR_ lpFilename, DWORD_ nSize)
  160. {
  161. return ::GetModuleFileNameA(hModule, lpFilename, nSize);
  162. }
  163. #endif // #if !defined( BOOST_NO_ANSI_APIS )
  164. BOOST_FORCEINLINE HMODULE_ load_library(LPCWSTR_ lpFileName)
  165. {
  166. return ::LoadLibraryW(lpFileName);
  167. }
  168. BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCWSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags)
  169. {
  170. return ::LoadLibraryExW(lpFileName, hFile, dwFlags);
  171. }
  172. BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCWSTR_ lpFileName)
  173. {
  174. return ::GetModuleHandleW(lpFileName);
  175. }
  176. BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPWSTR_ lpFilename, DWORD_ nSize)
  177. {
  178. return ::GetModuleFileNameW(hModule, lpFilename, nSize);
  179. }
  180. } // namespace winapi
  181. } // namespace detail
  182. } // namespace boost
  183. #endif // BOOST_DETAIL_WINAPI_DLL_HPP