Skip to content
Permalink
Browse files

WinUpdater: Properly initialize COM on window thread and release ITas…

…kbarList3 on exit
  • Loading branch information...
CookiePLMonster committed Aug 19, 2019
1 parent 7520306 commit fe8c9dfa148956085683650ad1e84f1e2f3d6159
Showing with 16 additions and 9 deletions.
  1. +16 −9 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);

0 comments on commit fe8c9df

Please sign in to comment.
You can’t perform that action at this time.