Textractor/GUI/main.cpp

45 lines
1.6 KiB
C++
Raw Normal View History

2018-07-21 15:40:16 -07:00
#include "mainwindow.h"
2018-09-01 15:31:18 -04:00
#include <sstream>
2018-07-21 15:40:16 -07:00
#include <QApplication>
2018-10-15 06:46:02 -04:00
char* GetCppExceptionInfo(EXCEPTION_POINTERS* exception)
{
// See https://blogs.msdn.microsoft.com/oldnewthing/20100730-00/?p=13273
// Not very reliable so use __try
__try { return ((char****)exception->ExceptionRecord->ExceptionInformation[2])[3][1][1] + 8; }
__except (EXCEPTION_EXECUTE_HANDLER) { return "Could not find"; }
}
2018-09-01 14:57:25 -04:00
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* exception)
{
2018-09-01 15:31:18 -04:00
MEMORY_BASIC_INFORMATION info = {};
VirtualQuery(exception->ExceptionRecord->ExceptionAddress, &info, sizeof(info));
2018-09-23 19:36:00 -04:00
wchar_t moduleName[MAX_PATH] = {};
GetModuleFileNameW((HMODULE)info.AllocationBase, moduleName, MAX_PATH);
std::wstringstream errorMsg;
2018-10-09 04:02:33 -04:00
errorMsg << std::uppercase << std::hex <<
2018-09-23 19:36:00 -04:00
L"Error code: " << exception->ExceptionRecord->ExceptionCode << std::endl <<
2018-10-09 04:02:33 -04:00
L"Error address: " << (uint64_t)exception->ExceptionRecord->ExceptionAddress << std::endl <<
L"Error in module: " << moduleName << std::endl;
2018-10-15 06:46:02 -04:00
if (exception->ExceptionRecord->ExceptionCode == 0xE06D7363)
errorMsg << "Additional info: " << GetCppExceptionInfo(exception) << std::endl;
2018-10-09 04:02:33 -04:00
for (int i = 0; i < exception->ExceptionRecord->NumberParameters; ++i)
errorMsg << L"Additional info: " << exception->ExceptionRecord->ExceptionInformation[i] << std::endl;
2018-09-29 16:05:08 -04:00
MessageBoxW(NULL, errorMsg.str().c_str(), L"Textractor ERROR", MB_ICONERROR);
2018-10-09 04:02:33 -04:00
2018-09-01 14:57:25 -04:00
return EXCEPTION_CONTINUE_SEARCH;
}
2018-07-21 15:40:16 -07:00
int main(int argc, char *argv[])
{
2018-09-01 15:49:16 -04:00
SetUnhandledExceptionFilter(ExceptionHandler);
2018-08-22 12:44:16 -04:00
QApplication a(argc, argv);
MainWindow w;
w.show();
2018-08-22 12:44:53 -04:00
return a.exec();
2018-07-21 15:40:16 -07:00
}