(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.
This commit is contained in:
sukibaby
2025-01-20 09:47:13 -08:00
committed by teejusb
parent cbd186dab2
commit 03c71aec90
2 changed files with 18 additions and 4 deletions
+17 -3
View File
@@ -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);
}
}
/*
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef APP_INSTANCE_H
#define APP_INSTANCE_H
#include "windows.h"
#include <windows.h>
/** @brief get an HINSTANCE for starting dialog boxes. */
class AppInstance