ReactOS  0.4.13-dev-99-g7e18b6d
CShellDispatch.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: shell32
3  * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE: IShellDispatch implementation
5  * COPYRIGHT: Copyright 2015-2018 Mark Jansen (mark.jansen@reactos.org)
6  * Copyright 2018 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7  */
8 
9 #include "precomp.h"
10 #include "winsvc.h"
11 #include <traycmd.h> // tray commands
12 
14 
15 
17 {
18 }
19 
21 {
22 }
23 
25 {
26  return S_OK;
27 }
28 
29 // *** IShellDispatch methods ***
31 {
32  TRACE("(%p, %p)\n", this, ppid);
33 
34  if (!ppid)
35  return E_INVALIDARG;
36 
37  *ppid = this;
38  AddRef();
39 
40  return S_OK;
41 }
42 
44 {
45  TRACE("(%p, %p)\n", this, ppid);
46 
47  if (ppid)
48  {
49  *ppid = static_cast<IDispatch*>(this);
50  AddRef();
51  }
52 
53  return S_OK;
54 }
55 
57 {
58  HRESULT hr = S_FALSE;
59  if(V_VT(var) == VT_I4)
60  {
61  hr = SHGetSpecialFolderLocation(NULL, V_I4(var), idlist);
62  }
63  else if(V_VT(var) == VT_BSTR)
64  {
65  hr = SHILCreateFromPathW(V_BSTR(var), idlist, NULL);
66  }
67  return hr;
68 }
69 
71 {
72  TRACE("(%p, %s, %p)\n", this, debugstr_variant(&vDir), ppsdf);
73  if (!ppsdf)
74  return E_POINTER;
75  *ppsdf = NULL;
76  HRESULT hr;
77 
78  if (V_VT(&vDir) == VT_I2)
79  {
80  hr = VariantChangeType(&vDir, &vDir, 0, VT_I4);
82  return hr;
83  }
84 
86  hr = VariantToIdlist(&vDir, &idlist);
87  if (!SUCCEEDED(hr) || !idlist)
88  return S_FALSE;
89 
90  return ShellObjectCreatorInit<CFolder>(static_cast<LPITEMIDLIST>(idlist), IID_PPV_ARG(Folder, ppsdf));
91 }
92 
94 {
95  return V_VT(arg) == VT_ERROR && V_ERROR(arg) == DISP_E_PARAMNOTFOUND;
96 }
97 
99 {
100  TRACE("(%p, %lu, %ls, %lu, %s, %p)\n", this, Hwnd, Title, Options, debugstr_variant(&RootFolder), ppsdf);
101 
102  *ppsdf = NULL;
103 
104  if (!is_optional_argument(&RootFolder))
105  FIXME("root folder is ignored\n");
106 
107  BROWSEINFOW bi = { 0 };
108  bi.hwndOwner = reinterpret_cast<HWND>(LongToHandle(Hwnd));
109  bi.lpszTitle = Title;
110  bi.ulFlags = Options;
111 
113  selection.Attach(SHBrowseForFolderW(&bi));
114  if (!selection)
115  return S_FALSE;
116 
117  return ShellObjectCreatorInit<CFolder>(static_cast<LPITEMIDLIST>(selection), IID_PPV_ARG(Folder, ppsdf));
118 }
119 
121 {
122  TRACE("(%p, %p)\n", this, ppid);
123 
124  *ppid = NULL;
125 
126  return E_NOTIMPL;
127 }
128 
130 {
131  TRACE("(%p, %s)\n", this, debugstr_variant(&vDir));
132  return E_NOTIMPL;
133 }
134 
136 {
137  TRACE("(%p, %s)\n", this, debugstr_variant(&vDir));
138  return E_NOTIMPL;
139 }
140 
142 {
143  TRACE("(%p)\n", this);
144  return E_NOTIMPL;
145 }
146 
148 {
149  TRACE("(%p)\n", this);
150  return E_NOTIMPL;
151 }
152 
154 {
155  TRACE("(%p)\n", this);
156  return E_NOTIMPL;
157 }
158 
160 {
161  TRACE("(%p)\n", this);
162  return E_NOTIMPL;
163 }
164 
166 {
167  TRACE("(%p)\n", this);
168  return E_NOTIMPL;
169 }
170 
172 {
173  TRACE("(%p)\n", this);
174  return E_NOTIMPL;
175 }
176 
178 {
180  return S_OK;
181 }
182 
184 {
185  TRACE("(%p)\n", this);
186  return E_NOTIMPL;
187 }
188 
190 {
191  TRACE("(%p)\n", this);
192  return E_NOTIMPL;
193 }
194 
196 {
197  TRACE("(%p)\n", this);
198  return E_NOTIMPL;
199 }
200 
202 {
203  TRACE("(%p)\n", this);
204  return E_NOTIMPL;
205 }
206 
208 {
209  TRACE("(%p)\n", this);
210  return E_NOTIMPL;
211 }
212 
214 {
215  TRACE("(%p)\n", this);
216  return E_NOTIMPL;
217 }
218 
220 {
221  TRACE("(%p)\n", this);
222  return E_NOTIMPL;
223 }
224 
226 {
227  TRACE("(%p)\n", this);
228  return E_NOTIMPL;
229 }
230 
232 {
233  TRACE("(%p, %ls)\n", this, szDir);
234  return E_NOTIMPL;
235 }
236 
237 
238 // *** IShellDispatch2 methods ***
240 {
241  TRACE("(%p, %ls, %ls, %p)\n", this, group, restriction, value);
242  return E_NOTIMPL;
243 }
244 
246 {
247  CComVariant args_str, dir_str, op_str, show_int;
248  WCHAR *args = NULL, *dir = NULL, *op = NULL;
249  INT show = 0;
250  HINSTANCE ret;
251 
252  TRACE("(%s, %s, %s, %s, %s)\n", debugstr_w(file), debugstr_variant(&v_args),
253  debugstr_variant(&v_dir), debugstr_variant(&v_op), debugstr_variant(&v_show));
254 
255  args_str.ChangeType(VT_BSTR, &v_args);
256  if (V_VT(&args_str) == VT_BSTR)
257  args = V_BSTR(&args_str);
258 
259  dir_str.ChangeType(VT_BSTR, &v_dir);
260  if (V_VT(&dir_str) == VT_BSTR)
261  dir = V_BSTR(&dir_str);
262 
263  op_str.ChangeType(VT_BSTR, &v_op);
264  if (V_VT(&op_str) == VT_BSTR)
265  op = V_BSTR(&op_str);
266 
267  show_int.ChangeType(VT_I4, &v_show);
268  if (V_VT(&show_int) == VT_I4)
269  show = V_I4(&show_int);
270 
271  ret = ShellExecuteW(NULL, op, file, args, dir, show);
272 
273  return (ULONG_PTR)ret > 32 ? S_OK : S_FALSE;
274 }
275 
277 {
278  TRACE("(%p, %ls, %ls, %ls)\n", this, name, location, model);
279  return E_NOTIMPL;
280 }
281 
283 {
284  TRACE("(%p, %ls, %p)\n", this, name, ret);
285  return E_NOTIMPL;
286 }
287 
289 {
290  TRACE("(%p, %ls, %s, %p)\n", this, service, wine_dbgstr_variant(&persistent), ret);
291  return E_NOTIMPL;
292 }
293 
295 {
296  TRACE("(%p, %ls, %s, %p)\n", this, service, wine_dbgstr_variant(&persistent), ret);
297  return E_NOTIMPL;
298 }
299 
301 {
303  SC_HANDLE scm, service;
304  DWORD dummy;
305 
306  TRACE("(%s, %p)\n", debugstr_w(name), running);
307 
308  V_VT(running) = VT_BOOL;
309  V_BOOL(running) = VARIANT_FALSE;
310 
312  if (!scm)
313  {
314  ERR("failed to connect to service manager\n");
315  return S_OK;
316  }
317 
318  service = OpenServiceW(scm, name, SERVICE_QUERY_STATUS);
319  if (!service)
320  {
321  ERR("Failed to open service %s (%u)\n", debugstr_w(name), GetLastError());
322  CloseServiceHandle(scm);
323  return S_OK;
324  }
325 
327  sizeof(SERVICE_STATUS_PROCESS), &dummy))
328  {
329  TRACE("failed to query service status (%u)\n", GetLastError());
330  CloseServiceHandle(service);
331  CloseServiceHandle(scm);
332  return S_OK;
333  }
334 
335  if (status.dwCurrentState == SERVICE_RUNNING)
336  V_BOOL(running) = VARIANT_TRUE;
337 
338  CloseServiceHandle(service);
339  CloseServiceHandle(scm);
340 
341  return S_OK;
342 }
343 
345 {
346  TRACE("(%p, %ls, %p)\n", this, service, ret);
347  return E_NOTIMPL;
348 }
349 
351 {
352  TRACE("(%p, %ls, %s, %p)\n", this, clsid, wine_dbgstr_variant(&show), ret);
353  return E_NOTIMPL;
354 }
355 
356 
357 // *** IShellDispatch3 methods ***
359 {
360  TRACE("(%p, %s, %ls)\n", this, wine_dbgstr_variant(&file), category);
361  return E_NOTIMPL;
362 }
363 
364 
365 // *** IShellDispatch4 methods ***
367 {
368  TRACE("(%p)\n", this);
369  return E_NOTIMPL;
370 }
371 
373 {
374  TRACE("(%p)\n", this);
375 
376  HWND hTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
378 
379  return S_OK;
380 }
381 
383 {
384  TRACE("(%p, %ls, %p)\n", this, policy, value);
385  return E_NOTIMPL;
386 }
387 
389 {
390  TRACE("(%p, %lu, %p)\n", this, setting, result);
391  return E_NOTIMPL;
392 }
393 
394 
395 // *** IObjectSafety methods ***
397 {
398  TRACE("(%p, %s, %p, %p)\n", this, wine_dbgstr_guid(&riid), pdwSupportedOptions, pdwEnabledOptions);
399  return E_NOTIMPL;
400 }
401 
403 {
404  TRACE("(%p, %s, %lu, %lu)\n", this, wine_dbgstr_guid(&riid), dwOptionSetMask, dwEnabledOptions);
405  return E_NOTIMPL;
406 }
407 
408 
409 // *** IObjectWithSite methods ***
411 {
412  TRACE("(%p, %p)\n", this, pUnkSite);
413  return E_NOTIMPL;
414 }
415 
417 {
418  TRACE("(%p, %s, %p)\n", this, wine_dbgstr_guid(&riid), ppvSite);
419  return E_NOTIMPL;
420 }
421 
423 {
424  return ShellObjectCreatorInit<CShellDispatch>(riid, ppvOut);
425 }
426 
virtual HRESULT STDMETHODCALLTYPE ToggleDesktop()
virtual HRESULT STDMETHODCALLTYPE GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
virtual HRESULT STDMETHODCALLTYPE TrayProperties()
virtual HRESULT STDMETHODCALLTYPE UndoMinimizeALL()
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:965
#define REFIID
Definition: guiddef.h:113
Definition: compat.h:1939
virtual HRESULT STDMETHODCALLTYPE ShutdownWindows()
HRESULT hr
Definition: shlfolder.c:183
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
REFIID riid
Definition: precomp.h:44
virtual HRESULT STDMETHODCALLTYPE ShellExecute(BSTR file, VARIANT args, VARIANT dir, VARIANT op, VARIANT show)
virtual HRESULT STDMETHODCALLTYPE FindFiles()
virtual HRESULT STDMETHODCALLTYPE ServiceStart(BSTR service, VARIANT persistent, VARIANT *ret)
virtual HRESULT STDMETHODCALLTYPE ShowBrowserBar(BSTR clsid, VARIANT show, VARIANT *ret)
HRESULT ChangeType(_In_ VARTYPE newType, _In_opt_ const LPVARIANT src=NULL)
Definition: atlcomcli.h:559
HWND hwndOwner
Definition: shlobj.h:1118
virtual HRESULT STDMETHODCALLTYPE CanStartStopService(BSTR service, VARIANT *ret)
const char * wine_dbgstr_guid(const GUID *guid)
HRESULT WINAPI CShellDispatch_Constructor(REFIID riid, LPVOID *ppvOut)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define TRAYCMD_TOGGLE_DESKTOP
Definition: traycmd.h:31
OLECHAR * BSTR
Definition: compat.h:1934
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2830
enum OPTION_FLAGS Options
Definition: stats.c:44
#define IID_PPV_ARG(Itype, ppType)
Definition: match.c:390
virtual HRESULT STDMETHODCALLTYPE ControlPanelItem(BSTR szDir)
int32_t INT
Definition: typedefs.h:56
short VARIANT_BOOL
Definition: compat.h:1931
int selection
Definition: ctm.c:92
#define DISP_E_PARAMNOTFOUND
Definition: winerror.h:2513
#define V_I4(A)
Definition: oleauto.h:247
virtual HRESULT STDMETHODCALLTYPE MinimizeAll()
WINE_DEFAULT_DEBUG_CHANNEL(shell)
uint32_t ULONG_PTR
Definition: typedefs.h:63
virtual HRESULT STDMETHODCALLTYPE TileHorizontally()
virtual HRESULT STDMETHODCALLTYPE AddToRecent(VARIANT file, BSTR category)
virtual HRESULT STDMETHODCALLTYPE FindComputer()
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define FIXME(fmt,...)
Definition: debug.h:110
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
static BOOL is_optional_argument(const VARIANT *arg)
virtual HRESULT STDMETHODCALLTYPE IsRestricted(BSTR group, BSTR restriction, LONG *value)
HRESULT Initialize()
virtual HRESULT STDMETHODCALLTYPE Help()
#define SERVICE_QUERY_STATUS
Definition: winsvc.h:55
unsigned int dir
Definition: maze.c:112
LPCWSTR lpszTitle
Definition: shlobj.h:1121
virtual HRESULT STDMETHODCALLTYPE IsServiceRunning(BSTR service, VARIANT *running)
GLboolean GLuint group
Definition: glext.h:11120
#define TRACE(s)
Definition: solgame.cpp:4
static const WCHAR Title[]
Definition: oid.c:1259
virtual HRESULT STDMETHODCALLTYPE Windows(IDispatch **ppid)
virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite)
__wchar_t WCHAR
Definition: xmlstorage.h:180
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
void WINAPI ExitWindowsDialog(HWND hWndOwner)
Definition: dialogs.cpp:1145
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2687
LONG HRESULT
Definition: typedefs.h:77
virtual HRESULT STDMETHODCALLTYPE get_Parent(IDispatch **ppid)
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:35
#define WINAPI
Definition: msvc.h:8
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define V_BOOL(A)
Definition: oleauto.h:224
unsigned long DWORD
Definition: ntddk_ex.h:95
virtual HRESULT STDMETHODCALLTYPE ServiceStop(BSTR service, VARIANT persistent, VARIANT *ret)
ULONG AddRef()
HRESULT VariantToIdlist(VARIANT *var, LPITEMIDLIST *idlist)
int ret
REFCLSID clsid
Definition: msctf.c:84
virtual HRESULT STDMETHODCALLTYPE NameSpace(VARIANT vDir, Folder **ppsdf)
static const WCHAR L[]
Definition: oid.c:1250
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
virtual HRESULT STDMETHODCALLTYPE BrowseForFolder(LONG Hwnd, BSTR Title, LONG Options, VARIANT RootFolder, Folder **ppsdf)
#define V_VT(A)
Definition: oleauto.h:211
#define LongToHandle(h)
Definition: basetsd.h:82
unsigned char BYTE
Definition: mem.h:68
#define WM_COMMAND
Definition: winuser.h:1716
#define V_BSTR(A)
Definition: oleauto.h:226
virtual HRESULT STDMETHODCALLTYPE FindPrinter(BSTR name, BSTR location, BSTR model)
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1156
#define ERR(fmt,...)
Definition: debug.h:109
virtual HRESULT STDMETHODCALLTYPE SetInterfaceSafetyOptions(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
virtual HRESULT STDMETHODCALLTYPE get_Application(IDispatch **ppid)
virtual HRESULT STDMETHODCALLTYPE Open(VARIANT vDir)
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
#define S_OK
Definition: intsafe.h:59
UINT ulFlags
Definition: shlobj.h:1122
virtual HRESULT STDMETHODCALLTYPE TileVertically()
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
unsigned char dummy
Definition: maze.c:118
virtual HRESULT STDMETHODCALLTYPE FileRun()
#define E_NOTIMPL
Definition: ddrawi.h:99
#define V_ERROR(A)
Definition: oleauto.h:241
virtual HRESULT STDMETHODCALLTYPE ExplorerPolicy(BSTR policy, VARIANT *value)
HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST *ppidl, DWORD *attributes)
Definition: pidl.c:392
virtual HRESULT STDMETHODCALLTYPE Suspend()
virtual HRESULT STDMETHODCALLTYPE WindowsSecurity()
virtual HRESULT STDMETHODCALLTYPE RefreshMenu()
virtual HRESULT STDMETHODCALLTYPE GetSetting(LONG setting, VARIANT_BOOL *result)
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
Definition: name.c:36
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2236
const char * op_str
Definition: compile.c:77
virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, PVOID *ppvSite)
UINT op
Definition: effect.c:223
virtual HRESULT STDMETHODCALLTYPE SetTime()
virtual HRESULT STDMETHODCALLTYPE GetSystemInformation(BSTR name, VARIANT *ret)
#define E_POINTER
Definition: winerror.h:2365
GLuint64EXT * result
Definition: glext.h:11304
virtual HRESULT STDMETHODCALLTYPE Explore(VARIANT vDir)
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
virtual HRESULT STDMETHODCALLTYPE CascadeWindows()
static SERVICE_STATUS status
Definition: service.c:31
virtual HRESULT STDMETHODCALLTYPE EjectPC()
Definition: compat.h:1938
#define SUCCEEDED(hr)
Definition: intsafe.h:57
Definition: fci.c:126
Definition: ps.c:97