Skip to content

Instantly share code, notes, and snippets.

@cristeigabriel
Created January 5, 2024 02:04
Show Gist options
  • Save cristeigabriel/7df945b01987cbee8b1e0fee658edc1c to your computer and use it in GitHub Desktop.
Save cristeigabriel/7df945b01987cbee8b1e0fee658edc1c to your computer and use it in GitHub Desktop.
error print code for mastodon
#include <windows.h>
#include <cstdio>
static LPWSTR getErrorStr(DWORD code) {
LPWSTR buffer = nullptr;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr, code, LANG_USER_DEFAULT, (LPWSTR)&buffer, 0,
nullptr);
return buffer;
}
int main() {
DWORD code = 0x80000003;
auto str = getErrorStr(code);
if (str) {
wprintf(L"%s\n", str);
LocalFree(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment