summaryrefslogtreecommitdiffhomepage
path: root/compat/win32-com.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-17 21:40:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-17 22:32:03 +0200
commit62c137157ed04d08e6bcc7a741bcdb046943776f (patch)
tree8f717bd5fa9fdda743f08677544e8cd5c9f9fef2 /compat/win32-com.cpp
parentfad4b316af2cde1a5988ed1bbdbc4ba5933e88df (diff)
compat/win32-com: default to right COM type without caller specifying it
The main window always needs the apartment threaded context for OLE used by Qt. Default to apartment threaded before a QApplication is created, or if the thread is the QApplication thread. Use multithreaded COM otherwise.
Diffstat (limited to 'compat/win32-com.cpp')
-rw-r--r--compat/win32-com.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/compat/win32-com.cpp b/compat/win32-com.cpp
index 689e1411..7bebc500 100644
--- a/compat/win32-com.cpp
+++ b/compat/win32-com.cpp
@@ -5,11 +5,24 @@
#include "compat/util.hpp"
#include <QString>
+#include <QCoreApplication>
+#include <QApplication>
#include <QThread>
#include <QDebug>
-bool OPENTRACK_COMPAT_EXPORT init_com_threading(com_type t)
+bool OPENTRACK_COMPAT_EXPORT init_com_threading(com_type t_)
{
+ const com_type t = progn(
+ if (t_ != com_invalid)
+ return t_;
+ if (QCoreApplication::instance() == nullptr)
+ return com_apartment;
+ if (qApp->thread() == QThread::currentThread())
+ return com_apartment;
+ else
+ return com_multithreaded;
+ );
+
HRESULT ret = CoInitializeEx(0, t);
if (ret != S_OK && ret != S_FALSE)