https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d82185f10451b3c6661dda8f1a30cb0da114b2ce

commit d82185f10451b3c6661dda8f1a30cb0da114b2ce
Author:     Mark Jansen <[email protected]>
AuthorDate: Sun Oct 23 21:16:56 2022 +0200
Commit:     Mark Jansen <[email protected]>
CommitDate: Tue Nov 1 21:24:14 2022 +0100

    [SDK] Define CCoInit in shellutils
---
 dll/shellext/acppage/ACPPage.cpp                     |  9 +--------
 dll/win32/shell32/shlexec.cpp                        | 18 ++++--------------
 modules/rostests/apitests/browseui/ACListISF.cpp     | 11 ++---------
 modules/rostests/apitests/browseui/IACLCustomMRU.cpp | 11 ++---------
 modules/rostests/apitests/browseui/IACLHistory.cpp   | 13 +++----------
 modules/rostests/apitests/browseui/IAutoComplete.cpp |  8 +-------
 sdk/include/reactos/shellutils.h                     | 19 +++++++++++++++++--
 7 files changed, 30 insertions(+), 59 deletions(-)

diff --git a/dll/shellext/acppage/ACPPage.cpp b/dll/shellext/acppage/ACPPage.cpp
index 14f4f632b01..6c265336af0 100644
--- a/dll/shellext/acppage/ACPPage.cpp
+++ b/dll/shellext/acppage/ACPPage.cpp
@@ -75,18 +75,11 @@ STDAPI DllUnregisterServer()
     return S_OK;
 }
 
-struct CCoInit
-{
-    CCoInit() { hres = CoInitialize(NULL); }
-    ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
-    HRESULT hres;
-};
-
 EXTERN_C
 BOOL WINAPI GetExeFromLnk(PCWSTR pszLnk, PWSTR pszExe, size_t cchSize)
 {
     CCoInit init;
-    if (FAILED_UNEXPECTEDLY(init.hres))
+    if (FAILED_UNEXPECTEDLY(init.hr))
         return FALSE;
 
     CComPtr<IShellLinkW> spShellLink;
diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp
index f1fce51cc9f..133c3b11c2a 100644
--- a/dll/win32/shell32/shlexec.cpp
+++ b/dll/win32/shell32/shlexec.cpp
@@ -1430,24 +1430,14 @@ end:
     return r;
 }
 
-namespace
-{
-    struct CCoInit
-    {
-        CCoInit() { hres = CoInitialize(NULL); }
-        ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
-        HRESULT hres;
-    };
-}
-
 static HRESULT shellex_load_object_and_run(HKEY hkey, LPCGUID guid, 
LPSHELLEXECUTEINFOW sei)
 {
     TRACE("%p %s %p\n", hkey, debugstr_guid(guid), sei);
 
     CCoInit coInit;
 
-    if (FAILED_UNEXPECTEDLY(coInit.hres))
-        return coInit.hres;
+    if (FAILED_UNEXPECTEDLY(coInit.hr))
+        return coInit.hr;
 
     CComPtr<IShellExtInit> obj;
     HRESULT hr = CoCreateInstance(*guid, NULL, CLSCTX_INPROC_SERVER,
@@ -1519,8 +1509,8 @@ static HRESULT 
ShellExecute_ContextMenuVerb(LPSHELLEXECUTEINFOW sei)
 
     CCoInit coInit;
 
-    if (FAILED_UNEXPECTEDLY(coInit.hres))
-        return coInit.hres;
+    if (FAILED_UNEXPECTEDLY(coInit.hr))
+        return coInit.hr;
 
     CComPtr<IContextMenu> cm;
     HRESULT hr = shellex_get_contextmenu(sei, cm);
diff --git a/modules/rostests/apitests/browseui/ACListISF.cpp 
b/modules/rostests/apitests/browseui/ACListISF.cpp
index ab87cb492ef..34516bf4a50 100644
--- a/modules/rostests/apitests/browseui/ACListISF.cpp
+++ b/modules/rostests/apitests/browseui/ACListISF.cpp
@@ -722,19 +722,12 @@ static void GetEnvStatus()
     trace("Show hidden folders: %s\n", g_ShowHidden ? "yes" : "no");
 }
 
-struct CCoInit
-{
-    CCoInit() { hres = CoInitialize(NULL); }
-    ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
-    HRESULT hres;
-};
-
 START_TEST(ACListISF)
 {
     GetEnvStatus();
     CCoInit init;
-    ok_hr(init.hres, S_OK);
-    if (!SUCCEEDED(init.hres))
+    ok_hr(init.hr, S_OK);
+    if (!SUCCEEDED(init.hr))
     {
         skip("CoInitialize failed\n");
         return;
diff --git a/modules/rostests/apitests/browseui/IACLCustomMRU.cpp 
b/modules/rostests/apitests/browseui/IACLCustomMRU.cpp
index 89eb058261d..3627a8f3591 100644
--- a/modules/rostests/apitests/browseui/IACLCustomMRU.cpp
+++ b/modules/rostests/apitests/browseui/IACLCustomMRU.cpp
@@ -32,13 +32,6 @@ ULONG DbgPrint(PCH Format,...);
 #define ok_wstri(x, y) \
     ok(lstrcmpiW(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
 
-struct CCoInit
-{
-    CCoInit() { hres = CoInitialize(NULL); }
-    ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
-    HRESULT hres;
-};
-
 
 DEFINE_GUID(IID_IACLCustomMRU,             0xf729fc5e, 0x8769, 0x4f3e, 0xbd, 
0xb2, 0xd7, 0xb5, 0x0f, 0xd2, 0x27, 0x5b);
 static const WCHAR szTestPath[] = L"TESTPATH_BROWSEUI_APITEST";
@@ -551,8 +544,8 @@ test_IACLCustomMRU_TypedURLs() // TypedURLs is special case
 START_TEST(IACLCustomMRU)
 {
     CCoInit init;
-    ok_hex(init.hres, S_OK);
-    if (!SUCCEEDED(init.hres))
+    ok_hex(init.hr, S_OK);
+    if (!SUCCEEDED(init.hr))
         return;
 
     test_IACLCustomMRU_Basics();
diff --git a/modules/rostests/apitests/browseui/IACLHistory.cpp 
b/modules/rostests/apitests/browseui/IACLHistory.cpp
index 68d25dc0a6a..e57ba165304 100644
--- a/modules/rostests/apitests/browseui/IACLHistory.cpp
+++ b/modules/rostests/apitests/browseui/IACLHistory.cpp
@@ -14,20 +14,13 @@
 #include <stdio.h>
 #include <shellutils.h>
 
-struct CCoInit
-{
-    CCoInit() { hres = CoInitialize(NULL); }
-    ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } }
-    HRESULT hres;
-};
-
 START_TEST(IACLHistory)
 {
     CCoInit init;
-    ok_hex(init.hres, S_OK);
-    if (FAILED(init.hres))
+    ok_hex(init.hr, S_OK);
+    if (FAILED(init.hr))
     {
-        skip("CoInitialize failed with 0x%08lX\n", init.hres);
+        skip("CoInitialize failed with 0x%08lX\n", init.hr);
         return;
     }
 
diff --git a/modules/rostests/apitests/browseui/IAutoComplete.cpp 
b/modules/rostests/apitests/browseui/IAutoComplete.cpp
index d65478e2c5e..6afff3d181b 100644
--- a/modules/rostests/apitests/browseui/IAutoComplete.cpp
+++ b/modules/rostests/apitests/browseui/IAutoComplete.cpp
@@ -16,6 +16,7 @@
 #include <atlsimpcoll.h>
 #include <shlwapi.h>
 #include <strsafe.h>
+#include <shellutils.h>
 
 //#define MANUAL_DEBUGGING
 
@@ -23,13 +24,6 @@
 #define ok_wstri(x, y) \
     ok(lstrcmpiW(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
 
-struct CCoInit
-{
-    CCoInit() { hr = CoInitialize(NULL); }
-    ~CCoInit() { if (SUCCEEDED(hr)) { CoUninitialize(); } }
-    HRESULT hr;
-};
-
 // create an EDIT control
 static HWND MyCreateEditCtrl(INT x, INT y, INT cx, INT cy)
 {
diff --git a/sdk/include/reactos/shellutils.h b/sdk/include/reactos/shellutils.h
index f516d8c6830..9ccce4d3373 100644
--- a/sdk/include/reactos/shellutils.h
+++ b/sdk/include/reactos/shellutils.h
@@ -129,9 +129,8 @@ IUnknown *CComCreatorCentralInstance<T>::s_pInstance = NULL;
 #define DECLARE_CENTRAL_INSTANCE_NOT_AGGREGATABLE(x)                           
 \
 public:                                                                        
 \
     typedef CComCreatorCentralInstance< ATL::CComObject<x> > _CreatorClass;
-#endif
 
-#ifdef __cplusplus
+
 template <class Base>
 class CComDebugObject : public Base
 {
@@ -538,6 +537,22 @@ void DumpIdList(LPCITEMIDLIST pcidl)
     DbgPrint("End IDList Dump.\n");
 }
 
+struct CCoInit
+{
+    CCoInit()
+    {
+        hr = CoInitialize(NULL);
+    }
+    ~CCoInit()
+    {
+        if (SUCCEEDED(hr))
+        {
+            CoUninitialize();
+        }
+    }
+    HRESULT hr;
+};
+
 #endif /* __cplusplus */
 
 #define S_LESSTHAN 0xffff

Reply via email to