Created
January 5, 2024 08:47
-
-
Save noqisofon/2fa2b19ecf9b8ce47bd7e93906ba70e5 to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ HRESULT の値から対応するメッセージを取得したいよなーー、俺もな~~~~~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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