mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
Use winapi threads
This commit is contained in:
parent
698112a573
commit
fdcad96521
1 changed files with 17 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue