diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index 39080de388..3e8044d1d5 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -40,6 +40,7 @@ #include "wx/msw/private.h" #include "wx/msw/wrapshl.h" #include "wx/msw/private/comptr.h" +#include "wx/msw/private/cotaskmemptr.h" #include "wx/dynlib.h" #include @@ -483,8 +484,8 @@ bool GetPathsFromIFileOpenDialog(const wxCOMPtr& fileDialog, bo // helper function for wxDirDialog::ShowIFileOpenDialog() bool ConvertIShellItemToPath(const wxCOMPtr& item, wxString& path) { - LPOLESTR pathOLE = NULL; - const HRESULT hr = item->GetDisplayName(SIGDN_FILESYSPATH, &pathOLE); + wxCoTaskMemPtr pOLEPath; + const HRESULT hr = item->GetDisplayName(SIGDN_FILESYSPATH, &pOLEPath); if ( FAILED(hr) ) { @@ -492,8 +493,7 @@ bool ConvertIShellItemToPath(const wxCOMPtr& item, wxString& path) return false; } - path = pathOLE; - CoTaskMemFree(pathOLE); + path = pOLEPath; return true; }