Commit 571159d5 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

shell32/shellview: Improve error handling on some helpers, fix possible leak.

parent 115efbed
...@@ -634,36 +634,32 @@ static INT CALLBACK fill_list( LPVOID ptr, LPVOID arg ) ...@@ -634,36 +634,32 @@ static INT CALLBACK fill_list( LPVOID ptr, LPVOID arg )
return TRUE; return TRUE;
} }
static HRESULT ShellView_FillList(IShellViewImpl * This) static HRESULT ShellView_FillList(IShellViewImpl *This)
{ {
LPENUMIDLIST pEnumIDList; LPENUMIDLIST pEnumIDList;
LPITEMIDLIST pidl; LPITEMIDLIST pidl;
DWORD dwFetched; DWORD fetched;
HRESULT hRes; HRESULT hr;
HDPA hdpa; HDPA hdpa;
TRACE("%p\n",This); TRACE("(%p)\n", This);
/* get the itemlist from the shfolder*/ /* get the itemlist from the shfolder*/
hRes = IShellFolder_EnumObjects(This->pSFParent,This->hWnd, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &pEnumIDList); hr = IShellFolder_EnumObjects(This->pSFParent, This->hWnd, SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, &pEnumIDList);
if (hRes != S_OK) if (hr != S_OK) return hr;
{
if (hRes==S_FALSE)
return(NOERROR);
return(hRes);
}
/* create a pointer array */ /* create a pointer array */
hdpa = DPA_Create(16); hdpa = DPA_Create(16);
if (!hdpa) if (!hdpa)
{ {
return(E_OUTOFMEMORY); IEnumIDList_Release(pEnumIDList);
return E_OUTOFMEMORY;
} }
/* copy the items into the array*/ /* copy the items into the array*/
while((S_OK == IEnumIDList_Next(pEnumIDList,1, &pidl, &dwFetched)) && dwFetched) while((S_OK == IEnumIDList_Next(pEnumIDList, 1, &pidl, &fetched)) && fetched)
{ {
if (DPA_InsertPtr(hdpa, 0x7fff, pidl) == -1) if (DPA_InsertPtr(hdpa, DPA_GetPtrCount(hdpa), pidl) == -1)
{ {
SHFree(pidl); SHFree(pidl);
} }
...@@ -672,15 +668,11 @@ static HRESULT ShellView_FillList(IShellViewImpl * This) ...@@ -672,15 +668,11 @@ static HRESULT ShellView_FillList(IShellViewImpl * This)
/* sort the array */ /* sort the array */
DPA_Sort(hdpa, ShellView_CompareItems, (LPARAM)This->pSFParent); DPA_Sort(hdpa, ShellView_CompareItems, (LPARAM)This->pSFParent);
/*turn the listview's redrawing off*/ SendMessageW(This->hWndList, WM_SETREDRAW, FALSE, 0);
SendMessageA(This->hWndList, WM_SETREDRAW, FALSE, 0); DPA_DestroyCallback(hdpa, fill_list, This);
SendMessageW(This->hWndList, WM_SETREDRAW, TRUE, 0);
DPA_DestroyCallback( hdpa, fill_list, This ); IEnumIDList_Release(pEnumIDList);
/*turn the listview's redrawing back on and force it to draw*/
SendMessageA(This->hWndList, WM_SETREDRAW, TRUE, 0);
IEnumIDList_Release(pEnumIDList); /* destroy the list*/
return S_OK; return S_OK;
} }
...@@ -688,36 +680,44 @@ static HRESULT ShellView_FillList(IShellViewImpl * This) ...@@ -688,36 +680,44 @@ static HRESULT ShellView_FillList(IShellViewImpl * This)
/********************************************************** /**********************************************************
* ShellView_OnCreate() * ShellView_OnCreate()
*/ */
static LRESULT ShellView_OnCreate(IShellViewImpl * This) static LRESULT ShellView_OnCreate(IShellViewImpl *This)
{ {
IShellView2 *iface = (IShellView2*)This;
IPersistFolder2 *ppf2;
IDropTarget* pdt; IDropTarget* pdt;
SHChangeNotifyEntry ntreg; HRESULT hr;
IPersistFolder2 * ppf2 = NULL;
TRACE("%p\n",This); TRACE("(%p)\n", This);
if(ShellView_CreateList(This)) if (ShellView_CreateList(This))
{ {
if(ShellView_InitList(This)) if (ShellView_InitList(This))
{ {
ShellView_FillList(This); ShellView_FillList(This);
} }
} }
if (SUCCEEDED(IUnknown_QueryInterface((IUnknown*)&This->lpVtbl, &IID_IDropTarget, (LPVOID*)&pdt))) hr = IShellView2_QueryInterface(iface, &IID_IDropTarget, (LPVOID*)&pdt);
if (hr == S_OK)
{ {
RegisterDragDrop(This->hWnd, pdt); RegisterDragDrop(This->hWnd, pdt);
IDropTarget_Release(pdt); IDropTarget_Release(pdt);
} }
/* register for receiving notifications */ /* register for receiving notifications */
IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2); hr = IShellFolder_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&ppf2);
if (ppf2) if (hr == S_OK)
{
SHChangeNotifyEntry ntreg;
hr = IPersistFolder2_GetCurFolder(ppf2, (LPITEMIDLIST*)&ntreg.pidl);
if (hr == S_OK)
{ {
IPersistFolder2_GetCurFolder(ppf2, (LPITEMIDLIST*)&ntreg.pidl);
ntreg.fRecursive = TRUE; ntreg.fRecursive = TRUE;
This->hNotify = SHChangeNotifyRegister(This->hWnd, SHCNF_IDLIST, SHCNE_ALLEVENTS, SHV_CHANGE_NOTIFY, 1, &ntreg); This->hNotify = SHChangeNotifyRegister(This->hWnd, SHCNF_IDLIST, SHCNE_ALLEVENTS,
SHV_CHANGE_NOTIFY, 1, &ntreg);
SHFree((LPITEMIDLIST)ntreg.pidl); SHFree((LPITEMIDLIST)ntreg.pidl);
}
IPersistFolder2_Release(ppf2); IPersistFolder2_Release(ppf2);
} }
...@@ -1875,7 +1875,7 @@ static HRESULT WINAPI IShellView_fnRefresh(IShellView2 * iface) ...@@ -1875,7 +1875,7 @@ static HRESULT WINAPI IShellView_fnRefresh(IShellView2 * iface)
{ {
IShellViewImpl *This = (IShellViewImpl *)iface; IShellViewImpl *This = (IShellViewImpl *)iface;
TRACE("(%p)\n",This); TRACE("(%p)\n", This);
SendMessageW(This->hWndList, LVM_DELETEALLITEMS, 0, 0); SendMessageW(This->hWndList, LVM_DELETEALLITEMS, 0, 0);
ShellView_FillList(This); ShellView_FillList(This);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment