From 72a7c34109b9e30cbef4a53a0eb81725dcf278f7 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 11 Jan 2012 05:02:03 +0300 Subject: [PATCH] shell32: Avoid casts when creating item menu. --- dlls/shell32/cpanelfolder.c | 3 +-- dlls/shell32/shell32_main.h | 2 +- dlls/shell32/shfldr_desktop.c | 5 +---- dlls/shell32/shfldr_fs.c | 4 +--- dlls/shell32/shfldr_mycomp.c | 4 +--- dlls/shell32/shfldr_netplaces.c | 3 +-- dlls/shell32/shfldr_unixfs.c | 5 ++--- dlls/shell32/shlmenu.c | 6 ++++-- dlls/shell32/shlview_cmenu.c | 17 +++++++++++------ 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/dlls/shell32/cpanelfolder.c b/dlls/shell32/cpanelfolder.c index bbbd9446dba..fbd1225a34a 100644 --- a/dlls/shell32/cpanelfolder.c +++ b/dlls/shell32/cpanelfolder.c @@ -600,8 +600,7 @@ static HRESULT WINAPI ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 *iface, HWN *ppvOut = NULL; if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) { - pObj = (LPUNKNOWN) ItemMenu_Constructor((IShellFolder *) iface, This->pidlRoot, apidl, cidl); - hr = S_OK; + return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut); } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) { pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl); hr = S_OK; diff --git a/dlls/shell32/shell32_main.h b/dlls/shell32/shell32_main.h index 3b0fb83fc20..88a89a77850 100644 --- a/dlls/shell32/shell32_main.h +++ b/dlls/shell32/shell32_main.h @@ -78,7 +78,7 @@ LPDATAOBJECT IDataObject_Constructor(HWND hwndOwner, LPCITEMIDLIST myPidl, LPCIT LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT, const FORMATETC []) DECLSPEC_HIDDEN; LPCLASSFACTORY IClassFactory_Constructor(REFCLSID) DECLSPEC_HIDDEN; -IContextMenu2 * ItemMenu_Constructor(IShellFolder*, LPCITEMIDLIST, const LPCITEMIDLIST*, UINT) DECLSPEC_HIDDEN; +HRESULT ItemMenu_Constructor(IShellFolder*, LPCITEMIDLIST, const LPCITEMIDLIST*, UINT, REFIID, void**) DECLSPEC_HIDDEN; HRESULT BackgroundMenu_Constructor(IShellFolder*, BOOL, REFIID, void**) DECLSPEC_HIDDEN; LPSHELLVIEW IShellView_Constructor(LPSHELLFOLDER) DECLSPEC_HIDDEN; diff --git a/dlls/shell32/shfldr_desktop.c b/dlls/shell32/shfldr_desktop.c index ec9ba63d18a..43d41087976 100644 --- a/dlls/shell32/shfldr_desktop.c +++ b/dlls/shell32/shfldr_desktop.c @@ -530,10 +530,7 @@ static HRESULT WINAPI ISF_Desktop_fnGetUIObjectOf (IShellFolder2 * iface, if (IsEqualIID (riid, &IID_IContextMenu)) { if (cidl > 0) - { - pObj = (LPUNKNOWN) ItemMenu_Constructor( (IShellFolder *) iface, This->pidlRoot, apidl, cidl); - hr = S_OK; - } + return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut); else return BackgroundMenu_Constructor((IShellFolder*)iface, TRUE, riid, ppvOut); } diff --git a/dlls/shell32/shfldr_fs.c b/dlls/shell32/shfldr_fs.c index 49c4e7e4743..3bbe26eaccd 100644 --- a/dlls/shell32/shfldr_fs.c +++ b/dlls/shell32/shfldr_fs.c @@ -744,9 +744,7 @@ IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface, } if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) { - pObj = (LPUNKNOWN) ItemMenu_Constructor ((IShellFolder *) iface, - This->pidlRoot, apidl, cidl); - hr = S_OK; + return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut); } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) { pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl); diff --git a/dlls/shell32/shfldr_mycomp.c b/dlls/shell32/shfldr_mycomp.c index 24822230566..200ad86ddb0 100644 --- a/dlls/shell32/shfldr_mycomp.c +++ b/dlls/shell32/shfldr_mycomp.c @@ -532,9 +532,7 @@ static HRESULT WINAPI ISF_MyComputer_fnGetUIObjectOf (IShellFolder2 * iface, if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) { - pObj = (LPUNKNOWN) ItemMenu_Constructor ((IShellFolder *) iface, - This->pidlRoot, apidl, cidl); - hr = S_OK; + return ItemMenu_Constructor((IShellFolder*) iface, This->pidlRoot, apidl, cidl, riid, ppvOut); } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) { diff --git a/dlls/shell32/shfldr_netplaces.c b/dlls/shell32/shfldr_netplaces.c index f1fd0e7215e..39f748be182 100644 --- a/dlls/shell32/shfldr_netplaces.c +++ b/dlls/shell32/shfldr_netplaces.c @@ -426,8 +426,7 @@ static HRESULT WINAPI ISF_NetworkPlaces_fnGetUIObjectOf (IShellFolder2 * iface, if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) { - pObj = (LPUNKNOWN) ItemMenu_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl); - hr = S_OK; + return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut); } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) { diff --git a/dlls/shell32/shfldr_unixfs.c b/dlls/shell32/shfldr_unixfs.c index 40d4c5c35ac..d22327b7bb8 100644 --- a/dlls/shell32/shfldr_unixfs.c +++ b/dlls/shell32/shfldr_unixfs.c @@ -1165,10 +1165,9 @@ static HRESULT WINAPI UnixFolder_IShellFolder2_GetUIObjectOf(IShellFolder2* ifac if(hr != S_FALSE) return hr; } - + if (IsEqualIID(&IID_IContextMenu, riid)) { - *ppvOut = ItemMenu_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl); - return S_OK; + return ItemMenu_Constructor((IShellFolder*)iface, This->m_pidlLocation, apidl, cidl, riid, ppvOut); } else if (IsEqualIID(&IID_IDataObject, riid)) { *ppvOut = IDataObject_Constructor(hwndOwner, This->m_pidlLocation, apidl, cidl); return S_OK; diff --git a/dlls/shell32/shlmenu.c b/dlls/shell32/shlmenu.c index c3fd055e639..911feca9ef3 100644 --- a/dlls/shell32/shlmenu.c +++ b/dlls/shell32/shlmenu.c @@ -1275,7 +1275,8 @@ HRESULT WINAPI CDefFolderMenu_Create2(LPCITEMIDLIST pidlFolder, HWND hwnd, UINT } else folder_pidl=ILClone(pidlFolder); - system_menu = (IContextMenu*)ItemMenu_Constructor(psf,folder_pidl,(const LPCITEMIDLIST*)apidl,cidl); + + ItemMenu_Constructor(psf, folder_pidl, (const LPCITEMIDLIST*)apidl, cidl, &IID_IContextMenu, (void**)&system_menu); hres= SHELL_CreateContextMenu(hwnd,system_menu,psf,folder_pidl,apidl,cidl,ahkeys,nKeys,&IID_IContextMenu,(void**)ppcm); IContextMenu_Release(system_menu); ILFree(folder_pidl); @@ -1300,7 +1301,8 @@ HRESULT WINAPI SHCreateDefaultContextMenu(const DEFCONTEXTMENU *pdcm, REFIID rii folder_pidl=ILClone(pdcm->pidlFolder); if(pdcm->cKeys==0) FIXME("Loading shell extensions using IQueryAssociations not yet supported\n"); - system_menu = (IContextMenu*)ItemMenu_Constructor(folder,folder_pidl,(const LPCITEMIDLIST*)pdcm->apidl,pdcm->cidl); + + ItemMenu_Constructor(folder, folder_pidl, (const LPCITEMIDLIST*)pdcm->apidl, pdcm->cidl, &IID_IContextMenu, (void**)&system_menu); ret = SHELL_CreateContextMenu(pdcm->hwnd,system_menu,folder,folder_pidl,(LPCITEMIDLIST*)pdcm->apidl,pdcm->cidl,pdcm->aKeys,pdcm->cKeys,riid,ppv); IContextMenu_Release(system_menu); ILFree(folder_pidl); diff --git a/dlls/shell32/shlview_cmenu.c b/dlls/shell32/shlview_cmenu.c index 7833efeecbb..b46820c1a11 100644 --- a/dlls/shell32/shlview_cmenu.c +++ b/dlls/shell32/shlview_cmenu.c @@ -569,12 +569,16 @@ static const IContextMenu3Vtbl ItemContextMenuVtbl = ContextMenu_HandleMenuMsg2 }; -IContextMenu2 *ItemMenu_Constructor(IShellFolder *parent, LPCITEMIDLIST pidl, const LPCITEMIDLIST *apidl, UINT cidl) +HRESULT ItemMenu_Constructor(IShellFolder *parent, LPCITEMIDLIST pidl, const LPCITEMIDLIST *apidl, UINT cidl, + REFIID riid, void **pObj) { ContextMenu* This; - UINT u; + HRESULT hr; + int i; This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This)); + if (!This) return E_OUTOFMEMORY; + This->IContextMenu3_iface.lpVtbl = &ItemContextMenuVtbl; This->ref = 1; This->verb_offset = 0; @@ -588,12 +592,13 @@ IContextMenu2 *ItemMenu_Constructor(IShellFolder *parent, LPCITEMIDLIST pidl, co This->desktop = FALSE; - for(u = 0; u < cidl; u++) - This->allvalues &= (_ILIsValue(apidl[u]) ? 1 : 0); + for (i = 0; i < cidl; i++) + This->allvalues &= (_ILIsValue(apidl[i]) ? 1 : 0); - TRACE("(%p)\n", This); + hr = IContextMenu3_QueryInterface(&This->IContextMenu3_iface, riid, pObj); + IContextMenu3_Release(&This->IContextMenu3_iface); - return (IContextMenu2*)&This->IContextMenu3_iface; + return hr; } /* Background menu implementation */ -- 2.11.4.GIT