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
10 #ifndef BOOST_WINAPI_ERROR_HANDLING_HPP_INCLUDED_
11 #define BOOST_WINAPI_ERROR_HANDLING_HPP_INCLUDED_
12
13 #include <stdarg.h>
14 #include <boost/winapi/basic_types.hpp>
15 #include <boost/winapi/get_last_error.hpp>
16 #include <boost/winapi/detail/header.hpp>
17
18 #ifdef BOOST_HAS_PRAGMA_ONCE
19 #pragma once
20 #endif
21
22 #if !defined( BOOST_USE_WINDOWS_H )
23 extern "C" {
24 #if !defined( BOOST_NO_ANSI_APIS )
25 BOOST_WINAPI_IMPORT boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
26 FormatMessageA(
27 boost::winapi::DWORD_ dwFlags,
28 boost::winapi::LPCVOID_ lpSource,
29 boost::winapi::DWORD_ dwMessageId,
30 boost::winapi::DWORD_ dwLanguageId,
31 boost::winapi::LPSTR_ lpBuffer,
32 boost::winapi::DWORD_ nSize,
33 va_list *Arguments);
34 #endif
35
36 BOOST_WINAPI_IMPORT_EXCEPT_WM boost::winapi::DWORD_ BOOST_WINAPI_WINAPI_CC
37 FormatMessageW(
38 boost::winapi::DWORD_ dwFlags,
39 boost::winapi::LPCVOID_ lpSource,
40 boost::winapi::DWORD_ dwMessageId,
41 boost::winapi::DWORD_ dwLanguageId,
42 boost::winapi::LPWSTR_ lpBuffer,
43 boost::winapi::DWORD_ nSize,
44 va_list *Arguments);
45
46 #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
47 BOOST_WINAPI_IMPORT boost::winapi::UINT_ BOOST_WINAPI_WINAPI_CC
48 SetErrorMode(boost::winapi::UINT_ uMode);
49 #endif
50 } // extern "C"
51 #endif
52
53 namespace boost {
54 namespace winapi {
55
56 #if defined( BOOST_USE_WINDOWS_H )
57
58 #if BOOST_WINAPI_PARTITION_APP_SYSTEM
59 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ALLOCATE_BUFFER_= FORMAT_MESSAGE_ALLOCATE_BUFFER;
60 #endif
61
62 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_IGNORE_INSERTS_= FORMAT_MESSAGE_IGNORE_INSERTS;
63 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_STRING_= FORMAT_MESSAGE_FROM_STRING;
64 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_HMODULE_= FORMAT_MESSAGE_FROM_HMODULE;
65 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_SYSTEM_= FORMAT_MESSAGE_FROM_SYSTEM;
66 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ARGUMENT_ARRAY_= FORMAT_MESSAGE_ARGUMENT_ARRAY;
67 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_MAX_WIDTH_MASK_= FORMAT_MESSAGE_MAX_WIDTH_MASK;
68
69 BOOST_CONSTEXPR_OR_CONST WORD_ LANG_NEUTRAL_= LANG_NEUTRAL;
70 BOOST_CONSTEXPR_OR_CONST WORD_ LANG_INVARIANT_= LANG_INVARIANT;
71
72 BOOST_CONSTEXPR_OR_CONST WORD_ SUBLANG_DEFAULT_= SUBLANG_DEFAULT; // user default
73
MAKELANGID_(WORD_ p,WORD_ s)74 BOOST_FORCEINLINE BOOST_CONSTEXPR WORD_ MAKELANGID_(WORD_ p, WORD_ s) BOOST_NOEXCEPT
75 {
76 return MAKELANGID(p,s);
77 }
78
79 #if BOOST_WINAPI_PARTITION_DESKTOP
80 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_FAILCRITICALERRORS_ = SEM_FAILCRITICALERRORS;
81 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOGPFAULTERRORBOX_ = SEM_NOGPFAULTERRORBOX;
82 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOALIGNMENTFAULTEXCEPT_ = SEM_NOALIGNMENTFAULTEXCEPT;
83 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOOPENFILEERRORBOX_ = SEM_NOOPENFILEERRORBOX;
84 #endif
85
86 #else
87
88 #if BOOST_WINAPI_PARTITION_APP_SYSTEM
89 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ALLOCATE_BUFFER_= 0x00000100;
90 #endif
91 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_IGNORE_INSERTS_= 0x00000200;
92 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_STRING_= 0x00000400;
93 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_HMODULE_= 0x00000800;
94 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_FROM_SYSTEM_= 0x00001000;
95 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_ARGUMENT_ARRAY_= 0x00002000;
96 BOOST_CONSTEXPR_OR_CONST DWORD_ FORMAT_MESSAGE_MAX_WIDTH_MASK_= 0x000000FF;
97
98 BOOST_CONSTEXPR_OR_CONST WORD_ LANG_NEUTRAL_= 0x00;
99 BOOST_CONSTEXPR_OR_CONST WORD_ LANG_INVARIANT_= 0x7f;
100
101 BOOST_CONSTEXPR_OR_CONST WORD_ SUBLANG_DEFAULT_= 0x01; // user default
102
103 BOOST_FORCEINLINE BOOST_CONSTEXPR WORD_ MAKELANGID_(WORD_ p, WORD_ s) BOOST_NOEXCEPT
104 {
105 return (WORD_)((((WORD_)(s)) << 10) | (WORD_)(p));
106 }
107
108 #if BOOST_WINAPI_PARTITION_DESKTOP
109 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_FAILCRITICALERRORS_ = 0x0001;
110 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOGPFAULTERRORBOX_ = 0x0002;
111 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOALIGNMENTFAULTEXCEPT_ = 0x0004;
112 BOOST_CONSTEXPR_OR_CONST DWORD_ SEM_NOOPENFILEERRORBOX_ = 0x8000;
113 #endif
114
115 #endif
116
117 #if !defined( BOOST_NO_ANSI_APIS )
118 using ::FormatMessageA;
119 #endif
120 using ::FormatMessageW;
121 #if BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
122 using ::SetErrorMode;
123 #endif
124
125 #if !defined( BOOST_NO_ANSI_APIS )
format_message(DWORD_ dwFlags,LPCVOID_ lpSource,DWORD_ dwMessageId,DWORD_ dwLanguageId,LPSTR_ lpBuffer,DWORD_ nSize,va_list * Arguments)126 BOOST_FORCEINLINE DWORD_ format_message(
127 DWORD_ dwFlags,
128 LPCVOID_ lpSource,
129 DWORD_ dwMessageId,
130 DWORD_ dwLanguageId,
131 LPSTR_ lpBuffer,
132 DWORD_ nSize,
133 va_list *Arguments)
134 {
135 return ::FormatMessageA(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
136 }
137 #endif
138
format_message(DWORD_ dwFlags,LPCVOID_ lpSource,DWORD_ dwMessageId,DWORD_ dwLanguageId,LPWSTR_ lpBuffer,DWORD_ nSize,va_list * Arguments)139 BOOST_FORCEINLINE DWORD_ format_message(
140 DWORD_ dwFlags,
141 LPCVOID_ lpSource,
142 DWORD_ dwMessageId,
143 DWORD_ dwLanguageId,
144 LPWSTR_ lpBuffer,
145 DWORD_ nSize,
146 va_list *Arguments)
147 {
148 return ::FormatMessageW(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
149 }
150
151 }
152 }
153
154 #include <boost/winapi/detail/footer.hpp>
155
156 #endif // BOOST_WINAPI_ERROR_HANDLING_HPP_INCLUDED_
157