Skip to content

Instantly share code, notes, and snippets.

@mooware
Created February 12, 2016 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooware/e3d8bba1b9f059a4e0c7 to your computer and use it in GitHub Desktop.
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.
#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;
}
@mooware
Copy link
Author

mooware commented Feb 12, 2016

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.".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment