get_proc_address.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2020 Andrey Semashev
  3. *
  4. * Distributed under the Boost Software License, Version 1.0.
  5. * See http://www.boost.org/LICENSE_1_0.txt
  6. */
  7. #ifndef BOOST_WINAPI_GET_PROC_ADDRESS_HPP_INCLUDED_
  8. #define BOOST_WINAPI_GET_PROC_ADDRESS_HPP_INCLUDED_
  9. #include <boost/winapi/basic_types.hpp>
  10. #ifdef BOOST_HAS_PRAGMA_ONCE
  11. #pragma once
  12. #endif
  13. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  14. #include <boost/winapi/detail/header.hpp>
  15. #if !defined(BOOST_USE_WINDOWS_H)
  16. namespace boost { namespace winapi {
  17. #ifdef _WIN64
  18. typedef INT_PTR_ (BOOST_WINAPI_WINAPI_CC *FARPROC_)();
  19. typedef INT_PTR_ (BOOST_WINAPI_WINAPI_CC *NEARPROC_)();
  20. typedef INT_PTR_ (BOOST_WINAPI_WINAPI_CC *PROC_)();
  21. #else
  22. typedef int (BOOST_WINAPI_WINAPI_CC *FARPROC_)();
  23. typedef int (BOOST_WINAPI_WINAPI_CC *NEARPROC_)();
  24. typedef int (BOOST_WINAPI_WINAPI_CC *PROC_)();
  25. #endif // _WIN64
  26. }} // namespace boost::winapi
  27. extern "C" {
  28. #if !defined(UNDER_CE)
  29. BOOST_WINAPI_IMPORT boost::winapi::FARPROC_ BOOST_WINAPI_WINAPI_CC
  30. GetProcAddress(boost::winapi::HMODULE_ hModule, boost::winapi::LPCSTR_ lpProcName);
  31. #else
  32. // On Windows CE there are two functions: GetProcAddressA (since Windows CE 3.0) and GetProcAddressW.
  33. // GetProcAddress is a macro that is _always_ defined to GetProcAddressW.
  34. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::FARPROC_ BOOST_WINAPI_WINAPI_CC
  35. GetProcAddressA(boost::winapi::HMODULE_ hModule, boost::winapi::LPCSTR_ lpProcName);
  36. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::FARPROC_ BOOST_WINAPI_WINAPI_CC
  37. GetProcAddressW(boost::winapi::HMODULE_ hModule, boost::winapi::LPCWSTR_ lpProcName);
  38. #endif
  39. } // extern "C"
  40. #endif // !defined(BOOST_USE_WINDOWS_H)
  41. namespace boost {
  42. namespace winapi {
  43. #if defined(BOOST_USE_WINDOWS_H)
  44. typedef ::FARPROC FARPROC_;
  45. typedef ::NEARPROC NEARPROC_;
  46. typedef ::PROC PROC_;
  47. #endif // defined(BOOST_USE_WINDOWS_H)
  48. #if !defined(UNDER_CE)
  49. // For backward compatibility, don't use directly. Use get_proc_address instead.
  50. using ::GetProcAddress;
  51. #else
  52. using ::GetProcAddressA;
  53. using ::GetProcAddressW;
  54. #endif
  55. BOOST_FORCEINLINE FARPROC_ get_proc_address(HMODULE_ hModule, LPCSTR_ lpProcName)
  56. {
  57. #if !defined(UNDER_CE)
  58. return ::GetProcAddress(hModule, lpProcName);
  59. #else
  60. return ::GetProcAddressA(hModule, lpProcName);
  61. #endif
  62. }
  63. } // namespace winapi
  64. } // namespace boost
  65. #include <boost/winapi/detail/footer.hpp>
  66. #endif // BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  67. #endif // BOOST_WINAPI_GET_PROC_ADDRESS_HPP_INCLUDED_