[EXPLORER_NEW]

- Plug a memory leak in IDropTargetImpl
- Do not allocate 64x the required space in TaskSwitchWnd_AllocTaskItem
- Properly free and unregister the tray window
- Fix a few more style issues

svn path=/trunk/; revision=58123
This commit is contained in:
Thomas Faber 2013-01-06 10:12:39 +00:00
parent b9a482f6fd
commit 6effe35b24
8 changed files with 78 additions and 70 deletions

View file

@ -62,6 +62,9 @@ static VOID
IDropTargetImpl_Free(IDropTargetImpl *This) IDropTargetImpl_Free(IDropTargetImpl *This)
{ {
IDropTargetHelper_Release(This->DropTargetHelper); IDropTargetHelper_Release(This->DropTargetHelper);
HeapFree(hProcessHeap,
0,
This);
} }
static ULONG STDMETHODCALLTYPE static ULONG STDMETHODCALLTYPE
@ -127,10 +130,10 @@ CreateDropTarget(IN HWND hwndTarget,
IDropTargetImpl *This; IDropTargetImpl *This;
HRESULT hr; HRESULT hr;
This = (IDropTargetImpl *)HeapAlloc(hProcessHeap, This = HeapAlloc(hProcessHeap,
0, 0,
FIELD_OFFSET(IDropTargetImpl, FIELD_OFFSET(IDropTargetImpl,
Formats[nSupportedFormats])); Formats[nSupportedFormats]));
if (This != NULL) if (This != NULL)
{ {
ZeroMemory(This, ZeroMemory(This,
@ -159,7 +162,7 @@ CreateDropTarget(IN HWND hwndTarget,
NULL, NULL,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
&IID_IDropTargetHelper, &IID_IDropTargetHelper,
(PVOID)&This->DropTargetHelper); (PVOID *)&This->DropTargetHelper);
if (!SUCCEEDED(hr)) if (!SUCCEEDED(hr))
{ {

View file

@ -311,7 +311,7 @@ GetVersionInfoString(IN TCHAR *szFileName,
(LPVOID *)&lpTranslate, (LPVOID *)&lpTranslate,
&cbTranslate); &cbTranslate);
for (i = 0;i < (cbTranslate / sizeof(LANGCODEPAGE));i++) for (i = 0; i < cbTranslate / sizeof(LANGCODEPAGE); i++)
{ {
/* If the bottom eight bits of the language id's /* If the bottom eight bits of the language id's
match, use this version information (since this match, use this version information (since this
@ -410,7 +410,11 @@ _tWinMain(IN HINSTANCE hInstance,
} }
if (Tray != NULL) if (Tray != NULL)
{
TrayMessageLoop(Tray); TrayMessageLoop(Tray);
ITrayWindow_Release(Tray);
UnregisterTrayWindowClass();
}
if (hShellDesktop != NULL) if (hShellDesktop != NULL)
DesktopDestroyShellWindow(hShellDesktop); DesktopDestroyShellWindow(hShellDesktop);

View file

@ -59,10 +59,10 @@ CreateContextMenuFromShellFolderPidl(IN HWND hWndOwner,
hRet = IShellFolder_GetUIObjectOf(psf, hRet = IShellFolder_GetUIObjectOf(psf,
hWndOwner, hWndOwner,
1, 1,
(LPCITEMIDLIST*)&pidl, /* FIXME: shouldn't need a typecast! */ (LPCITEMIDLIST *)&pidl,
&IID_IContextMenu, &IID_IContextMenu,
NULL, NULL,
(PVOID*)&pcm); (PVOID *)&pcm);
if (SUCCEEDED(hRet)) if (SUCCEEDED(hRet))
{ {
hPopup = CreatePopupMenu(); hPopup = CreatePopupMenu();
@ -82,9 +82,10 @@ CreateContextMenuFromShellFolderPidl(IN HWND hWndOwner,
return hPopup; return hPopup;
} }
IContextMenu_Release(pcm);
DestroyMenu(hPopup); DestroyMenu(hPopup);
} }
IContextMenu_Release(pcm);
} }
return NULL; return NULL;
@ -96,7 +97,7 @@ OnStartContextMenuCommand(IN HWND hWndOwner,
IN PVOID pcmContext OPTIONAL, IN PVOID pcmContext OPTIONAL,
IN PVOID Context OPTIONAL) IN PVOID Context OPTIONAL)
{ {
PSTARTMNU_CTMENU_CTX psmcmc = (PSTARTMNU_CTMENU_CTX)pcmContext; PSTARTMNU_CTMENU_CTX psmcmc = pcmContext;
if (uiCmdId != 0) if (uiCmdId != 0)
{ {
@ -231,7 +232,7 @@ CreateStartContextMenu(IN HWND hWndOwner,
hRet = IShellFolder_BindToObject(psfDesktop, hRet = IShellFolder_BindToObject(psfDesktop,
pidlStart, pidlStart,
NULL, NULL,
(REFIID)&IID_IShellFolder, /* FIXME: Shouldn't require a typecast */ &IID_IShellFolder,
(PVOID*)&psfStart); (PVOID*)&psfStart);
if (SUCCEEDED(hRet)) if (SUCCEEDED(hRet))
{ {
@ -255,7 +256,7 @@ CreateStartContextMenu(IN HWND hWndOwner,
AddStartContextMenuItems(hWndOwner, AddStartContextMenuItems(hWndOwner,
hPopup); hPopup);
*((PSTARTMNU_CTMENU_CTX*)ppcmContext) = psmcmc; *ppcmContext = psmcmc;
return hPopup; return hPopup;
} }
else else
@ -815,12 +816,11 @@ UpdateStartMenu(IN OUT IMenuPopup *pMenuPopup,
hRet = IMenuPopup_QueryInterface(pMenuPopup, hRet = IMenuPopup_QueryInterface(pMenuPopup,
&IID_IBanneredBar, &IID_IBanneredBar,
(PVOID)&pbb); (PVOID *)&pbb);
if (SUCCEEDED(hRet)) if (SUCCEEDED(hRet))
{ {
hRet = IBanneredBar_SetBitmap(pbb, hbmBanner); hRet = IBanneredBar_SetBitmap(pbb, hbmBanner);
/* Update the icon size */ /* Update the icon size */
hRet = IBanneredBar_SetIconSize(pbb, hRet = IBanneredBar_SetIconSize(pbb,
bSmallIcons ? BMICON_SMALL : BMICON_LARGE); bSmallIcons ? BMICON_SMALL : BMICON_LARGE);
@ -831,7 +831,7 @@ UpdateStartMenu(IN OUT IMenuPopup *pMenuPopup,
return hRet; return hRet;
} }
IMenuPopup* IMenuPopup *
CreateStartMenu(IN ITrayWindow *Tray, CreateStartMenu(IN ITrayWindow *Tray,
OUT IMenuBand **ppMenuBand, OUT IMenuBand **ppMenuBand,
IN HBITMAP hbmBanner OPTIONAL, IN HBITMAP hbmBanner OPTIONAL,
@ -855,7 +855,7 @@ CreateStartMenu(IN ITrayWindow *Tray,
NULL, NULL,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
&IID_IMenuPopup, &IID_IMenuPopup,
(PVOID*)&pMp); (PVOID *)&pMp);
if (FAILED(hr)) if (FAILED(hr))
{ {
DbgPrint("CoCreateInstance failed: %x\n", hr); DbgPrint("CoCreateInstance failed: %x\n", hr);
@ -864,7 +864,7 @@ CreateStartMenu(IN ITrayWindow *Tray,
hr = IMenuPopup_QueryInterface(pMp, hr = IMenuPopup_QueryInterface(pMp,
&IID_IObjectWithSite, &IID_IObjectWithSite,
(PVOID*)&pOws); (PVOID *)&pOws);
if (FAILED(hr)) if (FAILED(hr))
{ {
DbgPrint("IMenuPopup_QueryInterface failed: %x\n", hr); DbgPrint("IMenuPopup_QueryInterface failed: %x\n", hr);
@ -872,7 +872,7 @@ CreateStartMenu(IN ITrayWindow *Tray,
} }
/* Set the menu site so we can handle messages */ /* Set the menu site so we can handle messages */
hr = IObjectWithSite_SetSite(pOws, (IUnknown*)pSms); hr = IObjectWithSite_SetSite(pOws, (IUnknown *)pSms);
if (FAILED(hr)) if (FAILED(hr))
{ {
DbgPrint("IObjectWithSite_SetSite failed: %x\n", hr); DbgPrint("IObjectWithSite_SetSite failed: %x\n", hr);
@ -903,7 +903,7 @@ CreateStartMenu(IN ITrayWindow *Tray,
goto cleanup; goto cleanup;
} }
hr = IUnknown_QueryInterface(pUnk, &IID_IBandSite, (PVOID*)&pBs); hr = IUnknown_QueryInterface(pUnk, &IID_IBandSite, (PVOID *)&pBs);
if (FAILED(hr)) if (FAILED(hr))
{ {
DbgPrint("IUnknown_QueryInterface pBs failed: %x\n", hr); DbgPrint("IUnknown_QueryInterface pBs failed: %x\n", hr);
@ -919,7 +919,7 @@ CreateStartMenu(IN ITrayWindow *Tray,
goto cleanup; goto cleanup;
} }
hr = IBandSite_GetBandObject(pBs, dwBandId, &IID_IMenuBand, (PVOID*)&pMb); hr = IBandSite_GetBandObject(pBs, dwBandId, &IID_IMenuBand, (PVOID *)&pMb);
if (FAILED(hr)) if (FAILED(hr))
{ {
DbgPrint("IBandSite_GetBandObject failed: %x\n", hr); DbgPrint("IBandSite_GetBandObject failed: %x\n", hr);

View file

@ -506,7 +506,7 @@ ITaskBandImpl_SetSite(IN OUT IObjectWithSite *iface,
/* Check if the site supports IOleWindow */ /* Check if the site supports IOleWindow */
hRet = IUnknown_QueryInterface(pUnkSite, hRet = IUnknown_QueryInterface(pUnkSite,
&IID_IOleWindow, &IID_IOleWindow,
(PVOID*)&OleWindow); (PVOID *)&OleWindow);
if (SUCCEEDED(hRet)) if (SUCCEEDED(hRet))
{ {
HWND hWndParent = NULL; HWND hWndParent = NULL;

View file

@ -852,7 +852,19 @@ TaskSwitchWnd_AllocTaskItem(IN OUT PTASK_SWITCH_WND This)
ASSERT(This->AllocatedTaskItems >= This->TaskItemCount); ASSERT(This->AllocatedTaskItems >= This->TaskItemCount);
if (This->TaskItemCount != 0) if (This->TaskItemCount == 0)
{
This->TaskItems = HeapAlloc(hProcessHeap,
0,
TASK_ITEM_ARRAY_ALLOC * sizeof(*This->TaskItems));
if (This->TaskItems != NULL)
{
This->AllocatedTaskItems = TASK_ITEM_ARRAY_ALLOC;
}
else
return NULL;
}
else if (This->TaskItemCount >= This->AllocatedTaskItems)
{ {
PTASK_ITEM NewArray; PTASK_ITEM NewArray;
SIZE_T NewArrayLength, ActiveTaskItemIndex; SIZE_T NewArrayLength, ActiveTaskItemIndex;
@ -877,18 +889,6 @@ TaskSwitchWnd_AllocTaskItem(IN OUT PTASK_SWITCH_WND This)
else else
return NULL; return NULL;
} }
else
{
This->TaskItems = HeapAlloc(hProcessHeap,
0,
TASK_ITEM_ARRAY_ALLOC * sizeof(*This->TaskItems));
if (This->TaskItems != NULL)
{
This->AllocatedTaskItems = TASK_ITEM_ARRAY_ALLOC;
}
else
return NULL;
}
return This->TaskItems + This->TaskItemCount++; return This->TaskItems + This->TaskItemCount++;
} }
@ -2073,9 +2073,9 @@ ForwardContextMenuMsg:
case WM_NCCREATE: case WM_NCCREATE:
{ {
LPCREATESTRUCT CreateStruct = (LPCREATESTRUCT)lParam; LPCREATESTRUCT CreateStruct = (LPCREATESTRUCT)lParam;
This = (PTASK_SWITCH_WND)HeapAlloc(hProcessHeap, This = HeapAlloc(hProcessHeap,
0, 0,
sizeof(*This)); sizeof(*This));
if (This == NULL) if (This == NULL)
return FALSE; return FALSE;

View file

@ -239,7 +239,6 @@ SysPagerWnd_RemoveButton(IN OUT PSYS_PAGER_WND_DATA This,
PNOTIFY_ITEM updateItem; PNOTIFY_ITEM updateItem;
deleteItem = *NotifyPointer; deleteItem = *NotifyPointer;
SendMessage(This->hWndToolbar, SendMessage(This->hWndToolbar,
TB_DELETEBUTTON, TB_DELETEBUTTON,
deleteItem->Index, deleteItem->Index,
@ -611,16 +610,16 @@ static HWND
CreateSysPagerWnd(IN HWND hWndParent, CreateSysPagerWnd(IN HWND hWndParent,
IN BOOL bVisible) IN BOOL bVisible)
{ {
PSYS_PAGER_WND_DATA TcData; PSYS_PAGER_WND_DATA SpData;
DWORD dwStyle; DWORD dwStyle;
HWND hWnd = NULL; HWND hWnd = NULL;
TcData = HeapAlloc(hProcessHeap, SpData = HeapAlloc(hProcessHeap,
0, 0,
sizeof(*TcData)); sizeof(*SpData));
if (TcData != NULL) if (SpData != NULL)
{ {
ZeroMemory(TcData, sizeof(*TcData)); ZeroMemory(SpData, sizeof(*SpData));
/* Create the window. The tray window is going to move it to the correct /* Create the window. The tray window is going to move it to the correct
position and resize it as needed. */ position and resize it as needed. */
@ -639,18 +638,20 @@ CreateSysPagerWnd(IN HWND hWndParent,
hWndParent, hWndParent,
NULL, NULL,
hExplorerInstance, hExplorerInstance,
TcData); SpData);
if (hWnd == NULL) if (hWnd != NULL)
{
SetWindowTheme(hWnd, L"TrayNotify", NULL);
}
else
{ {
HeapFree(hProcessHeap, HeapFree(hProcessHeap,
0, 0,
TcData); SpData);
} }
} }
SetWindowTheme(hWnd, L"TrayNotify", NULL);
return hWnd; return hWnd;
} }
@ -1381,16 +1382,19 @@ CreateTrayClockWnd(IN HWND hWndParent,
hWndParent, hWndParent,
NULL, NULL,
hExplorerInstance, hExplorerInstance,
(LPVOID)TcData); TcData);
if (hWnd == NULL) if (hWnd != NULL)
{
SetWindowTheme(hWnd, L"TrayNotify", NULL);
}
else
{ {
HeapFree(hProcessHeap, HeapFree(hProcessHeap,
0, 0,
TcData); TcData);
} }
} }
SetWindowTheme(hWnd, L"TrayNotify", NULL);
return hWnd; return hWnd;
@ -1860,7 +1864,7 @@ CreateTrayNotifyWnd(IN OUT ITrayWindow *TrayWindow,
hWndTrayWindow, hWndTrayWindow,
NULL, NULL,
hExplorerInstance, hExplorerInstance,
(LPVOID)TnData); TnData);
if (hWnd == NULL) if (hWnd == NULL)
{ {

View file

@ -369,9 +369,9 @@ DisplayTrayProperties(ITrayWindow *Tray)
PROPSHEETPAGE psp[5]; PROPSHEETPAGE psp[5];
TCHAR szCaption[256]; TCHAR szCaption[256];
pPropInfo = (PPROPSHEET_INFO)HeapAlloc(hProcessHeap, pPropInfo = HeapAlloc(hProcessHeap,
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(PROPSHEET_INFO)); sizeof(PROPSHEET_INFO));
if (!pPropInfo) if (!pPropInfo)
{ {
return NULL; return NULL;

View file

@ -2769,23 +2769,20 @@ TrayMessageLoop(IN OUT ITrayWindow *Tray)
while (1) while (1)
{ {
Ret = (GetMessage(&Msg, Ret = GetMessage(&Msg,
NULL, NULL,
0, 0,
0) != 0); 0);
if (Ret != -1) if (!Ret || Ret == -1)
break;
if (This->StartMenuBand == NULL ||
IMenuBand_IsMenuMessage(This->StartMenuBand,
&Msg) != S_OK)
{ {
if (!Ret) TranslateMessage(&Msg);
break; DispatchMessage(&Msg);
if (This->StartMenuBand == NULL ||
IMenuBand_IsMenuMessage(This->StartMenuBand,
&Msg) != S_OK)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
} }
} }
} }