diff --git a/src/api/directinput/JoystickDirectInput.cpp b/src/api/directinput/JoystickDirectInput.cpp index 2e0a3b7e..44eef79c 100644 --- a/src/api/directinput/JoystickDirectInput.cpp +++ b/src/api/directinput/JoystickDirectInput.cpp @@ -47,6 +47,9 @@ CJoystickDirectInput::CJoystickDirectInput(GUID device CJoystickDirectInput::~CJoystickDirectInput() { + if (m_joystickDevice) + m_joystickDevice->Unacquire(); + SAFE_RELEASE(m_joystickDevice); } diff --git a/src/api/directinput/JoystickInterfaceDirectInput.cpp b/src/api/directinput/JoystickInterfaceDirectInput.cpp index 793ae648..fb136842 100644 --- a/src/api/directinput/JoystickInterfaceDirectInput.cpp +++ b/src/api/directinput/JoystickInterfaceDirectInput.cpp @@ -142,6 +142,16 @@ BOOL CALLBACK CJoystickInterfaceDirectInput::EnumJoysticksCallback(const DIDEVIC return DIENUM_CONTINUE; } + // This will be done automatically when we're in the foreground but + // let's do it here to check that we can acquire it and that no other + // app has it in exclusive mode + hr = pJoystick->Acquire(); + if (FAILED(hr)) + { + esyslog("%s: Failed to acquire device on: %s", __FUNCTION__, pdidInstance->tszProductName); + return DIENUM_CONTINUE; + } + const std::string strName = pdidInstance->tszProductName ? pdidInstance->tszProductName : ""; context->AddScanResult(JoystickPtr(new CJoystickDirectInput(pdidInstance->guidInstance, pJoystick, strName)));