Fix error messages not working

The docs say combining FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE
should work. It doesn't 🤷‍♀️
This commit is contained in:
Adam Demasi 2024-10-06 01:58:15 +09:30
parent 1405239be1
commit 49b29e76c4
No known key found for this signature in database
GPG key ID: 5D3B26B3D58C7D91

View file

@ -27,7 +27,11 @@ EXTERN_C LPWSTR GetMessageForHresult(HRESULT hr) {
}
LPWSTR message;
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, g_messagesHModule, hr, LANG_NEUTRAL, (LPWSTR)&message, 0, NULL) == 0) {
if (FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, g_messagesHModule, hr, LANG_NEUTRAL, (LPWSTR)&message, 0, NULL) != 0) {
return message;
}
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr, LANG_NEUTRAL, (LPWSTR)&message, 0, NULL) == 0) {
message = (LPWSTR)LocalAlloc(LPTR, 1024 * sizeof(WCHAR));
wsprintf(message, L"Error 0x%08X", hr);
return message;