diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-12-21 16:19:46 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-12-21 17:03:30 +0100 |
commit | c35f81148fb18ba070516edcbb4d614444899235 (patch) | |
tree | a7411001321a0745f161787fcc2be978e2c94e0a /vcl | |
parent | 9466e895b319fc695cc326b37ee773e14b465c0a (diff) |
Use sal::systools::CoInitializeGuard and sal::systools::ThrowIfFailed
Change-Id: Ifb40e7672671df03b5ffc89905ad1e7b68451b68
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127232
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/win/saldata.hxx | 3 | ||||
-rw-r--r-- | vcl/win/app/fileregistration.cxx | 14 | ||||
-rw-r--r-- | vcl/win/app/salinst.cxx | 6 | ||||
-rw-r--r-- | vcl/win/dtrans/MtaOleClipb.cxx | 5 |
4 files changed, 10 insertions, 18 deletions
diff --git a/vcl/inc/win/saldata.hxx b/vcl/inc/win/saldata.hxx index 80286d87d347..32accf042f37 100644 --- a/vcl/inc/win/saldata.hxx +++ b/vcl/inc/win/saldata.hxx @@ -28,6 +28,7 @@ #include <svdata.hxx> #include <salwtype.hxx> +#include <systools/win32/comtools.hxx> #include <tools/long.hxx> #include <win/wincomp.hxx> @@ -61,7 +62,7 @@ struct SalIcon SalIcon *pNext; }; -class SalData +class SalData : public sal::systools::CoInitializeGuard { public: SalData(); diff --git a/vcl/win/app/fileregistration.cxx b/vcl/win/app/fileregistration.cxx index 2347e46c4b61..75bb0010ba21 100644 --- a/vcl/win/app/fileregistration.cxx +++ b/vcl/win/app/fileregistration.cxx @@ -112,14 +112,9 @@ static bool IsDefaultAppInstalledInReg() void LaunchRegistrationUI() { - const bool bUninit = SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)); - comphelper::ScopeGuard g([bUninit]() { - if (bUninit) - CoUninitialize(); - }); - try { + sal::systools::CoInitializeGuard aGuard(COINIT_APARTMENTTHREADED); if (IsWindows10OrGreater()) { LaunchModernSettingsDialogDefaultApps(); @@ -150,11 +145,8 @@ void CheckFileExtRegistration(weld::Window* pDialogParent) if (!IsDefaultAppInstalledInReg()) return; - const bool bUninit = SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)); - comphelper::ScopeGuard g([bUninit]() { - if (bUninit) - CoUninitialize(); - }); + sal::systools::CoInitializeGuard aGuard(COINIT_APARTMENTTHREADED, false, + sal::systools::CoInitializeGuard::WhenFailed::NoThrow); sal::systools::COMReference<IApplicationAssociationRegistration> pAAR; try { diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx index a34448884057..c7538b519851 100644 --- a/vcl/win/app/salinst.cxx +++ b/vcl/win/app/salinst.cxx @@ -242,6 +242,9 @@ void SalData::initKeyCodeMap() // SalData SalData::SalData() + : sal::systools::CoInitializeGuard(COINIT_APARTMENTTHREADED, false, + sal::systools::CoInitializeGuard::WhenFailed::NoThrow) + // put main thread in Single Threaded Apartment (STA) { mhInst = nullptr; // default instance handle mnCmdShow = 0; // default frame show style @@ -296,7 +299,6 @@ SalData::SalData() SetSalData( this ); initNWF(); - CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); // put main thread in Single Threaded Apartment (STA) static Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); } @@ -306,8 +308,6 @@ SalData::~SalData() deInitNWF(); SetSalData( nullptr ); - CoUninitialize(); - if (gdiplusToken) Gdiplus::GdiplusShutdown(gdiplusToken); } diff --git a/vcl/win/dtrans/MtaOleClipb.cxx b/vcl/win/dtrans/MtaOleClipb.cxx index 00fbf4143386..c1caea416d13 100644 --- a/vcl/win/dtrans/MtaOleClipb.cxx +++ b/vcl/win/dtrans/MtaOleClipb.cxx @@ -697,7 +697,8 @@ unsigned int WINAPI CMtaOleClipboard::clipboardChangedNotifierThreadProc( LPVOID CMtaOleClipboard* pInst = static_cast< CMtaOleClipboard* >( pParam ); OSL_ASSERT( nullptr != pInst ); - CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED ); + sal::systools::CoInitializeGuard aGuard(COINIT_APARTMENTTHREADED, false, + sal::systools::CoInitializeGuard::WhenFailed::NoThrow); // assuming we don't need a lock for // a boolean variable like m_bRun... @@ -733,8 +734,6 @@ unsigned int WINAPI CMtaOleClipboard::clipboardChangedNotifierThreadProc( LPVOID aGuard.clear( ); } - CoUninitialize( ); - return 0; } |