Revert back to DirectInput COM initialization

Using and linking against DirectInput libraries directly caused dinput.dll
to be loaded at startup time. Windows 10 kills applications started from
services (as the Jenkins slave service) that load dinput.dll.
This commit also adds some safety in case no helper windows could be created.
This commit is contained in:
Roland Winklmeier
2018-10-01 16:45:57 +02:00
committed by Klaus Basan
parent 8ee428e7cf
commit 7f1d1847ca
2 changed files with 19 additions and 8 deletions

View File

@@ -152,15 +152,20 @@ namespace BlackInput
CJoystickWindows::CJoystickWindows(QObject *parent) : IJoystick(parent)
{
// Initialize COM
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
this->createHelperWindow();
this->initDirectInput();
this->enumJoystickDevices();
if (helperWindow)
{
this->initDirectInput();
this->enumJoystickDevices();
}
}
CJoystickWindows::~CJoystickWindows()
{
m_joystickDevices.clear();
m_directInput.reset();
CoUninitialize();
}
void ReleaseDirectInput(IDirectInput8 *obj)
@@ -171,8 +176,13 @@ namespace BlackInput
HRESULT CJoystickWindows::initDirectInput()
{
IDirectInput8 *directInput = nullptr;
HRESULT hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, reinterpret_cast<LPVOID *>(&directInput), nullptr);
// HRESULT hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, reinterpret_cast<LPVOID *>(&directInput), nullptr);
HRESULT hr = CoCreateInstance(CLSID_DirectInput8, nullptr, CLSCTX_INPROC_SERVER, IID_IDirectInput8, reinterpret_cast<LPVOID *>(&directInput));
if(FAILED(hr)) { return hr; }
m_directInput = DirectInput8Ptr(directInput, ReleaseDirectInput);
HINSTANCE instance = GetModuleHandle(nullptr);
hr = m_directInput->Initialize(instance, DIRECTINPUT_VERSION);
return hr;
}

View File

@@ -131,15 +131,16 @@ namespace BlackInput
//! Joystick enumeration callback
static BOOL CALLBACK enumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext);
DirectInput8Ptr m_directInput; //!< DirectInput object
ATOM helperWindowClass = 0;
HWND helperWindow = nullptr;
DirectInput8Ptr m_directInput; //!< DirectInput object
QVector<CJoystickDevice *> m_joystickDevices; //!< Joystick devices
BlackMisc::Input::CHotkeyCombination m_buttonCombination;
const TCHAR *helperWindowClassName = TEXT("HelperWindow");
const TCHAR *helperWindowName = TEXT("JoystickCatcherWindow");
ATOM helperWindowClass = 0;
HWND helperWindow = nullptr;
};
} // ns