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 /tests/auto/corelib/io | |
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 'tests/auto/corelib/io')
-rw-r--r-- | tests/auto/corelib/io/qfile/tst_qfile.cpp | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 41dfd12d4f..cbe46ca041 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -22,6 +22,7 @@ #include <private/qabstractfileengine_p.h> #include <private/qfsfileengine_p.h> #include <private/qfilesystemengine_p.h> +#include <QtCore/private/qfunctions_win_p.h> #include <QtTest/private/qemulationdetector_p.h> @@ -1540,13 +1541,9 @@ static QString getWorkingDirectoryForLink(const QString &linkFileName) bool neededCoInit = false; QString ret; + QComHelper comHelper; IShellLink *psl; HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); - if (hres == CO_E_NOTINITIALIZED) { // COM was not initialized - neededCoInit = true; - CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); - hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl); - } if (SUCCEEDED(hres)) { // Get pointer to the IPersistFile interface. IPersistFile *ppf; @@ -1565,10 +1562,6 @@ static QString getWorkingDirectoryForLink(const QString &linkFileName) psl->Release(); } - if (neededCoInit) { - CoUninitialize(); - } - return ret; } #endif |