ReactOS 0.4.15-dev-7918-g2a2556c
shellservice.cpp
Go to the documentation of this file.
1/*
2* ReactOS Explorer
3*
4* Copyright 2014 - David Quintana
5*
6* This library is free software; you can redistribute it and/or
7* modify it under the terms of the GNU Lesser General Public
8* License as published by the Free Software Foundation; either
9* version 2.1 of the License, or (at your option) any later version.
10*
11* This library is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14* Lesser General Public License for more details.
15*
16* You should have received a copy of the GNU Lesser General Public
17* License along with this library; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "precomp.h"
22
23static int CALLBACK InitializeAllCallback(void* pItem, void* pData)
24{
25 IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
26 HRESULT * phr = reinterpret_cast<HRESULT *>(pData);
27 TRACE("Initializing SSO %p\n", pOct);
28 *phr = pOct->Exec(&CGID_ShellServiceObject, OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
29 return SUCCEEDED(*phr);
30}
31
32static int CALLBACK ShutdownAllCallback(void* pItem, void* pData)
33{
34 IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
35 TRACE("Shutting down SSO %p\n", pOct);
36 pOct->Exec(&CGID_ShellServiceObject, OLECMDID_SAVE, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
37 return TRUE;
38}
39
40static int CALLBACK DeleteAllEnumCallback(void* pItem, void* pData)
41{
42 IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
43 TRACE("Releasing SSO %p\n", pOct);
44 pOct->Release();
45 return TRUE;
46}
47
49{
50 IOleCommandTarget * pOct;
51 HKEY hkey;
55 DWORD type;
56 LONG ret;
57 HDPA hdpa;
58 HRESULT hr = S_OK;
59 int count = 0;
60
61 *phdpa = NULL;
62
63 TRACE("Enumerating Shell Service Object GUIDs...\n");
64
66 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ShellServiceObjectDelayLoad",
67 &hkey))
68 {
69 ERR("RegOpenKeyW failed.\n");
71 }
72
73 hdpa = DPA_Create(5);
74
75 /* Enumerate */
76 do
77 {
78 DWORD name_len = MAX_PATH;
79 DWORD value_len = sizeof(value); /* byte count! */
80
81 ret = RegEnumValueW(hkey, count, name, &name_len, 0, &type, (LPBYTE) &value, &value_len);
82 if (ret)
83 break;
84
85 if (type != REG_SZ)
86 {
87 WARN("Value type was not REG_SZ.\n");
88 continue;
89 }
90
93 {
94 ERR("CLSIDFromString failed %08x.\n", hr);
95 goto cleanup;
96 }
97
98 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IOleCommandTarget, &pOct));
100 {
101 ERR("CoCreateInstance failed %08x.\n", hr);
102 goto cleanup;
103 }
104
105 DPA_AppendPtr(hdpa, pOct);
106
107 count++;
108 }
109 while (1);
110
112 {
113 ERR("RegEnumValueW failed %08x.\n", ret);
115 goto cleanup;
116 }
117
118 /* Initialize */
121 goto cleanup;
122
123 RegCloseKey(hkey);
124
125 *phdpa = hdpa;
126 return count > 0 ? S_OK : S_FALSE;
127
128cleanup:
129 RegCloseKey(hkey);
130 *phdpa = NULL;
132 return hr;
133}
134
136{
139 DPA_Destroy(hdpa);
140 return S_OK;
141}
#define WARN(fmt,...)
Definition: debug.h:112
#define ERR(fmt,...)
Definition: debug.h:110
#define RegCloseKey(hKey)
Definition: registry.h:49
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
VOID WINAPI DPA_EnumCallback(HDPA hdpa, PFNDPAENUMCALLBACK enumProc, LPVOID lParam)
Definition: dpa.c:969
BOOL WINAPI DPA_Destroy(HDPA hdpa)
Definition: dpa.c:396
HDPA WINAPI DPA_Create(INT nGrow)
Definition: dpa.c:950
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
static void cleanup(void)
Definition: main.c:1335
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
HRESULT Exec([in, unique] const GUID *pguidCmdGroup, [in] DWORD nCmdID, [in] DWORD nCmdexecopt, [in, unique] VARIANT *pvaIn, [in, out, unique] VARIANT *pvaOut)
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_SZ
Definition: layer.c:22
REFCLSID clsid
Definition: msctf.c:82
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define DPA_AppendPtr(hdpa, pitem)
Definition: commctrl.h:4958
static int CALLBACK DeleteAllEnumCallback(void *pItem, void *pData)
static int CALLBACK ShutdownAllCallback(void *pItem, void *pData)
static int CALLBACK InitializeAllCallback(void *pItem, void *pData)
HRESULT InitShellServices(HDPA *phdpa)
HRESULT ShutdownShellServices(HDPA hdpa)
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
Definition: dpa.c:49
Definition: name.c:39
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
unsigned char * LPBYTE
Definition: typedefs.h:53
Definition: pdh_main.c:94
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define S_FALSE
Definition: winerror.h:2357
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180