summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-09-16 17:01:24 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-09-16 17:53:40 +0200
commita5167736460bac22010333cfe7530a5fa50d2c70 (patch)
treeff4c5885483b06f347df37fb19fa97e6047ae959
parent7e97b1b0ee2d93aeb70b0c50954ff08e1f0eca71 (diff)
compat, dinput: don't overdo COM logic
-rw-r--r--compat/camera-names.cpp6
-rw-r--r--compat/win32-com.cpp45
-rw-r--r--compat/win32-com.hpp19
-rw-r--r--dinput/dinput.cpp3
-rw-r--r--gui/main.cpp2
5 files changed, 4 insertions, 71 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp
index 2f4c2f91..add8c094 100644
--- a/compat/camera-names.cpp
+++ b/compat/camera-names.cpp
@@ -3,7 +3,6 @@
#ifdef _WIN32
# define NO_DSHOW_STRSAFE
# include <dshow.h>
-# include "win32-com.hpp"
# include <cwchar>
#elif defined(__unix) || defined(__linux) || defined(__APPLE__)
# include <unistd.h>
@@ -33,7 +32,7 @@ OPENTRACK_COMPAT_EXPORT QList<QString> get_camera_names()
#if defined(_WIN32)
// Create the System Device Enumerator.
HRESULT hr;
- init_com_threading();
+ CoInitialize(nullptr);
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (FAILED(hr))
@@ -49,7 +48,8 @@ OPENTRACK_COMPAT_EXPORT QList<QString> get_camera_names()
// Enumerate the monikers.
IMoniker *pMoniker = NULL;
ULONG cFetched;
- while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK) {
+ while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
+ {
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
if (SUCCEEDED(hr)) {
diff --git a/compat/win32-com.cpp b/compat/win32-com.cpp
deleted file mode 100644
index b782e3a7..00000000
--- a/compat/win32-com.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifdef _WIN32
-
-#include "win32-com.hpp"
-
-#include "compat/util.hpp"
-
-#include <QString>
-#include <QCoreApplication>
-#include <QApplication>
-#include <QThread>
-#include <QDebug>
-
-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;
- return com_apartment;
- );
-
- HRESULT ret = CoInitializeEx(0, t);
-
- if (ret != S_OK && ret != S_FALSE)
- {
- qDebug() << "CoInitializeEx failed" << (progn (
- switch (ret)
- {
- case RPC_E_CHANGED_MODE:
- return QStringLiteral("COM threading mode already set");
- default:
- return QStringLiteral("Unknown error ") + QString::number(long(ret));
- }
- ));
- return false;
- }
-
- return true;
-}
-#endif
diff --git a/compat/win32-com.hpp b/compat/win32-com.hpp
deleted file mode 100644
index fe2b478f..00000000
--- a/compat/win32-com.hpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-#ifdef _WIN32
-
-#include "export.hpp"
-
-#include <objbase.h>
-#include <ole2.h>
-
-enum com_type : int
-{
- com_multithreaded = COINIT_MULTITHREADED,
- com_apartment = COINIT_APARTMENTTHREADED,
- com_invalid = 0,
-};
-
-bool OPENTRACK_COMPAT_EXPORT init_com_threading(com_type t = com_invalid);
-
-#endif
diff --git a/dinput/dinput.cpp b/dinput/dinput.cpp
index 5dad3eed..8909921a 100644
--- a/dinput/dinput.cpp
+++ b/dinput/dinput.cpp
@@ -1,5 +1,4 @@
#include "dinput.hpp"
-#include "compat/win32-com.hpp"
#include <QDebug>
std::atomic<int> dinput_handle::refcnt;
@@ -7,7 +6,7 @@ std::atomic_flag dinput_handle::init_lock = ATOMIC_FLAG_INIT;
LPDIRECTINPUT8& dinput_handle::init_di()
{
- init_com_threading();
+ CoInitialize(nullptr);
static LPDIRECTINPUT8 di_ = nullptr;
if (di_ == nullptr)
diff --git a/gui/main.cpp b/gui/main.cpp
index ebfd9728..c3e3999a 100644
--- a/gui/main.cpp
+++ b/gui/main.cpp
@@ -10,7 +10,6 @@
#include "migration/migration.hpp"
#include "main-window.hpp"
#include "options/options.hpp"
-#include "compat/win32-com.hpp"
using namespace options;
#include <QApplication>
#include <QCommandLineParser>
@@ -119,7 +118,6 @@ WINAPI
main(int argc, char** argv)
{
#ifdef _WIN32
- init_com_threading();
add_program_library_path();
#elif !defined(__linux)
// workaround QTBUG-38598