Skip to content
Permalink
Browse files

Merge pull request #8322 from CookiePLMonster/8298-com-fix

WinUpdater: Properly initialize COM on window thread
  • Loading branch information
stenzek committed Aug 20, 2019
2 parents 7520306 + fe8c9df commit e71cab06a8824a9b34f0402314a55b90e597dbbf
Showing with 16 additions and 9 deletions.
  1. +16 −9 Source/Core/WinUpdater/WinUI.cpp
@@ -11,6 +11,7 @@
#include <CommCtrl.h> #include <CommCtrl.h>
#include <ShObjIdl.h> #include <ShObjIdl.h>
#include <shellapi.h> #include <shellapi.h>
#include <wrl/client.h>


#include "Common/Event.h" #include "Common/Event.h"
#include "Common/ScopeGuard.h" #include "Common/ScopeGuard.h"
@@ -22,7 +23,7 @@ HWND window_handle = nullptr;
HWND label_handle = nullptr; HWND label_handle = nullptr;
HWND total_progressbar_handle = nullptr; HWND total_progressbar_handle = nullptr;
HWND current_progressbar_handle = nullptr; HWND current_progressbar_handle = nullptr;
ITaskbarList3* taskbar_list = nullptr; Microsoft::WRL::ComPtr<ITaskbarList3> taskbar_list;


std::thread ui_thread; std::thread ui_thread;
Common::Event window_created_event; Common::Event window_created_event;
@@ -75,15 +76,13 @@ bool InitWindow()
if (!window_handle) if (!window_handle)
return false; return false;


if (FAILED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, if (SUCCEEDED(CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&taskbar_list)))) IID_PPV_ARGS(taskbar_list.GetAddressOf()))))
{ {
taskbar_list = nullptr; if (FAILED(taskbar_list->HrInit()))
} {
if (taskbar_list && FAILED(taskbar_list->HrInit())) taskbar_list.Reset();
{ }
taskbar_list->Release();
taskbar_list = nullptr;
} }


int y = PADDING_HEIGHT; int y = PADDING_HEIGHT;
@@ -206,6 +205,14 @@ void SetDescription(const std::string& text)


void MessageLoop() void MessageLoop()
{ {
HRESULT result = CoInitializeEx(nullptr, COINIT_MULTITHREADED);

Common::ScopeGuard ui_guard{[result] {
taskbar_list.Reset();
if (SUCCEEDED(result))
CoUninitialize();
}};

if (!InitWindow()) if (!InitWindow())
{ {
MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR); MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR);

0 comments on commit e71cab0

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