Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created January 5, 2024 08:47
Show Gist options
  • Save noqisofon/2fa2b19ecf9b8ce47bd7e93906ba70e5 to your computer and use it in GitHub Desktop.
Save noqisofon/2fa2b19ecf9b8ce47bd7e93906ba70e5 to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ HRESULT の値から対応するメッセージを取得したいよなーー、俺もな~~~~~
#include <iostream>
#include <stdexcept>
#include <windows.h>
std::string hresult_to_string( HRESULT hr ) {
constexpr size_t MESSAGE_BUFFER_SIZE = 1024;
CHAR message[MESSAGE_BUFFER_SIZE] = {};
DWORD got = FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
hr,
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
message,
MESSAGE_BUFFER_SIZE,
nullptr );
return { message };
}
int main() {
std::cout << hresult_to_string( E_ACCESSDENIED ) << std::endl;
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment