summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-06-30 12:13:36 +0200
committerOliver Wolff <oliver.wolff@qt.io>2017-08-30 13:33:17 +0000
commited5a1134d50f6dbed3fc568c799a39f4e2338056 (patch)
tree7d5d0f38d4563e3cdcbad6cc40b4afe546d6c34a
parentd7af5496668da92bfa48564053bfc039cef6ecea (diff)
Bail out early if Bluetooth is used on an unsupported Windows versionv5.10.0-alpha1
Task-number: QTBUG-61566 Change-Id: Ie40762dbb07e9f29d862e75eba2bc05da088a34c Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/bluetooth/bluetooth.pro2
-rw-r--r--src/bluetooth/qbluetoothutils_win.cpp38
2 files changed, 39 insertions, 1 deletions
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 5f415341..b45da961 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -199,7 +199,7 @@ qtConfig(bluez) {
!winrt {
SOURCES += qbluetoothutils_win.cpp
DEFINES += CLASSIC_APP_BUILD
- LIBS += runtimeobject.lib
+ LIBS += runtimeobject.lib user32.lib
}
QT += core-private
diff --git a/src/bluetooth/qbluetoothutils_win.cpp b/src/bluetooth/qbluetoothutils_win.cpp
index d561dcef..fa3127cb 100644
--- a/src/bluetooth/qbluetoothutils_win.cpp
+++ b/src/bluetooth/qbluetoothutils_win.cpp
@@ -42,6 +42,14 @@
#define Q_OS_WINRT
#include <QtCore/qfunctions_winrt.h>
+#include <wrl.h>
+#include <windows.devices.bluetooth.h>
+
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Devices::Bluetooth;
+using namespace ABI::Windows::Foundation;
+
QT_BEGIN_NAMESPACE
#pragma warning (push)
@@ -53,4 +61,34 @@ HRESULT QEventDispatcherWinRT::runOnXamlThread(const std::function<HRESULT()> &d
}
#pragma warning (pop)
+extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID)
+{
+ switch (reason)
+ {
+ case DLL_PROCESS_ATTACH: {
+ // Check if we are running on a recent enough Windows
+ HRESULT hr = OleInitialize(NULL);
+ if (FAILED(hr)) {
+ MessageBox(NULL, (LPCWSTR)L"OleInitialize failed.", (LPCWSTR)L"Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
+ exit(-1);
+ }
+ ComPtr<IBluetoothDeviceStatics> deviceStatics;
+ hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Bluetooth_BluetoothDevice).Get(), &deviceStatics);
+ if (hr == REGDB_E_CLASSNOTREG) {
+ QString error ("This Windows version (" + QSysInfo::kernelVersion() + ") does not "
+ "support the required Bluetooth API. Consider updating to a more recent Windows "
+ "(10.0.10586 or above).");
+ MessageBox(NULL, (LPCWSTR)error.constData(), (LPCWSTR)L"Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
+ CoUninitialize();
+ exit(-1);
+ }
+ break;
+ }
+ case DLL_PROCESS_DETACH:
+ CoUninitialize();
+ }
+
+ return TRUE;
+}
+
QT_END_NAMESPACE