ReactOS  0.4.14-dev-115-g4576127
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 
13 
14 
16 {
17 }
18 
20 {
21 }
22 
24 {
25  return S_OK;
26 }
27 
28 // *** IShellDispatch methods ***
30 {
31  TRACE("(%p, %p)\n", this, ppid);
32 
33  if (!ppid)
34  return E_INVALIDARG;
35 
36  *ppid = this;
37  AddRef();
38 
39  return S_OK;
40 }
41 
43 {
44  TRACE("(%p, %p)\n", this, ppid);
45 
46  if (ppid)
47  {
48  *ppid = static_cast<IDispatch*>(this);
49  AddRef();
50  }
51 
52  return S_OK;
53 }
54 
56 {
57  HRESULT hr = S_FALSE;
58  if(V_VT(var) == VT_I4)
59  {
60  hr = SHGetSpecialFolderLocation(NULL, V_I4(var), idlist);
61  }
62  else if(V_VT(var) == VT_BSTR)
63  {
64  hr = SHILCreateFromPathW(V_BSTR(var), idlist, NULL);
65  }
66  return hr;
67 }
68 
70 {
71  TRACE("(%p, %s, %p)\n", this, debugstr_variant(&vDir), ppsdf);
72  if (!ppsdf)
73  return E_POINTER;
74  *ppsdf = NULL;
75  HRESULT hr;
76 
77  if (V_VT(&vDir) == VT_I2)
78  {
79  hr = VariantChangeType(&vDir, &vDir, 0, VT_I4);
81  return hr;
82  }
83 
85  hr = VariantToIdlist(&vDir, &idlist);
86  if (!SUCCEEDED(hr) || !idlist)
87  return S_FALSE;
88 
89  return ShellObjectCreatorInit<CFolder>(static_cast<LPITEMIDLIST>(idlist), IID_PPV_ARG(Folder, ppsdf));
90 }
91 
93 {
94  return V_VT(arg) == VT_ERROR && V_ERROR(arg) == DISP_E_PARAMNOTFOUND;
95 }
96 
98 {
99  TRACE("(%p, %lu, %ls, %lu, %s, %p)\n", this, Hwnd, Title, Options, debugstr_variant(&RootFolder), ppsdf);
100 
101  *ppsdf = NULL;
102 
103  if (!is_optional_argument(&RootFolder))
104  FIXME("root folder is ignored\n");
105 
106  BROWSEINFOW bi = { 0 };
107  bi.hwndOwner = reinterpret_cast<HWND>(LongToHandle(Hwnd));
108  bi.lpszTitle = Title;
109  bi.ulFlags = Options;
110 
112  selection.Attach(SHBrowseForFolderW(&bi));
113  if (!selection)
114  return S_FALSE;
115 
116  return ShellObjectCreatorInit<CFolder>(static_cast<LPITEMIDLIST>(selection), IID_PPV_ARG(Folder, ppsdf));
117 }
118 
120 {
121  TRACE("(%p, %p)\n", this, ppid);
122 
123  *ppid = NULL;
124 
125  return E_NOTIMPL;
126 }
127 
129 {
130  TRACE("(%p, %s)\n", this, debugstr_variant(&vDir));
131  return E_NOTIMPL;
132 }
133 
135 {
136  TRACE("(%p, %s)\n", this, debugstr_variant(&vDir));
137  return E_NOTIMPL;
138 }
139 
141 {
142  TRACE("(%p)\n", this);
143  return E_NOTIMPL;
144 }
145 
147 {
148  TRACE("(%p)\n", this);
149  return E_NOTIMPL;
150 }
151 
153 {
154  TRACE("(%p)\n", this);
155  return E_NOTIMPL;
156 }
157 
159 {
160  TRACE("(%p)\n", this);
161  return E_NOTIMPL;
162 }
163 
165 {
166  TRACE("(%p)\n", this);
167  return E_NOTIMPL;
168 }
169 
171 {
172  TRACE("(%p)\n", this);
173  return E_NOTIMPL;
174 }
175 
177 {
179  return S_OK;
180 }
181 
183 {
184  TRACE("(%p)\n", this);
185  return E_NOTIMPL;
186 }
187 
189 {
190  TRACE("(%p)\n", this);
191  return E_NOTIMPL;
192 }
193 
195 {
196  TRACE("(%p)\n", this);
197  return E_NOTIMPL;
198 }
199 
201 {
202  TRACE("(%p)\n", this);
203  return E_NOTIMPL;
204 }
205 
207 {
208  TRACE("(%p)\n", this);
209  return E_NOTIMPL;
210 }
211 
213 {
214  TRACE("(%p)\n", this);
215  return E_NOTIMPL;
216 }
217 
219 {
220  TRACE("(%p)\n", this);
221  return E_NOTIMPL;
222 }
223 
225 {
226  TRACE("(%p)\n", this);
227  return E_NOTIMPL;
228 }
229 
231 {
232  TRACE("(%p, %ls)\n", this, szDir);
233  return E_NOTIMPL;
234 }
235 
236 
237 // *** IShellDispatch2 methods ***
239 {
240  TRACE("(%p, %ls, %ls, %p)\n", this, group, restriction, value);
241  return E_NOTIMPL;
242 }
243 
245 {
246  CComVariant args_str, dir_str, op_str, show_int;
247  WCHAR *args = NULL, *dir = NULL, *op = NULL;
248  INT show = 0;
249  HINSTANCE ret;
250 
251  TRACE("(%s, %s, %s, %s, %s)\n", debugstr_w(file), debugstr_variant(&v_args),
252  debugstr_variant(&v_dir), debugstr_variant(&v_op), debugstr_variant(&v_show));
253 
254  args_str.ChangeType(VT_BSTR, &v_args);
255  if (V_VT(&args_str) == VT_BSTR)
256  args = V_BSTR(&args_str);
257 
258  dir_str.ChangeType(VT_BSTR, &v_dir);
259  if (V_VT(&dir_str) == VT_BSTR)
260  dir = V_BSTR(&dir_str);
261 
262  op_str.ChangeType(VT_BSTR, &v_op);
263  if (V_VT(&op_str) == VT_BSTR)
264  op = V_BSTR(&op_str);
265 
266  show_int.ChangeType(VT_I4, &v_show);
267  if (V_VT(&show_int) == VT_I4)
268  show = V_I4(&show_int);
269 
270  ret = ShellExecuteW(NULL, op, file, args, dir, show);
271 
272  return (ULONG_PTR)ret > 32 ? S_OK : S_FALSE;
273 }
274 
276 {
277  TRACE("(%p, %ls, %ls, %ls)\n", this, name, location, model);
278  return E_NOTIMPL;
279 }
280 
282 {
283  TRACE("(%p, %ls, %p)\n", this, name, ret);
284  return E_NOTIMPL;
285 }
286 
288 {
289  TRACE("(%p, %ls, %s, %p)\n", this, service, wine_dbgstr_variant(&persistent), ret);
290  return E_NOTIMPL;
291 }
292 
294 {
295  TRACE("(%p, %ls, %s, %p)\n", this, service, wine_dbgstr_variant(&persistent), ret);
296  return E_NOTIMPL;
297 }
298 
300 {
302  SC_HANDLE scm, service;
303  DWORD dummy;
304 
305  TRACE("(%s, %p)\n", debugstr_w(name), running);
306 
307  V_VT(running) = VT_BOOL;
308  V_BOOL(running) = VARIANT_FALSE;
309 
311  if (!scm)
312  {
313  ERR("failed to connect to service manager\n");
314  return S_OK;
315  }
316 
317  service = OpenServiceW(scm, name, SERVICE_QUERY_STATUS);
318  if (!service)
319  {
320  ERR("Failed to open service %s (%u)\n", debugstr_w(name), GetLastError());
321  CloseServiceHandle(scm);
322  return S_OK;
323  }
324 
326  sizeof(SERVICE_STATUS_PROCESS), &dummy))
327  {
328  TRACE("failed to query service status (%u)\n", GetLastError());
329  CloseServiceHandle(service);
330  CloseServiceHandle(scm);
331  return S_OK;
332  }
333 
334  if (status.dwCurrentState == SERVICE_RUNNING)
335  V_BOOL(running) = VARIANT_TRUE;
336 
337  CloseServiceHandle(service);
338  CloseServiceHandle(scm);
339 
340  return S_OK;
341 }
342 
344 {
345  TRACE("(%p, %ls, %p)\n", this, service, ret);
346  return E_NOTIMPL;
347 }
348 
350 {
351  TRACE("(%p, %ls, %s, %p)\n", this, clsid, wine_dbgstr_variant(&show), ret);
352  return E_NOTIMPL;
353 }
354 
355 
356 // *** IShellDispatch3 methods ***
358 {
359  TRACE("(%p, %s, %ls)\n", this, wine_dbgstr_variant(&file), category);
360  return E_NOTIMPL;
361 }
362 
363 
364 // *** IShellDispatch4 methods ***
366 {
367  TRACE("(%p)\n", this);
368  return E_NOTIMPL;
369 }
370 
372 {
373  TRACE("(%p)\n", this);
374 
375  HWND hTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
377 
378  return S_OK;
379 }
380 
382 {
383  TRACE("(%p, %ls, %p)\n", this, policy, value);
384  return E_NOTIMPL;
385 }
386 
388 {
389  TRACE("(%p, %lu, %p)\n", this, setting, result);
390  return E_NOTIMPL;
391 }
392 
393 
394 // *** IObjectSafety methods ***
396 {
397  TRACE("(%p, %s, %p, %p)\n", this, wine_dbgstr_guid(&riid), pdwSupportedOptions, pdwEnabledOptions);
398  return E_NOTIMPL;
399 }
400 
402 {
403  TRACE("(%p, %s, %lu, %lu)\n", this, wine_dbgstr_guid(&riid), dwOptionSetMask, dwEnabledOptions);
404  return E_NOTIMPL;
405 }
406 
407 
408 // *** IObjectWithSite methods ***
410 {
411  TRACE("(%p, %p)\n", this, pUnkSite);
412  return E_NOTIMPL;
413 }
414 
416 {
417  TRACE("(%p, %s, %p)\n", this, wine_dbgstr_guid(&riid), ppvSite);
418  return E_NOTIMPL;
419 }
420 
422 {
423  return ShellObjectCreatorInit<CShellDispatch>(riid, ppvOut);
424 }
425 
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:118
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
OLECHAR * BSTR
Definition: compat.h:1934
#define TRAYCMD_TOGGLE_DESKTOP
Definition: undocshell.h:661
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:71
#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:1722
#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:2208
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