diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-08-25 10:15:16 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-08-29 15:39:34 +0200 |
commit | 1bc7e9e77b2d6b03b995f376b622d4c8c97dd51c (patch) | |
tree | 23aabcab8feb2489a144d5229a6c8ee40b05bd56 /src/plugins/platforms/windows/qwindowsservices.cpp | |
parent | 49f9cadb52b5ef29e527b60c3881cb15a69c1625 (diff) |
Add QComHelper class for dealing with COM on Windows
Unifies our approach to calling CoInitializeEx and CoUninitialize,
removing a lot of boilerplate in the process, and also fixes a few
bugs where we would incorrectly balance our calls to CoInitializeEx
and CoUninitialize.
The optimistic approach of qfilesystemengine_win.cpp of calling
CoCreateInstance without initializing the COM library explicitly
has been removed, as calling CoInitializeEx should be a noop in
the situation where it's already been loaded.
Change-Id: I9e2ec101678c2ebb9946504b5e8034e58f1bb56a
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsservices.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsservices.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/plugins/platforms/windows/qwindowsservices.cpp b/src/plugins/platforms/windows/qwindowsservices.cpp index f2bd90f4bd..2c84204d2b 100644 --- a/src/plugins/platforms/windows/qwindowsservices.cpp +++ b/src/plugins/platforms/windows/qwindowsservices.cpp @@ -12,6 +12,7 @@ #include <QtCore/qthread.h> #include <QtCore/private/qwinregistry_p.h> +#include <QtCore/private/qfunctions_win_p.h> #include <shlobj.h> #include <shlwapi.h> @@ -34,11 +35,10 @@ public: void run() override { - if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))) { + QComHelper comHelper; + if (comHelper.isValid()) m_result = ShellExecute(nullptr, m_operation, m_file, m_parameters, nullptr, SW_SHOWNORMAL); - CoUninitialize(); - } } HINSTANCE result() const { return m_result; } |