如何获取例外的名称/描述?

Sas*_*cha 8 windows winapi exception

如何在不必将字符串硬编码到应用程序中的情况获得SEH异常的名称和/或描述?

我尝试使用FormatMessage(),但它有时会截断消息,即使您指定忽略插入:

__asm { // raise access violation
    xor    eax, eax
    mov    eax, [eax]
}
Run Code Online (Sandbox Code Playgroud)

使用代码引发异常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);
Run Code Online (Sandbox Code Playgroud)

填充msg截断的字符串:" The instruction at 0x".