views:

103

answers:

1

How do you get the name and/or description of an SEH exception without having to hard-code the strings into your application?

I tried to use FormatMessage(), but it truncates the message sometimes, even if you specify to ignore inserts:

__asm { // raise access violation
    xor    eax, eax
    mov    eax, [eax]
}

Raises an exception with the code 0xC0000005 (EXCEPTION_ACCESS_VIOLATION).

char msg[256];
FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
    GetModuleHandleA("ntdll.dll"), 0xC0000005,
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    msg, sizeof(msg), NULL);

Fills msg with the truncated string: "The instruction at 0x".