From 9027f80b86e8caddd3245170460450a096afc33f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 7 Jul 2016 11:48:28 +0200 Subject: logic/joystick: initialize dinput handle ASAP --- opentrack-logic/win32-joystick.cpp | 15 +++++++++++++-- opentrack-logic/win32-joystick.hpp | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/opentrack-logic/win32-joystick.cpp b/opentrack-logic/win32-joystick.cpp index 41427629..a24224b0 100644 --- a/opentrack-logic/win32-joystick.cpp +++ b/opentrack-logic/win32-joystick.cpp @@ -1,12 +1,13 @@ #ifdef _WIN32 #undef NDEBUG +#include "win32-joystick.hpp" +#include "opentrack-compat/sleep.hpp" #include #include #include #include -#include "win32-joystick.hpp" -#include "opentrack-compat/sleep.hpp" +#include QMutex win32_joy_ctx::enum_state::mtx; win32_joy_ctx::enum_state win32_joy_ctx::enumerator; @@ -115,6 +116,7 @@ win32_joy_ctx::di_t& win32_joy_ctx::make_di() { if (SUCCEEDED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&di_, NULL))) { + qDebug() << "made di handle"; return di_; } else @@ -384,4 +386,13 @@ win32_joy_ctx::joy::~joy() release(); } +win32_joy_ctx::di_initializer::di_initializer() +{ + HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + if (FAILED(hr)) + qDebug() << "dinput: failed CoInitializeEx" << hr << GetLastError(); + win32_joy_ctx::make_di(); + qDebug() << "made directinput8 handle"; +} + #endif diff --git a/opentrack-logic/win32-joystick.hpp b/opentrack-logic/win32-joystick.hpp index 0da5554b..ab6ebc7c 100644 --- a/opentrack-logic/win32-joystick.hpp +++ b/opentrack-logic/win32-joystick.hpp @@ -71,6 +71,13 @@ struct OPENTRACK_LOGIC_EXPORT win32_joy_ctx win32_joy_ctx(); void refresh(); static di_t& make_di(); + + class di_initializer final + { + static di_initializer self; + di_initializer(); + }; + private: static QString guid_to_string(const GUID guid); -- cgit v1.2.3