hyperplatform_log_parser/utility.cpp
// Return an error message of corresponding Win32 error code.
Return an error message of corresponding Win32 error code.
Return an error message of corresponding Win32 error code .
_Use_decl_annotations_ std::basic_string<TCHAR> GetWin32ErrorMessage(
    std::uint32_t error_code) {
  TCHAR *message_raw = nullptr;
  if (!::FormatMessage(
          FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr,
          error_code, LANG_USER_DEFAULT, reinterpret_cast<LPTSTR>(&message_raw),
          0, nullptr)) {
    return TEXT("");
  }
  if (!message_raw) {
    return TEXT("");
  }
  auto message = std::experimental::make_unique_resource(std::move(message_raw),
                                                         &LocalFree);
  const auto length = ::_tcslen(message.get());
  if (!length) {
    return TEXT("");
  }
  if (message.get()[length - 2] == TEXT('\r')) {
    message.get()[length - 2] = TEXT('\0');
  }
  return message.get();
}
_Use_decl_annotations_ std :: basic_string < TCHAR > GetWin32ErrorMessage ( std :: uint32_t error_code ) { TCHAR * message_raw = nullptr ; if ( ! :: FormatMessage ( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM , nullptr , error_code , LANG_USER_DEFAULT , reinterpret_cast < LPTSTR > ( & message_raw ) , 0 , nullptr ) ) { return TEXT ( " " ) ; } if ( ! message_raw ) { return TEXT ( " " ) ; } auto message = std :: experimental :: make_unique_resource ( std :: move ( message_raw ) , & LocalFree ) ; const auto length = :: _tcslen ( message . get ( ) ) ; if ( ! length ) { return TEXT ( " " ) ; } if ( message . get ( ) [ length - 2 ] == TEXT ( ' \r ' ) ) { message . get ( ) [ length - 2 ] = TEXT ( ' \0 ' ) ; } return message . get ( ) ; }
Return an error message of corresponding Win32 error code.
Return an error message of corresponding Win32 error code .