dll.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright 2010 Vicente J. Botet Escriba
  3. * Copyright 2014 Renato Tegon Forti, Antony Polukhin
  4. * Copyright 2015, 2020 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. #include <boost/winapi/get_proc_address.hpp>
  14. #include <boost/winapi/detail/header.hpp>
  15. #ifdef BOOST_HAS_PRAGMA_ONCE
  16. #pragma once
  17. #endif
  18. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  19. #if !defined( BOOST_USE_WINDOWS_H )
  20. extern "C" {
  21. #if !defined( BOOST_NO_ANSI_APIS )
  22. BOOST_WINAPI_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  23. LoadLibraryA(boost::winapi::LPCSTR_ lpFileName);
  24. BOOST_WINAPI_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  25. LoadLibraryExA(
  26. boost::winapi::LPCSTR_ lpFileName,
  27. boost::winapi::HANDLE_ hFile,
  28. boost::winapi::DWORD_ dwFlags
  29. );
  30. BOOST_WINAPI_IMPORT boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  31. GetModuleHandleA(boost::winapi::LPCSTR_ lpFileName);
  32. BOOST_WINAPI_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  33. GetModuleFileNameA(
  34. boost::winapi::HMODULE_ hModule,
  35. boost::winapi::LPSTR_ lpFilename,
  36. boost::winapi::DWORD_ nSize
  37. );
  38. #endif
  39. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  40. LoadLibraryW(boost::winapi::LPCWSTR_ lpFileName);
  41. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  42. LoadLibraryExW(
  43. boost::winapi::LPCWSTR_ lpFileName,
  44. boost::winapi::HANDLE_ hFile,
  45. boost::winapi::DWORD_ dwFlags
  46. );
  47. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::HMODULE_ BOOST_WINAPI_WINAPI_CC
  48. GetModuleHandleW(boost::winapi::LPCWSTR_ lpFileName);
  49. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  50. GetModuleFileNameW(
  51. boost::winapi::HMODULE_ hModule,
  52. boost::winapi::LPWSTR_ lpFilename,
  53. boost::winapi::DWORD_ nSize
  54. );
  55. struct _MEMORY_BASIC_INFORMATION;
  56. #if !defined( BOOST_WINAPI_IS_MINGW )
  57. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::SIZE_T_ BOOST_WINAPI_WINAPI_CC
  58. VirtualQuery(
  59. boost::winapi::LPCVOID_ lpAddress,
  60. ::_MEMORY_BASIC_INFORMATION* lpBuffer,
  61. boost::winapi::SIZE_T_ dwLength
  62. );
  63. #else // !defined( BOOST_WINAPI_IS_MINGW )
  64. BOOST_WINAPI_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  65. VirtualQuery(
  66. boost::winapi::LPCVOID_ lpAddress,
  67. ::_MEMORY_BASIC_INFORMATION* lpBuffer,
  68. boost::winapi::DWORD_ dwLength
  69. );
  70. #endif // !defined( BOOST_WINAPI_IS_MINGW )
  71. } // extern "C"
  72. #endif // #if !defined( BOOST_USE_WINDOWS_H )
  73. namespace boost {
  74. namespace winapi {
  75. typedef struct BOOST_MAY_ALIAS MEMORY_BASIC_INFORMATION_ {
  76. PVOID_ BaseAddress;
  77. PVOID_ AllocationBase;
  78. DWORD_ AllocationProtect;
  79. SIZE_T_ RegionSize;
  80. DWORD_ State;
  81. DWORD_ Protect;
  82. DWORD_ Type;
  83. } *PMEMORY_BASIC_INFORMATION_;
  84. #if defined( BOOST_USE_WINDOWS_H )
  85. BOOST_CONSTEXPR_OR_CONST DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = DONT_RESOLVE_DLL_REFERENCES;
  86. BOOST_CONSTEXPR_OR_CONST DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = LOAD_WITH_ALTERED_SEARCH_PATH;
  87. #else // defined( BOOST_USE_WINDOWS_H )
  88. BOOST_CONSTEXPR_OR_CONST DWORD_ DONT_RESOLVE_DLL_REFERENCES_ = 0x00000001;
  89. BOOST_CONSTEXPR_OR_CONST DWORD_ LOAD_WITH_ALTERED_SEARCH_PATH_ = 0x00000008;
  90. #endif // defined( BOOST_USE_WINDOWS_H )
  91. // This one is not defined by MinGW
  92. BOOST_CONSTEXPR_OR_CONST DWORD_ LOAD_IGNORE_CODE_AUTHZ_LEVEL_ = 0x00000010;
  93. #if !defined( BOOST_NO_ANSI_APIS )
  94. using ::LoadLibraryA;
  95. using ::LoadLibraryExA;
  96. using ::GetModuleHandleA;
  97. using ::GetModuleFileNameA;
  98. #endif // !defined( BOOST_NO_ANSI_APIS )
  99. using ::LoadLibraryW;
  100. using ::LoadLibraryExW;
  101. using ::GetModuleHandleW;
  102. using ::GetModuleFileNameW;
  103. BOOST_FORCEINLINE SIZE_T_ VirtualQuery(LPCVOID_ lpAddress, MEMORY_BASIC_INFORMATION_* lpBuffer, SIZE_T_ dwLength)
  104. {
  105. return ::VirtualQuery(lpAddress, reinterpret_cast< ::_MEMORY_BASIC_INFORMATION* >(lpBuffer), dwLength);
  106. }
  107. #if !defined( BOOST_NO_ANSI_APIS )
  108. BOOST_FORCEINLINE HMODULE_ load_library(LPCSTR_ lpFileName)
  109. {
  110. return ::LoadLibraryA(lpFileName);
  111. }
  112. BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags)
  113. {
  114. return ::LoadLibraryExA(lpFileName, hFile, dwFlags);
  115. }
  116. BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCSTR_ lpFileName)
  117. {
  118. return ::GetModuleHandleA(lpFileName);
  119. }
  120. BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPSTR_ lpFilename, DWORD_ nSize)
  121. {
  122. return ::GetModuleFileNameA(hModule, lpFilename, nSize);
  123. }
  124. #endif // #if !defined( BOOST_NO_ANSI_APIS )
  125. BOOST_FORCEINLINE HMODULE_ load_library(LPCWSTR_ lpFileName)
  126. {
  127. return ::LoadLibraryW(lpFileName);
  128. }
  129. BOOST_FORCEINLINE HMODULE_ load_library_ex(LPCWSTR_ lpFileName, HANDLE_ hFile, DWORD_ dwFlags)
  130. {
  131. return ::LoadLibraryExW(lpFileName, hFile, dwFlags);
  132. }
  133. BOOST_FORCEINLINE HMODULE_ get_module_handle(LPCWSTR_ lpFileName)
  134. {
  135. return ::GetModuleHandleW(lpFileName);
  136. }
  137. BOOST_FORCEINLINE DWORD_ get_module_file_name(HMODULE_ hModule, LPWSTR_ lpFilename, DWORD_ nSize)
  138. {
  139. return ::GetModuleFileNameW(hModule, lpFilename, nSize);
  140. }
  141. } // namespace winapi
  142. } // namespace boost
  143. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  144. //
  145. // FreeLibrary is in a different partition set (slightly)
  146. //
  147. #if BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  148. #if !defined(BOOST_USE_WINDOWS_H)
  149. extern "C" {
  150. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  151. FreeLibrary(boost::winapi::HMODULE_ hModule);
  152. }
  153. #endif
  154. namespace boost {
  155. namespace winapi {
  156. using ::FreeLibrary;
  157. }
  158. }
  159. #endif // BOOST_WINAPI_PARTITION_APP || BOOST_WINAPI_PARTITION_SYSTEM
  160. #include <boost/winapi/detail/footer.hpp>
  161. #endif // BOOST_WINAPI_DLL_HPP_INCLUDED_