mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 12:40:04 +00:00
Dynamically obtain the function pointer to IsHungAppWindow
This commit is contained in:
parent
792582af53
commit
100e400fed
@ -17,7 +17,29 @@
|
||||
namespace Crash
|
||||
{
|
||||
std::unordered_map<HWINEVENTHOOK, CrashMonitor*> CrashMonitor::smEventHookOwners{};
|
||||
|
||||
using IsHungAppWindowFn = BOOL(WINAPI*)(HWND hwnd);
|
||||
|
||||
// Obtains the pointer to user32.IsHungAppWindow, this function may be removed in the future.
|
||||
// See: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-ishungappwindow
|
||||
static IsHungAppWindowFn getIsHungAppWindow() noexcept
|
||||
{
|
||||
static IsHungAppWindowFn isHungAppWindow = nullptr;
|
||||
static bool isHungAppWindowInitialized = false;
|
||||
|
||||
if (isHungAppWindowInitialized)
|
||||
return isHungAppWindow;
|
||||
|
||||
auto user32Handle = LoadLibraryA("user32.dll");
|
||||
if (user32Handle == nullptr)
|
||||
return nullptr;
|
||||
|
||||
isHungAppWindow = reinterpret_cast<IsHungAppWindowFn>(GetProcAddress(user32Handle, "IsHungAppWindow"));
|
||||
isHungAppWindowInitialized = true;
|
||||
|
||||
return isHungAppWindow;
|
||||
}
|
||||
|
||||
CrashMonitor::CrashMonitor(HANDLE shmHandle)
|
||||
: mShmHandle(shmHandle)
|
||||
{
|
||||
@ -123,8 +145,8 @@ namespace Crash
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if (IsHungAppWindow)
|
||||
return IsHungAppWindow(mAppWindowHandle);
|
||||
if (auto isHungAppWindow = getIsHungAppWindow(); isHungAppWindow != nullptr)
|
||||
return isHungAppWindow(mAppWindowHandle);
|
||||
else
|
||||
{
|
||||
BOOL debuggerPresent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user