Created
February 12, 2016 22:57
-
-
Save mooware/e3d8bba1b9f059a4e0c7 to your computer and use it in GitHub Desktop.
An example program to show that FormatMessage() cannot properly return the text for an exception code.
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 <windows.h> | |
#include <stdio.h> | |
int main() | |
{ | |
HMODULE hMod = LoadLibrary("ntdll.dll"); | |
char buf[1024]; | |
DWORD id = 0xc0000005; // code for access violation | |
DWORD res = FormatMessageA( | |
FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, | |
hMod, | |
id, | |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | |
buf, | |
_countof(buf), | |
NULL); | |
if (res == 0) | |
printf("error code %x not found\n", id); | |
else | |
printf("error code %x: %s\n", id, buf); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text is always just "The instruction at 0x", but it should be "The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.".