Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cead3f0

Browse filesBrowse files
committed
refactor(COM): centralize COM initialization management.
Remove separated `CoInitialize/CoUninitialize` calls Move COM initialization responsibility to thread level (e.g. main thread)
1 parent 56f1cf2 commit cead3f0
Copy full SHA for cead3f0

File tree

Expand file treeCollapse file tree

3 files changed

+1
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+1
-17
lines changed
Open diff view settings
Collapse file

‎src/utils/AppUtil.cpp‎

Copy file name to clipboardExpand all lines: src/utils/AppUtil.cpp
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ namespace AppUtil {
252252

253253
/// name, appid, exePath
254254
QList<std::tuple<QString, QString, QString>> getStartAppList() {
255-
auto co_init = CoInitialize(nullptr);
256-
257255
IShellItem* psi = nullptr;
258256
// like Get-StartApps
259257
HRESULT hr = SHCreateItemInKnownFolder(FOLDERID_AppsFolder, 0, nullptr, IID_PPV_ARGS(&psi));
@@ -308,9 +306,6 @@ namespace AppUtil {
308306
psi->Release();
309307
}
310308

311-
if (SUCCEEDED(co_init))
312-
CoUninitialize();
313-
314309
return appList;
315310
}
316311

Collapse file

‎src/utils/Util.cpp‎

Copy file name to clipboardExpand all lines: src/utils/Util.cpp
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ namespace Util {
124124
}
125125

126126
QString getFileDescription(const QString& path) {
127-
CoInitialize(nullptr); // 初始化 COM 库
128-
129127
QString desc = QFileInfo(path).completeBaseName(); // fallback to base name
130128

131129
// 使用 CComPtr 自动释放 IShellItem2 接口
@@ -143,7 +141,6 @@ namespace Util {
143141
qWarning() << "SHCreateItemFromParsingName() failed";
144142
}
145143

146-
CoUninitialize(); // 取消初始化 COM 库
147144
return desc;
148145
}
149146

Collapse file

‎src/utils/uiautomation.cpp‎

Copy file name to clipboardExpand all lines: src/utils/uiautomation.cpp
+1-9Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ IUIAutomation* UIAutomation::pAutomation = nullptr;
1111

1212
bool UIAutomation::init() {
1313
qDebug() << "UIAutomation initializing";
14-
HRESULT hr = CoInitialize(nullptr);
15-
if (FAILED(hr)) {
16-
qCritical() << "Failed to initialize COM library.";
17-
return false;
18-
}
19-
2014
pAutomation = nullptr;
21-
hr = CoCreateInstance(CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_IUIAutomation, (void**) &pAutomation);
15+
HRESULT hr = CoCreateInstance(CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_IUIAutomation, (void**) &pAutomation);
2216
if (FAILED(hr) || !pAutomation) {
2317
qCritical() << "Failed to create UIAutomation instance.";
24-
CoUninitialize();
2518
return false;
2619
}
2720

@@ -70,7 +63,6 @@ void UIAutomation::cleanup() {
7063
if (pAutomation) {
7164
pAutomation->Release();
7265
pAutomation = nullptr;
73-
CoUninitialize();
7466
}
7567
}
7668

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.