Skip to content

Commit d098ce0

Browse files
authored
[llvm][Support][Windows] Refactored remove_directories() w/o CComPtr and atlbase.h (#119843)
This is the update of #118677. This patch fixes building with mingw.
1 parent a21f9bf commit d098ce0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
// These two headers must be included last, and make sure shlobj is required
2626
// after Windows.h to make sure it picks up our definition of _WIN32_WINNT
2727
#include "llvm/Support/Windows/WindowsSupport.h"
28-
#include <atlbase.h>
2928
#include <shellapi.h>
3029
#include <shlobj.h>
3130

@@ -1395,19 +1394,22 @@ std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
13951394
if (FAILED(HR))
13961395
break;
13971396
auto Uninitialize = make_scope_exit([] { CoUninitialize(); });
1398-
CComPtr<IFileOperation> FileOp;
1399-
HR = FileOp.CoCreateInstance(CLSID_FileOperation);
1397+
IFileOperation *FileOp = NULL;
1398+
HR = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL,
1399+
IID_PPV_ARGS(&FileOp));
14001400
if (FAILED(HR))
14011401
break;
1402+
auto FileOpRelease = make_scope_exit([&FileOp] { FileOp->Release(); });
14021403
HR = FileOp->SetOperationFlags(FOF_NO_UI | FOFX_NOCOPYHOOKS);
14031404
if (FAILED(HR))
14041405
break;
14051406
PIDLIST_ABSOLUTE PIDL = ILCreateFromPathW(Path16.data());
14061407
auto FreePIDL = make_scope_exit([&PIDL] { ILFree(PIDL); });
1407-
CComPtr<IShellItem> ShItem;
1408+
IShellItem *ShItem = NULL;
14081409
HR = SHCreateItemFromIDList(PIDL, IID_PPV_ARGS(&ShItem));
14091410
if (FAILED(HR))
14101411
break;
1412+
auto ShItemRelease = make_scope_exit([&ShItem] { ShItem->Release(); });
14111413
HR = FileOp->DeleteItem(ShItem, NULL);
14121414
if (FAILED(HR))
14131415
break;

0 commit comments

Comments
 (0)