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