paperjam
paperjam

Reputation: 8518

Windows/C++: FormatMessage() with GetExceptionCode() ignores FORMAT_MESSAGE_IGNORE_INSERTS

I would like to using code similar to the following to report divide-by-zero, access violations, etc. My problem is that, despite setting the flag FORMAT_MESSAGE_IGNORE_INSERTS, messages are truncated at the position of the insert.

__try
{
    int *p=0;
    int i = *p; // access violation
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
    char  message[1024];
    FormatMessageA(
        FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
        GetModuleHandleA("NTDLL.DLL"),
        GetExceptionCode(),
        MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
        message, 
        sizeof (message), 
        0);
    OutputDebugStringA(message);
}       

The above code yields "The instruction at 0x" in the debug output which is not terribly helpful.

Am I doing something wrong?

Upvotes: 3

Views: 903

Answers (0)

Related Questions