42 #define _WIN32_WINNT 0x0A00
44 #ifndef WIN32_LEAN_AND_MEAN
45 #define WIN32_LEAN_AND_MEAN
70 for (
int attempts = 0; attempts < 2; ++attempts)
72 DWORD error_code = GetLastError();
73 LPSTR message_buffer =
nullptr;
75 const size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
78 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
79 (LPSTR)&message_buffer,
85 message = {message_buffer, size};
92 error_code = GetLastError();
100 LocalFree(message_buffer);
111 message =
"unknown error";
119 DWORD error_code = GetLastError();
121 LPSTR message_buffer =
nullptr;
122 size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
125 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
126 (LPSTR)&message_buffer,
132 std::string message(message_buffer, size);
133 LocalFree(message_buffer);