header_utils
Loading...
Searching...
No Matches
last_error.h
1
4
5#pragma once
6
7#include "common.h"
8
9#include <string>
10
12
13namespace ghassanpl
14{
15
16 struct last_windows_error_t
17 {
18 uint32_t value{};
19 std::string formatted;
20 };
21
22 namespace detail
23 {
24#if !defined(DOXYGEN)
25 extern "C" __declspec(dllimport) win::DWORD __stdcall FormatMessageA(win::DWORD dwFlags, const void* lpSource, win::DWORD dwMessageId, win::DWORD dwLanguageId, char* lpBuffer, win::DWORD nSize, va_list * Arguments);
26 extern "C" __declspec(dllimport) win::HANDLE __stdcall LocalFree(win::HANDLE hMem);
27#endif
28 }
29
30 last_windows_error_t get_last_windows_error()
31 {
32 const auto le = win::GetLastError();
33
34 last_windows_error_t result{};
35 result.value = le;
36 if (le != 0)
37 {
38 char* messageBuffer = nullptr;
39 size_t size = detail::FormatMessageA(0x00000100 | 0x00001000 | 0x00000200 | 0xFF, nullptr, le, 0, (char*)&messageBuffer, 0, nullptr);
40 result.formatted = std::string{ messageBuffer, size };
41 detail::LocalFree(messageBuffer);
42 }
43 return result;
44 }
45}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33
The below code is based on Sun's libm library code, which is licensed under the following license:
Primary namespace for everything in this library.
Definition align+rec2.h:10