From 03c71aec900b27337e87e33690b2cf0619982785 Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:10:31 -0800 Subject: [PATCH] (Win32 refresh) AppInstance Use wchar as well as GetModuleFileNameW for native unicode support. Added some logging to catch any cases of unexpected behavior on the OS side. --- src/archutils/Win32/AppInstance.cpp | 20 +++++++++++++++++--- src/archutils/Win32/AppInstance.h | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/archutils/Win32/AppInstance.cpp b/src/archutils/Win32/AppInstance.cpp index 8d02ffd51e..98d0084907 100644 --- a/src/archutils/Win32/AppInstance.cpp +++ b/src/archutils/Win32/AppInstance.cpp @@ -1,12 +1,24 @@ #include "global.h" #include "AppInstance.h" +#include "RageLog.h" +#include "ErrorStrings.h" AppInstance::AppInstance() { // Little trick to get an HINSTANCE of ourself without having access to the hwnd. - TCHAR szFullAppPath[MAX_PATH]; - GetModuleFileName(nullptr, szFullAppPath, MAX_PATH); - h = LoadLibrary(szFullAppPath); + WCHAR szFullAppPath[MAX_PATH]; + if (GetModuleFileNameW(nullptr, szFullAppPath, MAX_PATH) == 0) + { + LOG->Warn("GetModuleFileName failed: %s", werr_ssprintf(GetLastError(), "GetModuleFileName").c_str()); + h = nullptr; + return; + } + + h = LoadLibraryW(szFullAppPath); + if (h == nullptr) + { + LOG->Warn("LoadLibrary failed: %s", werr_ssprintf(GetLastError(), "LoadLibrary").c_str()); + } /* h will be nullptr if this fails. Most operations that take an HINSTANCE * will still work without one (but may be missing graphics); that's OK. */ } @@ -14,7 +26,9 @@ AppInstance::AppInstance() AppInstance::~AppInstance() { if(h) + { FreeLibrary(h); + } } /* diff --git a/src/archutils/Win32/AppInstance.h b/src/archutils/Win32/AppInstance.h index 3a0358094e..98082351d5 100644 --- a/src/archutils/Win32/AppInstance.h +++ b/src/archutils/Win32/AppInstance.h @@ -1,7 +1,7 @@ #ifndef APP_INSTANCE_H #define APP_INSTANCE_H -#include "windows.h" +#include /** @brief get an HINSTANCE for starting dialog boxes. */ class AppInstance