Skip to content

Commit 17efec5

Browse files
committed
fix: v16 - load real system dinput8.dll instead of our wrapper for DI enumeration
1 parent 5daf31f commit 17efec5

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

Common Files/LogitechLED.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -888,34 +888,46 @@ bool LogitechLED::TrySteeringSDK()
888888
}
889889
}
890890

891-
// --- Fallback C: DInput device via bypass ---
891+
// --- Fallback C: DInput via REAL system dinput8.dll ---
892+
// Previous versions used GetModuleHandleA("dinput8.dll") which returns
893+
// OUR wrapper DLL (since we ARE dinput8.dll). That broke enumeration.
892894
if (g_PlayLedsDInput)
893895
{
894-
Log(" Fallback C: Real DInput device (bypass mode)...");
895-
g_bypassDIWrapper = true;
896+
Log(" Fallback C: Loading real system dinput8.dll...");
897+
898+
char sysDir[MAX_PATH];
899+
GetSystemDirectoryA(sysDir, MAX_PATH);
900+
strcat_s(sysDir, MAX_PATH, "\\dinput8.dll");
901+
HMODULE hSysDI8 = LoadLibraryA(sysDir);
902+
Log(" System DLL: %s -> 0x%p", sysDir, hSysDI8);
896903

897904
typedef HRESULT (WINAPI *DI8Create_t)(HINSTANCE, DWORD, REFIID, LPVOID*, LPUNKNOWN);
898-
DI8Create_t realCreate = (DI8Create_t)GetProcAddress(
899-
GetModuleHandleA("dinput8.dll"), "DirectInput8Create");
905+
DI8Create_t realCreate = hSysDI8 ?
906+
(DI8Create_t)GetProcAddress(hSysDI8, "DirectInput8Create") : NULL;
900907

901908
if (realCreate)
902909
{
903910
HRESULT hr = realCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
904911
IID_IDirectInput8A, (LPVOID*)&g_realDI, NULL);
905-
Log(" DirectInput8Create (bypass) -> 0x%08lX, DI=0x%p", hr, g_realDI);
912+
Log(" DirectInput8Create -> 0x%08lX, DI=0x%p", hr, g_realDI);
906913

907914
if (SUCCEEDED(hr) && g_realDI)
908915
{
909916
EnumWheelCtx enumCtx;
910917
memset(&enumCtx, 0, sizeof(enumCtx));
911918

912-
g_realDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
919+
HRESULT hrE = g_realDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
913920
EnumWheelCB, &enumCtx, DIEDFL_ATTACHEDONLY);
921+
Log(" EnumDevices(GAMECTRL, ATTACHED) -> 0x%08lX found=%s",
922+
hrE, enumCtx.found ? "yes" : "no");
914923

915924
if (!enumCtx.found)
916925
{
917926
memset(&enumCtx, 0, sizeof(enumCtx));
918-
g_realDI->EnumDevices(0, EnumWheelCB, &enumCtx, DIEDFL_ALLDEVICES);
927+
hrE = g_realDI->EnumDevices(0,
928+
EnumWheelCB, &enumCtx, DIEDFL_ATTACHEDONLY);
929+
Log(" EnumDevices(ALL, ATTACHED) -> 0x%08lX found=%s",
930+
hrE, enumCtx.found ? "yes" : "no");
919931
}
920932

921933
if (enumCtx.found)
@@ -931,13 +943,12 @@ bool LogitechLED::TrySteeringSDK()
931943

932944
if (led)
933945
{
934-
Sleep(1000);
946+
Sleep(2000);
935947
g_SteeringUpdate();
936948
g_PlayLedsDInput(g_realDIDevice, 0.0f, 0.0f, 100.0f);
937949
m_method = METHOD_STEERING_SDK;
938950
m_available = true;
939-
g_bypassDIWrapper = false;
940-
Log("=== LED CONTROL ACTIVE (direct engine + DInput) ===");
951+
Log("=== LED CONTROL ACTIVE (engine + real DInput) ===");
941952
return true;
942953
}
943954

@@ -946,15 +957,15 @@ bool LogitechLED::TrySteeringSDK()
946957
}
947958
}
948959
else
949-
{
950-
Log(" No Logitech wheel via DInput");
951-
}
960+
Log(" No Logitech wheel found in ANY DInput enumeration");
952961

953962
g_realDI->Release();
954963
g_realDI = NULL;
955964
}
956965
}
957-
g_bypassDIWrapper = false;
966+
else
967+
Log(" Could not load system dinput8.dll");
968+
// Don't FreeLibrary(hSysDI8) - may be referenced by DI internals
958969
}
959970

960971
Log(" All methods exhausted");
@@ -1354,7 +1365,7 @@ bool LogitechLED::TryLegacy(HANDLE h, USHORT outLen)
13541365

13551366
bool LogitechLED::Init()
13561367
{
1357-
Log("=== LogitechLED Init v15 (fix parsing + HID++ via WS) ===");
1368+
Log("=== LogitechLED Init v16 (real system DInput fix) ===");
13581369
Log("");
13591370

13601371
if (m_available) return true;

0 commit comments

Comments
 (0)