Nikolay Sivov : shell32: Avoid casts when creating item menu.

Alexandre Julliard julliard at winehq.org
Wed Jan 11 13:39:59 CST 2012


Module: wine
Branch: master
Commit: 72a7c34109b9e30cbef4a53a0eb81725dcf278f7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=72a7c34109b9e30cbef4a53a0eb81725dcf278f7

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Jan 11 05:02:03 2012 +0300

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 bbbd944..fbd1225 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 3b0fb83..88a89a7 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 ec9ba63..43d4108 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 49c4e7e..3bbe26e 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 2482223..200ad86 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 f1fd0e7..39f748b 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 40d4c5c..d22327b 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 c3fd055..911feca 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 7833efe..b46820c 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 */




More information about the wine-cvs mailing list