Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string get_last_error_std_string(const DWORD error_code)
- {
- const DWORD fmt_message_flags =
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
- const DWORD lng_id = MAKELANGID(LANG_RUSSIAN, SUBLANG_RUSSIAN_RUSSIA);
- std::string result;
- if (error_code)
- {
- LPVOID msg_buf = nullptr;
- const DWORD buf_len = FormatMessage
- (
- fmt_message_flags,
- nullptr,
- error_code,
- lng_id,
- reinterpret_cast<LPWSTR>(&msg_buf),
- 0,
- nullptr
- );
- if (buf_len)
- {
- const int required_memory = WideCharToMultiByte
- (
- CP_UTF8,
- 0,
- static_cast<LPCWCH>(msg_buf),
- -1,
- nullptr,
- 0,
- nullptr,
- nullptr
- );
- result.resize(required_memory);
- (void)WideCharToMultiByte
- (
- CP_UTF8,
- 0,
- static_cast<LPCWCH>(msg_buf),
- static_cast<int>(buf_len),
- &result[0],
- required_memory,
- nullptr,
- nullptr
- );
- LocalFree(msg_buf);
- }
- }
- return result;
- }
- throw std::runtime_error(u8"{0}{1:#x} Ошибка: "{2}"{5}Файл: {3}{5}Строка: {4}"_format
- (
- u8"Не удалось зарегистрировать класс окна т.к. функция `RegisterClassExW` вернула ошибку ",
- error_code,
- get_last_error_std_string(error_code),
- __FILE__,
- __LINE__ - 2,
- "n"
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement