1
0
Fork 0

Another attempt to fix msvcp140 loading

#3624
This commit is contained in:
Duncan Ogilvie 2025-07-06 12:20:34 +02:00
parent ad5e2d2ee2
commit c589e7db3b
1 changed files with 19 additions and 4 deletions

View File

@ -19,6 +19,7 @@ void randombytes(uint8_t* buf, uint64_t len)
__debugbreak(); __debugbreak();
} }
// Always ends with a backslash
static wchar_t szApplicationDir[MAX_PATH]; static wchar_t szApplicationDir[MAX_PATH];
static bool bPerformSignatureChecks = false; static bool bPerformSignatureChecks = false;
static bool bNewerThanXP = false; static bool bNewerThanXP = false;
@ -215,8 +216,16 @@ static bool FileExists(const wchar_t* szFullPath)
HMODULE WINAPI LoadLibraryCheckedW(const wchar_t* szDll, bool allowFailure) HMODULE WINAPI LoadLibraryCheckedW(const wchar_t* szDll, bool allowFailure)
{ {
std::wstring fullDllPath = szApplicationDir; std::wstring fullDllPath;
fullDllPath += szDll; if(wcschr(szDll, L'\\') == nullptr)
{
fullDllPath = szApplicationDir;
fullDllPath += szDll;
}
else
{
fullDllPath = szDll;
}
#ifdef DEBUG_SIGNATURE_CHECKS #ifdef DEBUG_SIGNATURE_CHECKS
debugMessage(L"LoadLibraryCheckedW"); debugMessage(L"LoadLibraryCheckedW");
@ -493,17 +502,23 @@ bool InitializeSignatureCheck()
std::wstring fullDllPath = szApplicationDir; std::wstring fullDllPath = szApplicationDir;
fullDllPath += L'\\'; fullDllPath += L'\\';
fullDllPath += szDll; fullDllPath += szDll;
HMODULE hModule = nullptr;
if(FileExists(fullDllPath.c_str())) if(FileExists(fullDllPath.c_str()))
{ {
if(bPerformSignatureChecks) if(bPerformSignatureChecks)
{ {
LoadLibraryCheckedW(fullDllPath.c_str(), true); hModule = LoadLibraryCheckedW(fullDllPath.c_str(), true);
} }
else else
{ {
LoadLibraryW(fullDllPath.c_str()); hModule = LoadLibraryW(fullDllPath.c_str());
} }
} }
if(!hModule)
{
MessageBoxW(nullptr, fullDllPath.c_str(), L"Failed to load runtime DLL!", MB_ICONERROR | MB_SYSTEMMODAL);
ExitProcess(ERROR_MOD_NOT_FOUND);
}
}; };
loadRuntimeDll(L"vcruntime140.dll"); loadRuntimeDll(L"vcruntime140.dll");
loadRuntimeDll(L"vcruntime140_1.dll"); loadRuntimeDll(L"vcruntime140_1.dll");