diff options
| author | Silent <zdanio95@gmail.com> | 2019-08-19 22:37:48 +0200 |
|---|---|---|
| committer | Silent <zdanio95@gmail.com> | 2019-08-19 22:37:48 +0200 |
| commit | fe8c9dfa148956085683650ad1e84f1e2f3d6159 (patch) | |
| tree | d7e1596d1b71451006bd4b1b84058acf2a3cad2e /Source/Core/WinUpdater/WinUI.cpp | |
| parent | 7520306671d90000f62295e300a66b2e305d665a (diff) | |
WinUpdater: Properly initialize COM on window thread and release ITaskbarList3 on exit
Diffstat (limited to 'Source/Core/WinUpdater/WinUI.cpp')
| -rw-r--r-- | Source/Core/WinUpdater/WinUI.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/Source/Core/WinUpdater/WinUI.cpp b/Source/Core/WinUpdater/WinUI.cpp index f6b0a7345c..403f539b18 100644 --- a/Source/Core/WinUpdater/WinUI.cpp +++ b/Source/Core/WinUpdater/WinUI.cpp @@ -11,6 +11,7 @@ #include <CommCtrl.h> #include <ShObjIdl.h> #include <shellapi.h> +#include <wrl/client.h> #include "Common/Event.h" #include "Common/ScopeGuard.h" @@ -22,7 +23,7 @@ HWND window_handle = nullptr; HWND label_handle = nullptr; HWND total_progressbar_handle = nullptr; HWND current_progressbar_handle = nullptr; -ITaskbarList3* taskbar_list = nullptr; +Microsoft::WRL::ComPtr<ITaskbarList3> taskbar_list; std::thread ui_thread; Common::Event window_created_event; @@ -75,15 +76,13 @@ bool InitWindow() if (!window_handle) return false; - if (FAILED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, - IID_PPV_ARGS(&taskbar_list)))) + if (SUCCEEDED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(taskbar_list.GetAddressOf())))) { - taskbar_list = nullptr; - } - if (taskbar_list && FAILED(taskbar_list->HrInit())) - { - taskbar_list->Release(); - taskbar_list = nullptr; + if (FAILED(taskbar_list->HrInit())) + { + taskbar_list.Reset(); + } } int y = PADDING_HEIGHT; @@ -206,6 +205,14 @@ void SetDescription(const std::string& text) void MessageLoop() { + HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + + Common::ScopeGuard ui_guard{[result] { + taskbar_list.Reset(); + if (SUCCEEDED(result)) + CoUninitialize(); + }}; + if (!InitWindow()) { MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR); |
