summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-07 11:48:28 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-07 11:48:28 +0200
commit9027f80b86e8caddd3245170460450a096afc33f (patch)
tree92bb4476e9906a222b5c91fc2341eb6c5c7368a2
parentfa9dcb9da8ad8a0b164a4008d5b493a268d682cf (diff)
logic/joystick: initialize dinput handle ASAP
-rw-r--r--opentrack-logic/win32-joystick.cpp15
-rw-r--r--opentrack-logic/win32-joystick.hpp7
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 <cassert>
#include <cstring>
#include <algorithm>
#include <cmath>
-#include "win32-joystick.hpp"
-#include "opentrack-compat/sleep.hpp"
+#include <objbase.h>
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);