Use winapi threads

This commit is contained in:
kynex7510 2024-06-11 15:04:15 +02:00
parent 698112a573
commit fdcad96521
No known key found for this signature in database
GPG key ID: 8BBB0FD2C57920AD

View file

@ -1,6 +1,5 @@
#include <Windows.h>
#include <string>
#include <thread>
struct XINPUT_STATE;
struct XINPUT_CAPABILITIES;
@ -54,8 +53,21 @@ static std::wstring getErrorString(DWORD error) {
return L"Could not load Geode! Error code: " + std::to_wstring(error);
}
static std::wstring get1114ErrorString(DWORD error) {
return L"Could not load Geode! Error code: " + std::to_wstring(error) + L"\n\nDo you want to update Microsoft Visual C++ Redistributable 2022 to try to fix this issue?";
static DWORD errorThread(LPVOID param) {
constexpr wchar_t REDIST_ERROR[] = L"Could not load Geode!\n"
"This is likely due to an outdated redist package.\n"
"Do you want to update Microsoft Visual C++ Redistributable 2022 to try to fix this issue?";
const DWORD error = reinterpret_cast<DWORD64>(param);
if (error == ERROR_DLL_INIT_FAILED) {
const auto choice = MessageBoxW(NULL, REDIST_ERROR, L"Load failed", MB_YESNO | MB_ICONWARNING);
if (choice == IDYES)
ShellExecuteW(NULL, L"open", L"https://aka.ms/vs/17/release/vc_redist.x64.exe", NULL, NULL, SW_SHOWNORMAL);
} else {
MessageBoxW(NULL, getErrorString(error).c_str(), L"Load failed" , MB_OK | MB_ICONWARNING);
}
return 0u;
}
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
@ -64,18 +76,8 @@ BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
// This is UB.
if (LoadLibraryW(L"Geode.dll") == NULL) {
auto error = GetLastError();
if(error == 1114) {
if(MessageBoxW(NULL, get1114ErrorString(error).c_str(), L"Load failed" , MB_YESNO | MB_ICONWARNING) == IDYES) {
std::thread([]() {
ShellExecuteW(NULL, L"open", L"https://aka.ms/vs/17/release/vc_redist.x64.exe", NULL, NULL, SW_SHOWNORMAL);
}).detach();
}
} else {
MessageBoxW(NULL, getErrorString(error).c_str(), L"Load failed" , MB_OK | MB_ICONWARNING);
}
const auto param = reinterpret_cast<LPVOID>(static_cast<DWORD64>(GetLastError()));
CreateThread(NULL, 0, &errorThread, param, 0, NULL);
}
}