error_handling.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2010 Vicente J. Botet Escriba
  3. * Copyright 2015 Andrey Semashev
  4. * Copyright 2016 Jorge Lodos
  5. *
  6. * Distributed under the Boost Software License, Version 1.0.
  7. * See http://www.boost.org/LICENSE_1_0.txt
  8. */
  9. #ifndef BOOST_WINAPI_ERROR_HANDLING_HPP_INCLUDED_
  10. #define BOOST_WINAPI_ERROR_HANDLING_HPP_INCLUDED_
  11. #include <stdarg.h>
  12. #include <boost/winapi/basic_types.hpp>
  13. #include <boost/winapi/get_last_error.hpp>
  14. #include <boost/winapi/detail/header.hpp>
  15. #ifdef BOOST_HAS_PRAGMA_ONCE
  16. #pragma once
  17. #endif
  18. #if !defined( BOOST_USE_WINDOWS_H )
  19. extern "C" {
  20. #if !defined( BOOST_NO_ANSI_APIS )
  21. BOOST_WINAPI_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  22. FormatMessageA(
  23. boost::winapi::DWORD_ dwFlags,
  24. boost::winapi::LPCVOID_ lpSource,
  25. boost::winapi::DWORD_ dwMessageId,
  26. boost::winapi::DWORD_ dwLanguageId,
  27. boost::winapi::LPSTR_ lpBuffer,
  28. boost::winapi::DWORD_ nSize,
  29. va_list *Arguments);
  30. #endif
  31. BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
  32. FormatMessageW(
  33. boost::winapi::DWORD_ dwFlags,
  34. boost::winapi::LPCVOID_ lpSource,
  35. boost::winapi::DWORD_ dwMessageId,
  36. boost::winapi::DWORD_ dwLanguageId,
  37. boost::winapi::LPWSTR_ lpBuffer,
  38. boost::winapi::DWORD_ nSize,
  39. va_list *Arguments);
  40. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  41. BOOST_WINAPI_IMPORT boost::winapi::UINT_ BOOST_WINAPI_WINAPI_CC
  42. SetErrorMode(boost::winapi::UINT_ uMode);
  43. #endif
  44. } // extern "C"
  45. #endif
  46. namespace boost {
  47. namespace winapi {
  48. #if defined( BOOST_USE_WINDOWS_H )
  49. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  50. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ALLOCATE_BUFFER_= FORMAT_MESSAGE_ALLOCATE_BUFFER;
  51. #endif
  52. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_IGNORE_INSERTS_= FORMAT_MESSAGE_IGNORE_INSERTS;
  53. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_STRING_= FORMAT_MESSAGE_FROM_STRING;
  54. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_HMODULE_= FORMAT_MESSAGE_FROM_HMODULE;
  55. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_SYSTEM_= FORMAT_MESSAGE_FROM_SYSTEM;
  56. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ARGUMENT_ARRAY_= FORMAT_MESSAGE_ARGUMENT_ARRAY;
  57. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_MAX_WIDTH_MASK_= FORMAT_MESSAGE_MAX_WIDTH_MASK;
  58. BOOST_CONSTEXPR_OR_CONST WORD_ LANG_NEUTRAL_= LANG_NEUTRAL;
  59. BOOST_CONSTEXPR_OR_CONST WORD_ LANG_INVARIANT_= LANG_INVARIANT;
  60. BOOST_CONSTEXPR_OR_CONST WORD_ SUBLANG_DEFAULT_= SUBLANG_DEFAULT; // user default
  61. BOOST_FORCEINLINE BOOST_CONSTEXPR WORD_ MAKELANGID_(WORD_ p, WORD_ s) BOOST_NOEXCEPT
  62. {
  63. return MAKELANGID(p,s);
  64. }
  65. #if BOOST_WINAPI_PARTITION_DESKTOP
  66. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_FAILCRITICALERRORS_ = SEM_FAILCRITICALERRORS;
  67. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOGPFAULTERRORBOX_ = SEM_NOGPFAULTERRORBOX;
  68. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOALIGNMENTFAULTEXCEPT_ = SEM_NOALIGNMENTFAULTEXCEPT;
  69. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOOPENFILEERRORBOX_ = SEM_NOOPENFILEERRORBOX;
  70. #endif
  71. #else
  72. #if BOOST_WINAPI_PARTITION_APP_SYSTEM
  73. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ALLOCATE_BUFFER_= 0x00000100;
  74. #endif
  75. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_IGNORE_INSERTS_= 0x00000200;
  76. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_STRING_= 0x00000400;
  77. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_HMODULE_= 0x00000800;
  78. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_SYSTEM_= 0x00001000;
  79. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ARGUMENT_ARRAY_= 0x00002000;
  80. BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_MAX_WIDTH_MASK_= 0x000000FF;
  81. BOOST_CONSTEXPR_OR_CONST WORD_ LANG_NEUTRAL_= 0x00;
  82. BOOST_CONSTEXPR_OR_CONST WORD_ LANG_INVARIANT_= 0x7f;
  83. BOOST_CONSTEXPR_OR_CONST WORD_ SUBLANG_DEFAULT_= 0x01; // user default
  84. BOOST_FORCEINLINE BOOST_CONSTEXPR WORD_ MAKELANGID_(WORD_ p, WORD_ s) BOOST_NOEXCEPT
  85. {
  86. return (WORD_)((((WORD_)(s)) << 10) | (WORD_)(p));
  87. }
  88. #if BOOST_WINAPI_PARTITION_DESKTOP
  89. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_FAILCRITICALERRORS_ = 0x0001;
  90. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOGPFAULTERRORBOX_ = 0x0002;
  91. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOALIGNMENTFAULTEXCEPT_ = 0x0004;
  92. BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOOPENFILEERRORBOX_ = 0x8000;
  93. #endif
  94. #endif
  95. #if !defined( BOOST_NO_ANSI_APIS )
  96. using ::FormatMessageA;
  97. #endif
  98. using ::FormatMessageW;
  99. #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
  100. using ::SetErrorMode;
  101. #endif
  102. #if !defined( BOOST_NO_ANSI_APIS )
  103. BOOST_FORCEINLINE DWORD_ format_message(
  104. DWORD_ dwFlags,
  105. LPCVOID_ lpSource,
  106. DWORD_ dwMessageId,
  107. DWORD_ dwLanguageId,
  108. LPSTR_ lpBuffer,
  109. DWORD_ nSize,
  110. va_list *Arguments)
  111. {
  112. return ::FormatMessageA(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
  113. }
  114. #endif
  115. BOOST_FORCEINLINE DWORD_ format_message(
  116. DWORD_ dwFlags,
  117. LPCVOID_ lpSource,
  118. DWORD_ dwMessageId,
  119. DWORD_ dwLanguageId,
  120. LPWSTR_ lpBuffer,
  121. DWORD_ nSize,
  122. va_list *Arguments)
  123. {
  124. return ::FormatMessageW(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
  125. }
  126. }
  127. }
  128. #include <boost/winapi/detail/footer.hpp>
  129. #endif // BOOST_WINAPI_ERROR_HANDLING_HPP_INCLUDED_