From e16b367e6e19aaa2968553c7b4e7fd6e92d9616d Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 6 Apr 2016 19:38:31 +0100 Subject: [PATCH] windows: Workaround weird LoadLibraryEx failures For some reason some Windows 7 systems (most are unaffected) cannot cope with LoadLibraryEx and return error code 87 - "The parameter is incorrect". Switch to using LoadLibrary instead for any case where Windows 7 is expected to successfully load the requested dll. Potentially Windows Vista is also affected. --- plugins/GSdx/GSDeviceDX.cpp | 4 +++- plugins/LilyPad/XInputEnum.cpp | 8 ++++---- plugins/xpad/xpad.cpp | 9 +++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/GSdx/GSDeviceDX.cpp b/plugins/GSdx/GSDeviceDX.cpp index 5aa5761ce1..2844f37e40 100644 --- a/plugins/GSdx/GSDeviceDX.cpp +++ b/plugins/GSdx/GSDeviceDX.cpp @@ -57,7 +57,9 @@ bool GSDeviceDX::LoadD3DCompiler() else { if (!IsWindows8Point1OrGreater()) - s_d3d_compiler_dll = LoadLibraryEx("D3DCompiler_43.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + // Use LoadLibrary instead of LoadLibraryEx, some Windows 7 systems + // have issues with it. + s_d3d_compiler_dll = LoadLibrary("D3DCompiler_43.dll"); if (s_d3d_compiler_dll == nullptr) return false; diff --git a/plugins/LilyPad/XInputEnum.cpp b/plugins/LilyPad/XInputEnum.cpp index 3f72441f0a..9a5a5d57df 100644 --- a/plugins/LilyPad/XInputEnum.cpp +++ b/plugins/LilyPad/XInputEnum.cpp @@ -255,13 +255,13 @@ void EnumXInputDevices() { // don't repeatedly try to load it. if (pXInputEnable) return; - const DWORD flags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32; - // Prefer XInput 1.3 since SCP only has an XInput 1.3 wrapper right now. + // Also use LoadLibrary and not LoadLibraryEx for XInput 1.3, since some + // Windows 7 systems have issues with it. // FIXME: Missing FreeLibrary call. - HMODULE hMod = LoadLibraryEx(L"xinput1_3.dll", nullptr, flags); + HMODULE hMod = LoadLibrary(L"xinput1_3.dll"); if (hMod == nullptr && IsWindows8OrGreater()) { - hMod = LoadLibraryEx(L"XInput1_4.dll", nullptr, flags); + hMod = LoadLibraryEx(L"XInput1_4.dll", nullptr, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); } if (hMod) { diff --git a/plugins/xpad/xpad.cpp b/plugins/xpad/xpad.cpp index 4da8b77816..f60cc2edeb 100644 --- a/plugins/xpad/xpad.cpp +++ b/plugins/xpad/xpad.cpp @@ -643,12 +643,13 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) EXPORT_C_(UINT32) PADinit(UINT32 flags) { - DWORD loadFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32; - - s_xInputDll = LoadLibraryEx(L"xinput1_3.dll", nullptr, loadFlags); + // Use LoadLibrary and not LoadLibraryEx for XInput 1.3, since some + // Windows 7 systems have issues with it. + // TODO: Only load XInput 1.4 for Windows 8+? Or implement the SCP extension? + s_xInputDll = LoadLibrary(L"xinput1_3.dll"); if (s_xInputDll == nullptr && IsWindows8OrGreater()) { - s_xInputDll = LoadLibraryEx(L"XInput1_4.dll", nullptr, loadFlags); + s_xInputDll = LoadLibraryEx(L"XInput1_4.dll", nullptr, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); } if (s_xInputDll == nullptr) {