engine: platform: win32: use widechar versions of LoadLibrary, which fixes loading engine if path contains non-latin characters

This commit is contained in:
Alibek Omarov
2025-03-16 03:16:02 +03:00
parent d68f29737a
commit 68a1fbdc2b
2 changed files with 12 additions and 4 deletions

View File

@@ -370,7 +370,7 @@ static void WIN_SetDPIAwareness( void )
BOOL ( __stdcall *pSetProcessDPIAware )( void );
BOOL bSuccess = FALSE;
if( ( hModule = LoadLibrary( "shcore.dll" ) ) )
if( ( hModule = LoadLibraryW( L"shcore.dll" ) ) )
{
if( ( pSetProcessDpiAwareness = (void*)GetProcAddress( hModule, "SetProcessDpiAwareness" ) ) )
{
@@ -395,7 +395,7 @@ static void WIN_SetDPIAwareness( void )
{
Con_Reportf( "%s: Trying SetProcessDPIAware...\n", __func__ );
if( ( hModule = LoadLibrary( "user32.dll" ) ) )
if( ( hModule = LoadLibraryW( L"user32.dll" ) ) )
{
if( ( pSetProcessDPIAware = ( void* )GetProcAddress( hModule, "SetProcessDPIAware" ) ) )
{

View File

@@ -18,6 +18,14 @@ GNU General Public License for more details.
#if XASH_LIB == LIB_WIN32
#include "lib_win.h"
static const wchar_t *FS_PathToWideChar( const char *path )
{
static wchar_t pathBuffer[MAX_PATH];
MultiByteToWideChar( CP_UTF8, 0, path, -1, pathBuffer, MAX_PATH );
return pathBuffer;
}
static DWORD GetOffsetByRVA( DWORD rva, PIMAGE_NT_HEADERS nt_header )
{
int i = 0;
@@ -375,7 +383,7 @@ static void ListMissingModules( dll_user_t *hInst )
HMODULE hMod;
const char *importName = (const char *)CALCULATE_ADDRESS( data, GetOffsetByRVA( importDesc->Name, peHeader ) );
hMod = LoadLibraryEx( importName, NULL, LOAD_LIBRARY_AS_DATAFILE );
hMod = LoadLibraryExW( FS_PathToWideChar( importName ), NULL, LOAD_LIBRARY_AS_DATAFILE );
if ( !hMod )
{
Q_snprintf( buf, sizeof( buf ), "%s not found!", importName );
@@ -470,7 +478,7 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
else
#endif
{
hInst->hInstance = LoadLibrary( hInst->fullPath );
hInst->hInstance = LoadLibraryW( FS_PathToWideChar( hInst->fullPath ));
}
if( !hInst->hInstance )