Copy exception message to clipboard for easy coby basting

This commit is contained in:
FutureRave 2022-02-10 12:14:43 +00:00
parent 3fdadb45a5
commit e3278840e9
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
2 changed files with 31 additions and 3 deletions

View File

@ -43,10 +43,10 @@ namespace Components
Utils::Time::Interval interval;
while (IsWindow(Window::GetWindow()) != FALSE && !interval.elapsed(2s))
{
if (PeekMessage(&msg, nullptr, NULL, NULL, PM_REMOVE))
if (PeekMessageA(&msg, nullptr, NULL, NULL, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
DispatchMessageA(&msg);
}
std::this_thread::sleep_for(10ms);
@ -57,6 +57,32 @@ namespace Components
Game::Sys_SuspendOtherThreads();
}
void Exception::CopyMessageToClipboard(const std::string& error)
{
const auto hWndNewOwner = GetDesktopWindow();
const auto result = OpenClipboard(hWndNewOwner);
if (result == FALSE)
return;
EmptyClipboard();
auto* hMem = GlobalAlloc(GMEM_MOVEABLE, error.size() + 1);
if (hMem != nullptr)
{
auto lock = reinterpret_cast<char*>(GlobalLock(hMem));
if (lock != nullptr)
{
std::strcpy(lock, error.data()); // Should be okay since we allocated size + 1
GlobalUnlock(hMem);
SetClipboardData(1, hMem);
}
}
CloseClipboard();
}
LONG WINAPI Exception::ExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
{
// Pass on harmless errors
@ -90,6 +116,7 @@ namespace Components
}
}*/
Exception::CopyMessageToClipboard(errorStr);
MessageBoxA(nullptr, errorStr.data(), "ERROR", MB_ICONERROR);
if (doFullDump)

View File

@ -18,7 +18,8 @@ namespace Components
static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter);
static __declspec(noreturn) void ErrorLongJmp(jmp_buf _Buf, int _Value);
static __declspec(noreturn) void LongJmp(jmp_buf _Buf, int _Value);
static void DebugMinidumpCommand(Command::Params*);
static void CopyMessageToClipboard(const std::string& error);
static int MiniDumpType;
static Utils::Hook SetFilterHook;