Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.