From 4724a069e4ed3036213191fccde677fbbea8d486 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilyev Date: Fri, 13 Dec 2024 13:14:38 +0400 Subject: [PATCH] [llvm][Support][Windows] Refactored remove_directories() w/o CComPtr and atlbase.h This is the update of #118677. --- llvm/lib/Support/Windows/Path.inc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index d4e8261ae4feb..17db114caeb1e 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -25,7 +25,6 @@ // These two headers must be included last, and make sure shlobj is required // after Windows.h to make sure it picks up our definition of _WIN32_WINNT #include "llvm/Support/Windows/WindowsSupport.h" -#include #include #include @@ -1395,19 +1394,22 @@ std::error_code remove_directories(const Twine &path, bool IgnoreErrors) { if (FAILED(HR)) break; auto Uninitialize = make_scope_exit([] { CoUninitialize(); }); - CComPtr FileOp; - HR = FileOp.CoCreateInstance(CLSID_FileOperation); + IFileOperation *FileOp = NULL; + HR = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL, + IID_PPV_ARGS(&FileOp)); if (FAILED(HR)) break; + auto FileOpRelease = make_scope_exit([&FileOp] { FileOp->Release(); }); HR = FileOp->SetOperationFlags(FOF_NO_UI | FOFX_NOCOPYHOOKS); if (FAILED(HR)) break; PIDLIST_ABSOLUTE PIDL = ILCreateFromPathW(Path16.data()); auto FreePIDL = make_scope_exit([&PIDL] { ILFree(PIDL); }); - CComPtr ShItem; + IShellItem *ShItem = NULL; HR = SHCreateItemFromIDList(PIDL, IID_PPV_ARGS(&ShItem)); if (FAILED(HR)) break; + auto ShItemRelease = make_scope_exit([&ShItem] { ShItem->Release(); }); HR = FileOp->DeleteItem(ShItem, NULL); if (FAILED(HR)) break;