Author: gadamopoulos
Date: Fri Apr 14 20:03:46 2017
New Revision: 74314
URL:
http://svn.reactos.org/svn/reactos?rev=74314&view=rev
Log:
[SHELLUTILS.H]
- Remove the ShellObjectCreator templates that allowed the caller to pass an arbitrary
interface pointer. Leaving only the templates that take an void ** ppv parameter means
that the callers are forced to use IID_PPV_ARG. This makes it less likely to have a
pointer to an wrong interface.
- Fix the callers to always use IID_PPV_ARG.
- Rewrite the ShellObjectCreator templates to create the objects using the ATL
CreateInstance thus allowing internal ATL methods to be called.
[BROWSEUI]
-Let CBandSite_CreateInstance take an additional parameter for the outer object since
CBandSite is aggregatable. Create the object using the ATL creator class.
Modified:
trunk/reactos/base/shell/rshell/misc.cpp
trunk/reactos/base/shell/rshell/rshell.spec
trunk/reactos/dll/win32/browseui/shellbars/CBandSite.cpp
trunk/reactos/dll/win32/browseui/shellbars/CSHEnumClassesOfCategories.cpp
trunk/reactos/dll/win32/shell32/CDefView.cpp
trunk/reactos/dll/win32/shell32/CEnumIDListBase.cpp
trunk/reactos/dll/win32/shell32/CIDLDataObj.cpp
trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp
trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.h
trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp
trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp
trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp
trunk/reactos/dll/win32/shell32/folders/CNetFolder.cpp
trunk/reactos/dll/win32/shell32/folders/CPrinterFolder.cpp
trunk/reactos/dll/win32/shell32/folders/CRecycleBin.cpp
trunk/reactos/dll/win32/shell32/shell32.cpp
trunk/reactos/sdk/include/reactos/shellutils.h
Modified: trunk/reactos/base/shell/rshell/misc.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/rshell/misc.cpp…
==============================================================================
--- trunk/reactos/base/shell/rshell/misc.cpp [iso-8859-1] (original)
+++ trunk/reactos/base/shell/rshell/misc.cpp [iso-8859-1] Fri Apr 14 20:03:46 2017
@@ -61,8 +61,6 @@
HRESULT WINAPI CMenuSite_Constructor(REFIID riid, LPVOID *ppv);
HRESULT WINAPI CMenuBand_Constructor(REFIID riid, LPVOID *ppv);
HRESULT WINAPI CMergedFolder_Constructor(REFIID riid, LPVOID *ppv);
-HRESULT WINAPI CBandSite_CreateInstance(REFIID riid, void **ppv);
-HRESULT WINAPI CBandSiteMenu_CreateInstance(REFIID riid, void **ppv);
}
DWORD WINAPI WinList_Init(void)
Modified: trunk/reactos/base/shell/rshell/rshell.spec
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/rshell/rshell.s…
==============================================================================
--- trunk/reactos/base/shell/rshell/rshell.spec [iso-8859-1] (original)
+++ trunk/reactos/base/shell/rshell/rshell.spec [iso-8859-1] Fri Apr 14 20:03:46 2017
@@ -7,7 +7,7 @@
@ stdcall CMenuSite_Constructor(ptr ptr);
@ stdcall CMenuBand_Constructor(ptr ptr);
@ stdcall CMergedFolder_Constructor(ptr ptr);
-@ stdcall CBandSite_CreateInstance(ptr ptr)
+@ stdcall CBandSite_CreateInstance(ptr ptr ptr)
@ stdcall CBandSiteMenu_CreateInstance(ptr ptr)
@ stdcall ShellDDEInit(long);
@ stdcall SHCreateDesktop(ptr);
Modified: trunk/reactos/dll/win32/browseui/shellbars/CBandSite.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/browseui/shellba…
==============================================================================
--- trunk/reactos/dll/win32/browseui/shellbars/CBandSite.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/browseui/shellbars/CBandSite.cpp [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -831,7 +831,7 @@
}
extern "C"
-HRESULT WINAPI CBandSite_CreateInstance(REFIID riid, void **ppv)
-{
- return ShellObjectCreator<CBandSite>(riid, ppv);
-}
+HRESULT WINAPI CBandSite_CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
+{
+ return CBandSite::_CreatorClass::CreateInstance(pUnkOuter, riid, ppv);
+}
Modified: trunk/reactos/dll/win32/browseui/shellbars/CSHEnumClassesOfCategories.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/browseui/shellba…
==============================================================================
--- trunk/reactos/dll/win32/browseui/shellbars/CSHEnumClassesOfCategories.cpp [iso-8859-1]
(original)
+++ trunk/reactos/dll/win32/browseui/shellbars/CSHEnumClassesOfCategories.cpp [iso-8859-1]
Fri Apr 14 20:03:46 2017
@@ -327,8 +327,8 @@
{
HRESULT hr;
- hr = ShellObjectCreatorInit<CSHEnumClassesOfCategories, ULONG, CATID*, ULONG,
CATID*, IEnumGUID>(
- cImplemented, pImplemented, cRequired, pRequired, IID_IEnumGUID, out);
+ hr = ShellObjectCreatorInit<CSHEnumClassesOfCategories>(
+ cImplemented, pImplemented, cRequired, pRequired, IID_PPV_ARG(IEnumGUID,
out));
if (FAILED_UNEXPECTEDLY(hr))
return hr;
return S_OK;
Modified: trunk/reactos/dll/win32/shell32/CDefView.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/CDefView…
==============================================================================
--- trunk/reactos/dll/win32/shell32/CDefView.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/CDefView.cpp [iso-8859-1] Fri Apr 14 20:03:46 2017
@@ -3156,7 +3156,7 @@
*/
HRESULT WINAPI IShellView_Constructor(IShellFolder *pFolder, IShellView **newView)
{
- return ShellObjectCreatorInit<CDefView>(pFolder, IID_IShellView, newView);
+ return ShellObjectCreatorInit<CDefView>(pFolder, IID_PPV_ARG(IShellView,
newView));
}
HRESULT WINAPI CDefView_Constructor(IShellFolder *pFolder, REFIID riid, LPVOID * ppvOut)
Modified: trunk/reactos/dll/win32/shell32/CEnumIDListBase.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/CEnumIDL…
==============================================================================
--- trunk/reactos/dll/win32/shell32/CEnumIDListBase.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/CEnumIDListBase.cpp [iso-8859-1] Fri Apr 14 20:03:46
2017
@@ -281,5 +281,5 @@
*/
HRESULT IEnumIDList_Constructor(IEnumIDList **enumerator)
{
- return ShellObjectCreator<CEnumIDListBase>(IID_IEnumIDList, enumerator);
-}
+ return ShellObjectCreator<CEnumIDListBase>(IID_PPV_ARG(IEnumIDList,
enumerator));
+}
Modified: trunk/reactos/dll/win32/shell32/CIDLDataObj.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/CIDLData…
==============================================================================
--- trunk/reactos/dll/win32/shell32/CIDLDataObj.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/CIDLDataObj.cpp [iso-8859-1] Fri Apr 14 20:03:46 2017
@@ -129,7 +129,7 @@
HRESULT IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[], IEnumFORMATETC
**ppFormat)
{
- return ShellObjectCreatorInit<IEnumFORMATETCImpl>(cfmt, afmt,
IID_IEnumFORMATETC, ppFormat);
+ return ShellObjectCreatorInit<IEnumFORMATETCImpl>(cfmt, afmt,
IID_PPV_ARG(IEnumFORMATETC, ppFormat));
}
@@ -410,7 +410,7 @@
*/
HRESULT IDataObject_Constructor(HWND hwndOwner, PCIDLIST_ABSOLUTE pMyPidl,
PCUIDLIST_RELATIVE_ARRAY apidl, UINT cidl, IDataObject **dataObject)
{
- return ShellObjectCreatorInit<CIDLDataObj>(hwndOwner, pMyPidl, apidl, cidl,
IID_IDataObject, dataObject);
+ return ShellObjectCreatorInit<CIDLDataObj>(hwndOwner, pMyPidl, apidl, cidl,
IID_PPV_ARG(IDataObject, dataObject));
}
/*************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp [iso-8859-1]
(original)
+++ trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp [iso-8859-1] Fri Apr
14 20:03:46 2017
@@ -311,7 +311,7 @@
*/
HRESULT WINAPI CControlPanelFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags,
LPENUMIDLIST *ppEnumIDList)
{
- return ShellObjectCreatorInit<CControlPanelEnum>(dwFlags, IID_IEnumIDList,
ppEnumIDList);
+ return ShellObjectCreatorInit<CControlPanelEnum>(dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CControlPanelFolder.h [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -96,7 +96,6 @@
CCPLItemMenu();
~CCPLItemMenu();
HRESULT WINAPI Initialize(UINT cidl, PCUITEMID_CHILD_ARRAY apidl);
- HRESULT WINAPI FinalConstruct();
// IContextMenu
virtual HRESULT WINAPI QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst,
UINT idCmdLast, UINT uFlags);
Modified: trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -441,7 +441,7 @@
*/
HRESULT WINAPI CDesktopFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST
*ppEnumIDList)
{
- return ShellObjectCreatorInit<CDesktopFolderEnum>(this, hwndOwner, dwFlags,
IID_IEnumIDList, ppEnumIDList);
+ return ShellObjectCreatorInit<CDesktopFolderEnum>(this, hwndOwner, dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -377,7 +377,7 @@
*/
HRESULT WINAPI CDrivesFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST
*ppEnumIDList)
{
- return ShellObjectCreatorInit<CDrivesFolderEnum>(hwndOwner, dwFlags,
IID_IEnumIDList, ppEnumIDList);
+ return ShellObjectCreatorInit<CDrivesFolderEnum>(hwndOwner, dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp [iso-8859-1] Fri Apr 14 20:03:46
2017
@@ -253,7 +253,7 @@
DWORD dwFlags,
LPENUMIDLIST *ppEnumIDList)
{
- return ShellObjectCreatorInit<CFileSysEnum>(sPathTarget, dwFlags,
IID_IEnumIDList, ppEnumIDList);
+ return ShellObjectCreatorInit<CFileSysEnum>(sPathTarget, dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CNetFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CNetFolder.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CNetFolder.cpp [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -274,7 +274,7 @@
*/
HRESULT WINAPI CNetFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST
*ppEnumIDList)
{
- return ShellObjectCreatorInit<CNetFolderEnum>(hwndOwner, dwFlags,
IID_IEnumIDList, ppEnumIDList);
+ return ShellObjectCreatorInit<CNetFolderEnum>(hwndOwner, dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CPrinterFolder.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CPrinterFolder.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CPrinterFolder.cpp [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -226,7 +226,7 @@
*/
HRESULT WINAPI CPrinterFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *
ppEnumIDList)
{
- return ShellObjectCreatorInit<CPrintersEnum>(hwndOwner, dwFlags,
IID_IEnumIDList, ppEnumIDList);
+ return ShellObjectCreatorInit<CPrintersEnum>(hwndOwner, dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/folders/CRecycleBin.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/…
==============================================================================
--- trunk/reactos/dll/win32/shell32/folders/CRecycleBin.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/folders/CRecycleBin.cpp [iso-8859-1] Fri Apr 14
20:03:46 2017
@@ -488,7 +488,7 @@
HRESULT WINAPI CRecycleBin::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST
*ppEnumIDList)
{
- return ShellObjectCreatorInit<CRecycleBinEnum>(dwFlags, IID_IEnumIDList,
ppEnumIDList);
+ return ShellObjectCreatorInit<CRecycleBinEnum>(dwFlags,
IID_PPV_ARG(IEnumIDList, ppEnumIDList));
}
HRESULT WINAPI CRecycleBin::BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbc, REFIID riid,
void **ppv)
Modified: trunk/reactos/dll/win32/shell32/shell32.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shell32.…
==============================================================================
--- trunk/reactos/dll/win32/shell32/shell32.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shell32/shell32.cpp [iso-8859-1] Fri Apr 14 20:03:46 2017
@@ -158,7 +158,7 @@
HRESULT IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, const IID
*riidInst, IClassFactory **theFactory)
{
- return ShellObjectCreatorInit<IDefClFImpl>(lpfnCI, pcRefDll, riidInst,
IID_IClassFactory, theFactory);
+ return ShellObjectCreatorInit<IDefClFImpl>(lpfnCI, pcRefDll, riidInst,
IID_PPV_ARG(IClassFactory, theFactory));
}
/******************************************************************************
Modified: trunk/reactos/sdk/include/reactos/shellutils.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/include/reactos/shellu…
==============================================================================
--- trunk/reactos/sdk/include/reactos/shellutils.h [iso-8859-1] (original)
+++ trunk/reactos/sdk/include/reactos/shellutils.h [iso-8859-1] Fri Apr 14 20:03:46 2017
@@ -213,273 +213,133 @@
return S_OK;
}
-template<class T, class R>
-HRESULT inline ShellObjectCreator(REFIID riid, R ** ppv)
-{
- CComPtr<T> obj;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
-ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
- if (FAILED(hResult))
- return hResult;
- return S_OK;
-}
-
-template<class T, class R>
-HRESULT inline ShellObjectCreatorInit(REFIID riid, R ** ppv)
-{
- CComPtr<T> obj;
- CComPtr<R> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize();
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
+template<class T>
+HRESULT inline ShellObjectCreator(REFIID riid, void ** ppv)
+{
+ _CComObject<T> *pobj;
+ HRESULT hResult;
+
+ hResult = _CComObject<T>::CreateInstance(&pobj);
+ if (FAILED(hResult))
+ return hResult;
+
+ pobj->AddRef(); /* CreateInstance returns object with 0 ref count */
+
+ hResult = pobj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+
+ pobj->Release(); /* In case of failure the object will be released */
+
+ return hResult;
}
template<class T>
HRESULT inline ShellObjectCreatorInit(REFIID riid, void ** ppv)
{
- CComPtr<T> obj;
- CComPtr<IUnknown> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize();
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
+ _CComObject<T> *pobj;
+ HRESULT hResult;
+
+ hResult = _CComObject<T>::CreateInstance(&pobj);
+ if (FAILED(hResult))
+ return hResult;
+
+ pobj->AddRef(); /* CreateInstance returns object with 0 ref count */
+
+ hResult = pobj->Initialize();
+
+ if (SUCCEEDED(hResult))
+ hResult = pobj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+
+ pobj->Release(); /* In case of failure the object will be released */
+
+ return hResult;
}
template<class T, class T1>
HRESULT inline ShellObjectCreatorInit(T1 initArg1, REFIID riid, void ** ppv)
{
- CComPtr<T> obj;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, ppv);
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1);
- if (FAILED(hResult))
- return hResult;
-
- return S_OK;
+ _CComObject<T> *pobj;
+ HRESULT hResult;
+
+ hResult = _CComObject<T>::CreateInstance(&pobj);
+ if (FAILED(hResult))
+ return hResult;
+
+ pobj->AddRef(); /* CreateInstance returns object with 0 ref count */
+
+ hResult = pobj->Initialize(initArg1);
+
+ if (SUCCEEDED(hResult))
+ hResult = pobj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+
+ pobj->Release(); /* In case of failure the object will be released */
+
+ return hResult;
}
template<class T, class T1, class T2>
HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, REFIID riid, void **
ppv)
{
- CComPtr<T> obj;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, ppv);
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1, initArg2);
- if (FAILED(hResult))
- return hResult;
-
- return S_OK;
+ _CComObject<T> *pobj;
+ HRESULT hResult;
+
+ hResult = _CComObject<T>::CreateInstance(&pobj);
+ if (FAILED(hResult))
+ return hResult;
+
+ pobj->AddRef(); /* CreateInstance returns object with 0 ref count */
+
+ hResult = pobj->Initialize(initArg1, initArg2);
+
+ if (SUCCEEDED(hResult))
+ hResult = pobj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+
+ pobj->Release(); /* In case of failure the object will be released */
+
+ return hResult;
}
template<class T, class T1, class T2, class T3>
HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, REFIID riid,
void ** ppv)
{
- CComPtr<T> obj;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, ppv);
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1, initArg2, initArg3);
- if (FAILED(hResult))
- return hResult;
-
- return S_OK;
-}
-
-template<class T, class T1, class R>
-HRESULT inline ShellObjectCreatorInit(T1 initArg1, REFIID riid, R ** ppv)
-{
- CComPtr<T> obj;
- CComPtr<R> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1);
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
-}
-
-template<class T, class T1, class T2, class R>
-HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, REFIID riid, R ** ppv)
-{
- CComPtr<T> obj;
- CComPtr<R> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1, initArg2);
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
-}
-
-template<class T, class T1, class T2, class T3, class R>
-HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, REFIID riid,
R ** ppv)
-{
- CComPtr<T> obj;
- CComPtr<R> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1, initArg2, initArg3);
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
-}
-
-template<class T, class T1, class T2, class T3, class T4, class R>
-HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4 initArg4,
REFIID riid, R ** ppv)
-{
- CComPtr<T> obj;
- CComPtr<R> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1, initArg2, initArg3, initArg4);
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
-}
-
-template<class T, class T1, class T2, class T3, class T4, class T5, class R>
-HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4 initArg4,
T5 initArg5, REFIID riid, R ** ppv)
-{
- CComPtr<T> obj;
- CComPtr<R> result;
- HRESULT hResult;
-
- if (ppv == NULL)
- return E_POINTER;
- *ppv = NULL;
- ATLTRY(obj = new _CComObject<T>);
- if (obj.p == NULL)
- return E_OUTOFMEMORY;
- hResult = obj->QueryInterface(riid, reinterpret_cast<void
**>(&result));
- if (FAILED(hResult))
- return hResult;
-
- hResult = obj->Initialize(initArg1, initArg2, initArg3, initArg4, initArg5);
- if (FAILED(hResult))
- return hResult;
-
- *ppv = result.Detach();
-
- return S_OK;
+ _CComObject<T> *pobj;
+ HRESULT hResult;
+
+ hResult = _CComObject<T>::CreateInstance(&pobj);
+ if (FAILED(hResult))
+ return hResult;
+
+ pobj->AddRef(); /* CreateInstance returns object with 0 ref count */
+
+ hResult = pobj->Initialize(initArg1, initArg2, initArg3);
+
+ if (SUCCEEDED(hResult))
+ hResult = pobj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+
+ pobj->Release(); /* In case of failure the object will be released */
+
+ return hResult;
+}
+
+template<class T, class T1, class T2, class T3, class T4>
+HRESULT inline ShellObjectCreatorInit(T1 initArg1, T2 initArg2, T3 initArg3, T4 initArg4,
REFIID riid, void ** ppv)
+{
+ _CComObject<T> *pobj;
+ HRESULT hResult;
+
+ hResult = _CComObject<T>::CreateInstance(&pobj);
+ if (FAILED(hResult))
+ return hResult;
+
+ pobj->AddRef(); /* CreateInstance returns object with 0 ref count */
+
+ hResult = pobj->Initialize(initArg1, initArg2, initArg3, initArg4);
+
+ if (SUCCEEDED(hResult))
+ hResult = pobj->QueryInterface(riid, reinterpret_cast<void **>(ppv));
+
+ pobj->Release(); /* In case of failure the object will be released */
+
+ return hResult;
}
HRESULT inline SHSetStrRet(LPSTRRET pStrRet, LPCSTR pstrValue)