vbscript: Moved Error object implementation to global.c.
[wine/multimedia.git] / dlls / wshom.ocx / shell.c
blob92733cc67f7e45667536b2481c85627c1c729f95
1 /*
2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wshom_private.h"
20 #include "wshom.h"
22 #include "shellapi.h"
23 #include "shlobj.h"
24 #include "dispex.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wshom);
31 static const char *debugstr_variant(const VARIANT *v)
33 if(!v)
34 return "(null)";
36 switch(V_VT(v)) {
37 case VT_EMPTY:
38 return "{VT_EMPTY}";
39 case VT_NULL:
40 return "{VT_NULL}";
41 case VT_I4:
42 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
43 case VT_R8:
44 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
45 case VT_BSTR:
46 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
47 case VT_DISPATCH:
48 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
49 case VT_BOOL:
50 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
51 case VT_UNKNOWN:
52 return wine_dbg_sprintf("{VT_UNKNOWN: %p}", V_UNKNOWN(v));
53 case VT_UINT:
54 return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v));
55 case VT_BSTR|VT_BYREF:
56 return wine_dbg_sprintf("{VT_BSTR|VT_BYREF: ptr %p, data %s}",
57 V_BSTRREF(v), debugstr_w(V_BSTRREF(v) ? *V_BSTRREF(v) : NULL));
58 default:
59 return wine_dbg_sprintf("{vt %d}", V_VT(v));
63 static IWshShell3 WshShell3;
65 typedef struct
67 IWshCollection IWshCollection_iface;
68 LONG ref;
69 } WshCollection;
71 typedef struct
73 IWshShortcut IWshShortcut_iface;
74 LONG ref;
76 IShellLinkW *link;
77 BSTR path_link;
78 } WshShortcut;
80 static inline WshCollection *impl_from_IWshCollection( IWshCollection *iface )
82 return CONTAINING_RECORD(iface, WshCollection, IWshCollection_iface);
85 static inline WshShortcut *impl_from_IWshShortcut( IWshShortcut *iface )
87 return CONTAINING_RECORD(iface, WshShortcut, IWshShortcut_iface);
90 static HRESULT WINAPI WshCollection_QueryInterface(IWshCollection *iface, REFIID riid, void **ppv)
92 WshCollection *This = impl_from_IWshCollection(iface);
94 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
96 if (IsEqualGUID(riid, &IID_IUnknown) ||
97 IsEqualGUID(riid, &IID_IDispatch) ||
98 IsEqualGUID(riid, &IID_IWshCollection))
100 *ppv = iface;
101 }else {
102 FIXME("Unknown iface %s\n", debugstr_guid(riid));
103 *ppv = NULL;
104 return E_NOINTERFACE;
107 IUnknown_AddRef((IUnknown*)*ppv);
108 return S_OK;
111 static ULONG WINAPI WshCollection_AddRef(IWshCollection *iface)
113 WshCollection *This = impl_from_IWshCollection(iface);
114 LONG ref = InterlockedIncrement(&This->ref);
115 TRACE("(%p) ref = %d\n", This, ref);
116 return ref;
119 static ULONG WINAPI WshCollection_Release(IWshCollection *iface)
121 WshCollection *This = impl_from_IWshCollection(iface);
122 LONG ref = InterlockedDecrement(&This->ref);
123 TRACE("(%p) ref = %d\n", This, ref);
125 if (!ref)
126 HeapFree(GetProcessHeap(), 0, This);
128 return ref;
131 static HRESULT WINAPI WshCollection_GetTypeInfoCount(IWshCollection *iface, UINT *pctinfo)
133 WshCollection *This = impl_from_IWshCollection(iface);
134 TRACE("(%p)->(%p)\n", This, pctinfo);
135 *pctinfo = 1;
136 return S_OK;
139 static HRESULT WINAPI WshCollection_GetTypeInfo(IWshCollection *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
141 WshCollection *This = impl_from_IWshCollection(iface);
142 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
143 return get_typeinfo(IWshCollection_tid, ppTInfo);
146 static HRESULT WINAPI WshCollection_GetIDsOfNames(IWshCollection *iface, REFIID riid, LPOLESTR *rgszNames,
147 UINT cNames, LCID lcid, DISPID *rgDispId)
149 WshCollection *This = impl_from_IWshCollection(iface);
150 ITypeInfo *typeinfo;
151 HRESULT hr;
153 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
155 hr = get_typeinfo(IWshCollection_tid, &typeinfo);
156 if(SUCCEEDED(hr))
158 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
159 ITypeInfo_Release(typeinfo);
162 return hr;
165 static HRESULT WINAPI WshCollection_Invoke(IWshCollection *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
166 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
168 WshCollection *This = impl_from_IWshCollection(iface);
169 ITypeInfo *typeinfo;
170 HRESULT hr;
172 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
173 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
175 hr = get_typeinfo(IWshCollection_tid, &typeinfo);
176 if(SUCCEEDED(hr))
178 hr = ITypeInfo_Invoke(typeinfo, &This->IWshCollection_iface, dispIdMember, wFlags,
179 pDispParams, pVarResult, pExcepInfo, puArgErr);
180 ITypeInfo_Release(typeinfo);
183 return hr;
186 static HRESULT WINAPI WshCollection_Item(IWshCollection *iface, VARIANT *index, VARIANT *value)
188 WshCollection *This = impl_from_IWshCollection(iface);
189 static const WCHAR allusersdesktopW[] = {'A','l','l','U','s','e','r','s','D','e','s','k','t','o','p',0};
190 static const WCHAR allusersprogramsW[] = {'A','l','l','U','s','e','r','s','P','r','o','g','r','a','m','s',0};
191 static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
192 PIDLIST_ABSOLUTE pidl;
193 WCHAR pathW[MAX_PATH];
194 int kind = 0;
195 BSTR folder;
196 HRESULT hr;
198 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(index), value);
200 if (V_VT(index) != VT_BSTR)
202 FIXME("only BSTR index supported, got %d\n", V_VT(index));
203 return E_NOTIMPL;
206 folder = V_BSTR(index);
207 if (!strcmpiW(folder, desktopW))
208 kind = CSIDL_DESKTOP;
209 else if (!strcmpiW(folder, allusersdesktopW))
210 kind = CSIDL_COMMON_DESKTOPDIRECTORY;
211 else if (!strcmpiW(folder, allusersprogramsW))
212 kind = CSIDL_COMMON_PROGRAMS;
213 else
215 FIXME("folder kind %s not supported\n", debugstr_w(folder));
216 return E_NOTIMPL;
219 hr = SHGetSpecialFolderLocation(NULL, kind, &pidl);
220 if (hr != S_OK) return hr;
222 if (SHGetPathFromIDListW(pidl, pathW))
224 V_VT(value) = VT_BSTR;
225 V_BSTR(value) = SysAllocString(pathW);
226 hr = V_BSTR(value) ? S_OK : E_OUTOFMEMORY;
228 else
229 hr = E_FAIL;
231 CoTaskMemFree(pidl);
233 return hr;
236 static HRESULT WINAPI WshCollection_Count(IWshCollection *iface, LONG *count)
238 WshCollection *This = impl_from_IWshCollection(iface);
239 FIXME("(%p)->(%p): stub\n", This, count);
240 return E_NOTIMPL;
243 static HRESULT WINAPI WshCollection_get_length(IWshCollection *iface, LONG *count)
245 WshCollection *This = impl_from_IWshCollection(iface);
246 FIXME("(%p)->(%p): stub\n", This, count);
247 return E_NOTIMPL;
250 static HRESULT WINAPI WshCollection__NewEnum(IWshCollection *iface, IUnknown *Enum)
252 WshCollection *This = impl_from_IWshCollection(iface);
253 FIXME("(%p)->(%p): stub\n", This, Enum);
254 return E_NOTIMPL;
257 static const IWshCollectionVtbl WshCollectionVtbl = {
258 WshCollection_QueryInterface,
259 WshCollection_AddRef,
260 WshCollection_Release,
261 WshCollection_GetTypeInfoCount,
262 WshCollection_GetTypeInfo,
263 WshCollection_GetIDsOfNames,
264 WshCollection_Invoke,
265 WshCollection_Item,
266 WshCollection_Count,
267 WshCollection_get_length,
268 WshCollection__NewEnum
271 static HRESULT WshCollection_Create(IWshCollection **collection)
273 WshCollection *This;
275 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
276 if (!This) return E_OUTOFMEMORY;
278 This->IWshCollection_iface.lpVtbl = &WshCollectionVtbl;
279 This->ref = 1;
281 *collection = &This->IWshCollection_iface;
283 return S_OK;
286 /* IWshShortcut */
287 static HRESULT WINAPI WshShortcut_QueryInterface(IWshShortcut *iface, REFIID riid, void **ppv)
289 WshShortcut *This = impl_from_IWshShortcut(iface);
291 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
293 if (IsEqualGUID(riid, &IID_IUnknown) ||
294 IsEqualGUID(riid, &IID_IDispatch) ||
295 IsEqualGUID(riid, &IID_IWshShortcut))
297 *ppv = iface;
298 }else {
299 FIXME("Unknown iface %s\n", debugstr_guid(riid));
300 *ppv = NULL;
301 return E_NOINTERFACE;
304 IUnknown_AddRef((IUnknown*)*ppv);
305 return S_OK;
308 static ULONG WINAPI WshShortcut_AddRef(IWshShortcut *iface)
310 WshShortcut *This = impl_from_IWshShortcut(iface);
311 LONG ref = InterlockedIncrement(&This->ref);
312 TRACE("(%p) ref = %d\n", This, ref);
313 return ref;
316 static ULONG WINAPI WshShortcut_Release(IWshShortcut *iface)
318 WshShortcut *This = impl_from_IWshShortcut(iface);
319 LONG ref = InterlockedDecrement(&This->ref);
320 TRACE("(%p) ref = %d\n", This, ref);
322 if (!ref)
324 SysFreeString(This->path_link);
325 IShellLinkW_Release(This->link);
326 HeapFree(GetProcessHeap(), 0, This);
329 return ref;
332 static HRESULT WINAPI WshShortcut_GetTypeInfoCount(IWshShortcut *iface, UINT *pctinfo)
334 WshShortcut *This = impl_from_IWshShortcut(iface);
335 TRACE("(%p)->(%p)\n", This, pctinfo);
336 *pctinfo = 1;
337 return S_OK;
340 static HRESULT WINAPI WshShortcut_GetTypeInfo(IWshShortcut *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
342 WshShortcut *This = impl_from_IWshShortcut(iface);
343 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
344 return get_typeinfo(IWshShortcut_tid, ppTInfo);
347 static HRESULT WINAPI WshShortcut_GetIDsOfNames(IWshShortcut *iface, REFIID riid, LPOLESTR *rgszNames,
348 UINT cNames, LCID lcid, DISPID *rgDispId)
350 WshShortcut *This = impl_from_IWshShortcut(iface);
351 ITypeInfo *typeinfo;
352 HRESULT hr;
354 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
356 hr = get_typeinfo(IWshShortcut_tid, &typeinfo);
357 if(SUCCEEDED(hr))
359 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
360 ITypeInfo_Release(typeinfo);
363 return hr;
366 static HRESULT WINAPI WshShortcut_Invoke(IWshShortcut *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
367 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
369 WshShortcut *This = impl_from_IWshShortcut(iface);
370 ITypeInfo *typeinfo;
371 HRESULT hr;
373 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
374 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
376 hr = get_typeinfo(IWshShortcut_tid, &typeinfo);
377 if(SUCCEEDED(hr))
379 hr = ITypeInfo_Invoke(typeinfo, &This->IWshShortcut_iface, dispIdMember, wFlags,
380 pDispParams, pVarResult, pExcepInfo, puArgErr);
381 ITypeInfo_Release(typeinfo);
384 return hr;
387 static HRESULT WINAPI WshShortcut_get_FullName(IWshShortcut *iface, BSTR *name)
389 WshShortcut *This = impl_from_IWshShortcut(iface);
390 FIXME("(%p)->(%p): stub\n", This, name);
391 return E_NOTIMPL;
394 static HRESULT WINAPI WshShortcut_get_Arguments(IWshShortcut *iface, BSTR *Arguments)
396 WshShortcut *This = impl_from_IWshShortcut(iface);
397 WCHAR buffW[INFOTIPSIZE];
398 HRESULT hr;
400 TRACE("(%p)->(%p)\n", This, Arguments);
402 if (!Arguments)
403 return E_POINTER;
405 *Arguments = NULL;
407 hr = IShellLinkW_GetArguments(This->link, buffW, sizeof(buffW)/sizeof(WCHAR));
408 if (FAILED(hr))
409 return hr;
411 *Arguments = SysAllocString(buffW);
412 return *Arguments ? S_OK : E_OUTOFMEMORY;
415 static HRESULT WINAPI WshShortcut_put_Arguments(IWshShortcut *iface, BSTR Arguments)
417 WshShortcut *This = impl_from_IWshShortcut(iface);
419 TRACE("(%p)->(%s)\n", This, debugstr_w(Arguments));
421 return IShellLinkW_SetArguments(This->link, Arguments);
424 static HRESULT WINAPI WshShortcut_get_Description(IWshShortcut *iface, BSTR *Description)
426 WshShortcut *This = impl_from_IWshShortcut(iface);
427 FIXME("(%p)->(%p): stub\n", This, Description);
428 return E_NOTIMPL;
431 static HRESULT WINAPI WshShortcut_put_Description(IWshShortcut *iface, BSTR Description)
433 WshShortcut *This = impl_from_IWshShortcut(iface);
434 TRACE("(%p)->(%s)\n", This, debugstr_w(Description));
435 return IShellLinkW_SetDescription(This->link, Description);
438 static HRESULT WINAPI WshShortcut_get_Hotkey(IWshShortcut *iface, BSTR *Hotkey)
440 WshShortcut *This = impl_from_IWshShortcut(iface);
441 FIXME("(%p)->(%p): stub\n", This, Hotkey);
442 return E_NOTIMPL;
445 static HRESULT WINAPI WshShortcut_put_Hotkey(IWshShortcut *iface, BSTR Hotkey)
447 WshShortcut *This = impl_from_IWshShortcut(iface);
448 FIXME("(%p)->(%s): stub\n", This, debugstr_w(Hotkey));
449 return E_NOTIMPL;
452 static HRESULT WINAPI WshShortcut_get_IconLocation(IWshShortcut *iface, BSTR *IconPath)
454 static const WCHAR fmtW[] = {'%','s',',',' ','%','d',0};
455 WshShortcut *This = impl_from_IWshShortcut(iface);
456 WCHAR buffW[MAX_PATH], pathW[MAX_PATH];
457 INT icon = 0;
458 HRESULT hr;
460 TRACE("(%p)->(%p)\n", This, IconPath);
462 if (!IconPath)
463 return E_POINTER;
465 hr = IShellLinkW_GetIconLocation(This->link, buffW, sizeof(buffW)/sizeof(WCHAR), &icon);
466 if (FAILED(hr)) return hr;
468 sprintfW(pathW, fmtW, buffW, icon);
469 *IconPath = SysAllocString(pathW);
470 if (!*IconPath) return E_OUTOFMEMORY;
472 return S_OK;
475 static HRESULT WINAPI WshShortcut_put_IconLocation(IWshShortcut *iface, BSTR IconPath)
477 WshShortcut *This = impl_from_IWshShortcut(iface);
478 HRESULT hr;
479 WCHAR *ptr;
480 BSTR path;
481 INT icon;
483 TRACE("(%p)->(%s)\n", This, debugstr_w(IconPath));
485 /* scan for icon id */
486 ptr = strrchrW(IconPath, ',');
487 if (!ptr)
489 WARN("icon index not found\n");
490 return E_FAIL;
493 path = SysAllocStringLen(IconPath, ptr-IconPath);
495 /* skip spaces if any */
496 while (isspaceW(*++ptr))
499 icon = atoiW(ptr);
501 hr = IShellLinkW_SetIconLocation(This->link, path, icon);
502 SysFreeString(path);
504 return hr;
507 static HRESULT WINAPI WshShortcut_put_RelativePath(IWshShortcut *iface, BSTR rhs)
509 WshShortcut *This = impl_from_IWshShortcut(iface);
510 FIXME("(%p)->(%s): stub\n", This, debugstr_w(rhs));
511 return E_NOTIMPL;
514 static HRESULT WINAPI WshShortcut_get_TargetPath(IWshShortcut *iface, BSTR *Path)
516 WshShortcut *This = impl_from_IWshShortcut(iface);
517 FIXME("(%p)->(%p): stub\n", This, Path);
518 return E_NOTIMPL;
521 static HRESULT WINAPI WshShortcut_put_TargetPath(IWshShortcut *iface, BSTR Path)
523 WshShortcut *This = impl_from_IWshShortcut(iface);
524 TRACE("(%p)->(%s)\n", This, debugstr_w(Path));
525 return IShellLinkW_SetPath(This->link, Path);
528 static HRESULT WINAPI WshShortcut_get_WindowStyle(IWshShortcut *iface, int *ShowCmd)
530 WshShortcut *This = impl_from_IWshShortcut(iface);
531 TRACE("(%p)->(%p)\n", This, ShowCmd);
532 return IShellLinkW_GetShowCmd(This->link, ShowCmd);
535 static HRESULT WINAPI WshShortcut_put_WindowStyle(IWshShortcut *iface, int ShowCmd)
537 WshShortcut *This = impl_from_IWshShortcut(iface);
538 TRACE("(%p)->(%d)\n", This, ShowCmd);
539 return IShellLinkW_SetShowCmd(This->link, ShowCmd);
542 static HRESULT WINAPI WshShortcut_get_WorkingDirectory(IWshShortcut *iface, BSTR *WorkingDirectory)
544 WshShortcut *This = impl_from_IWshShortcut(iface);
545 WCHAR buffW[MAX_PATH];
546 HRESULT hr;
548 TRACE("(%p)->(%p)\n", This, WorkingDirectory);
550 if (!WorkingDirectory)
551 return E_POINTER;
553 *WorkingDirectory = NULL;
554 hr = IShellLinkW_GetWorkingDirectory(This->link, buffW, sizeof(buffW)/sizeof(WCHAR));
555 if (FAILED(hr)) return hr;
557 *WorkingDirectory = SysAllocString(buffW);
558 return *WorkingDirectory ? S_OK : E_OUTOFMEMORY;
561 static HRESULT WINAPI WshShortcut_put_WorkingDirectory(IWshShortcut *iface, BSTR WorkingDirectory)
563 WshShortcut *This = impl_from_IWshShortcut(iface);
564 TRACE("(%p)->(%s)\n", This, debugstr_w(WorkingDirectory));
565 return IShellLinkW_SetWorkingDirectory(This->link, WorkingDirectory);
568 static HRESULT WINAPI WshShortcut_Load(IWshShortcut *iface, BSTR PathLink)
570 WshShortcut *This = impl_from_IWshShortcut(iface);
571 FIXME("(%p)->(%s): stub\n", This, debugstr_w(PathLink));
572 return E_NOTIMPL;
575 static HRESULT WINAPI WshShortcut_Save(IWshShortcut *iface)
577 WshShortcut *This = impl_from_IWshShortcut(iface);
578 IPersistFile *file;
579 HRESULT hr;
581 TRACE("(%p)\n", This);
583 IShellLinkW_QueryInterface(This->link, &IID_IPersistFile, (void**)&file);
584 hr = IPersistFile_Save(file, This->path_link, TRUE);
585 IPersistFile_Release(file);
587 return hr;
590 static const IWshShortcutVtbl WshShortcutVtbl = {
591 WshShortcut_QueryInterface,
592 WshShortcut_AddRef,
593 WshShortcut_Release,
594 WshShortcut_GetTypeInfoCount,
595 WshShortcut_GetTypeInfo,
596 WshShortcut_GetIDsOfNames,
597 WshShortcut_Invoke,
598 WshShortcut_get_FullName,
599 WshShortcut_get_Arguments,
600 WshShortcut_put_Arguments,
601 WshShortcut_get_Description,
602 WshShortcut_put_Description,
603 WshShortcut_get_Hotkey,
604 WshShortcut_put_Hotkey,
605 WshShortcut_get_IconLocation,
606 WshShortcut_put_IconLocation,
607 WshShortcut_put_RelativePath,
608 WshShortcut_get_TargetPath,
609 WshShortcut_put_TargetPath,
610 WshShortcut_get_WindowStyle,
611 WshShortcut_put_WindowStyle,
612 WshShortcut_get_WorkingDirectory,
613 WshShortcut_put_WorkingDirectory,
614 WshShortcut_Load,
615 WshShortcut_Save
618 static HRESULT WshShortcut_Create(const WCHAR *path, IDispatch **shortcut)
620 WshShortcut *This;
621 HRESULT hr;
623 *shortcut = NULL;
625 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
626 if (!This) return E_OUTOFMEMORY;
628 This->IWshShortcut_iface.lpVtbl = &WshShortcutVtbl;
629 This->ref = 1;
631 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
632 &IID_IShellLinkW, (void**)&This->link);
633 if (FAILED(hr))
635 HeapFree(GetProcessHeap(), 0, This);
636 return hr;
639 This->path_link = SysAllocString(path);
640 if (!This->path_link)
642 IShellLinkW_Release(This->link);
643 HeapFree(GetProcessHeap(), 0, This);
644 return E_OUTOFMEMORY;
647 *shortcut = (IDispatch*)&This->IWshShortcut_iface;
649 return S_OK;
652 static HRESULT WINAPI WshShell3_QueryInterface(IWshShell3 *iface, REFIID riid, void **ppv)
654 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
656 *ppv = NULL;
658 if(IsEqualGUID(riid, &IID_IUnknown) ||
659 IsEqualGUID(riid, &IID_IDispatch) ||
660 IsEqualGUID(riid, &IID_IWshShell3))
662 *ppv = iface;
664 else if (IsEqualGUID(riid, &IID_IDispatchEx))
666 return E_NOINTERFACE;
668 else
670 FIXME("Unknown iface %s\n", debugstr_guid(riid));
671 return E_NOINTERFACE;
674 IWshShell3_AddRef(iface);
675 return S_OK;
678 static ULONG WINAPI WshShell3_AddRef(IWshShell3 *iface)
680 TRACE("()\n");
681 return 2;
684 static ULONG WINAPI WshShell3_Release(IWshShell3 *iface)
686 TRACE("()\n");
687 return 2;
690 static HRESULT WINAPI WshShell3_GetTypeInfoCount(IWshShell3 *iface, UINT *pctinfo)
692 TRACE("(%p)\n", pctinfo);
693 *pctinfo = 1;
694 return S_OK;
697 static HRESULT WINAPI WshShell3_GetTypeInfo(IWshShell3 *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
699 TRACE("(%u %u %p)\n", iTInfo, lcid, ppTInfo);
700 return get_typeinfo(IWshShell3_tid, ppTInfo);
703 static HRESULT WINAPI WshShell3_GetIDsOfNames(IWshShell3 *iface, REFIID riid, LPOLESTR *rgszNames,
704 UINT cNames, LCID lcid, DISPID *rgDispId)
706 ITypeInfo *typeinfo;
707 HRESULT hr;
709 TRACE("(%s %p %u %u %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
711 hr = get_typeinfo(IWshShell3_tid, &typeinfo);
712 if(SUCCEEDED(hr))
714 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
715 ITypeInfo_Release(typeinfo);
718 return hr;
721 static HRESULT WINAPI WshShell3_Invoke(IWshShell3 *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
722 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
724 ITypeInfo *typeinfo;
725 HRESULT hr;
727 TRACE("(%d %s %d %d %p %p %p %p)\n", dispIdMember, debugstr_guid(riid),
728 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
730 hr = get_typeinfo(IWshShell3_tid, &typeinfo);
731 if(SUCCEEDED(hr))
733 hr = ITypeInfo_Invoke(typeinfo, &WshShell3, dispIdMember, wFlags,
734 pDispParams, pVarResult, pExcepInfo, puArgErr);
735 ITypeInfo_Release(typeinfo);
738 return hr;
741 static HRESULT WINAPI WshShell3_get_SpecialFolders(IWshShell3 *iface, IWshCollection **folders)
743 TRACE("(%p)\n", folders);
744 return WshCollection_Create(folders);
747 static HRESULT WINAPI WshShell3_get_Environment(IWshShell3 *iface, VARIANT *Type, IWshEnvironment **out_Env)
749 FIXME("(%p %p): stub\n", Type, out_Env);
750 return E_NOTIMPL;
753 static HRESULT WINAPI WshShell3_Run(IWshShell3 *iface, BSTR cmd, VARIANT *style, VARIANT *WaitOnReturn, int *exit_code)
755 SHELLEXECUTEINFOW info;
756 int waitforprocess;
757 VARIANT s, w;
758 HRESULT hr;
760 TRACE("(%s %s %s %p)\n", debugstr_w(cmd), debugstr_variant(style), debugstr_variant(WaitOnReturn), exit_code);
762 VariantInit(&s);
763 hr = VariantChangeType(&s, style, 0, VT_I4);
764 if (FAILED(hr))
766 ERR("failed to convert style argument, 0x%08x\n", hr);
767 return hr;
770 VariantInit(&w);
771 hr = VariantChangeType(&w, WaitOnReturn, 0, VT_I4);
772 if (FAILED(hr))
774 ERR("failed to convert wait argument, 0x%08x\n", hr);
775 return hr;
778 memset(&info, 0, sizeof(info));
779 info.cbSize = sizeof(info);
781 waitforprocess = V_I4(&w);
783 info.fMask = waitforprocess ? SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS : SEE_MASK_DEFAULT;
784 info.lpFile = cmd;
785 info.nShow = V_I4(&s);
787 if (!ShellExecuteExW(&info))
789 TRACE("ShellExecute failed, %d\n", GetLastError());
790 return HRESULT_FROM_WIN32(GetLastError());
792 else
794 if (waitforprocess)
796 if (exit_code)
798 DWORD code;
799 GetExitCodeProcess(info.hProcess, &code);
800 *exit_code = code;
802 CloseHandle(info.hProcess);
804 else
805 if (exit_code) *exit_code = 0;
807 return S_OK;
811 static HRESULT WINAPI WshShell3_Popup(IWshShell3 *iface, BSTR Text, VARIANT* SecondsToWait, VARIANT *Title, VARIANT *Type, int *button)
813 FIXME("(%s %s %s %s %p): stub\n", debugstr_w(Text), debugstr_variant(SecondsToWait),
814 debugstr_variant(Title), debugstr_variant(Type), button);
815 return E_NOTIMPL;
818 static HRESULT WINAPI WshShell3_CreateShortcut(IWshShell3 *iface, BSTR PathLink, IDispatch** Shortcut)
820 TRACE("(%s %p)\n", debugstr_w(PathLink), Shortcut);
821 return WshShortcut_Create(PathLink, Shortcut);
824 static HRESULT WINAPI WshShell3_ExpandEnvironmentStrings(IWshShell3 *iface, BSTR Src, BSTR* Dst)
826 DWORD ret;
828 TRACE("(%s %p)\n", debugstr_w(Src), Dst);
830 if (!Src || !Dst) return E_POINTER;
832 ret = ExpandEnvironmentStringsW(Src, NULL, 0);
833 *Dst = SysAllocStringLen(NULL, ret);
834 if (!*Dst) return E_OUTOFMEMORY;
836 if (ExpandEnvironmentStringsW(Src, *Dst, ret))
837 return S_OK;
838 else
840 SysFreeString(*Dst);
841 *Dst = NULL;
842 return HRESULT_FROM_WIN32(GetLastError());
846 static HRESULT WINAPI WshShell3_RegRead(IWshShell3 *iface, BSTR Name, VARIANT* out_Value)
848 FIXME("(%s %p): stub\n", debugstr_w(Name), out_Value);
849 return E_NOTIMPL;
852 static HRESULT WINAPI WshShell3_RegWrite(IWshShell3 *iface, BSTR Name, VARIANT *Value, VARIANT *Type)
854 FIXME("(%s %s %s): stub\n", debugstr_w(Name), debugstr_variant(Value), debugstr_variant(Type));
855 return E_NOTIMPL;
858 static HRESULT WINAPI WshShell3_RegDelete(IWshShell3 *iface, BSTR Name)
860 FIXME("(%s): stub\n", debugstr_w(Name));
861 return E_NOTIMPL;
864 static HRESULT WINAPI WshShell3_LogEvent(IWshShell3 *iface, VARIANT *Type, BSTR Message, BSTR Target, VARIANT_BOOL *out_Success)
866 FIXME("(%s %s %s %p): stub\n", debugstr_variant(Type), debugstr_w(Message), debugstr_w(Target), out_Success);
867 return E_NOTIMPL;
870 static HRESULT WINAPI WshShell3_AppActivate(IWshShell3 *iface, VARIANT *App, VARIANT *Wait, VARIANT_BOOL *out_Success)
872 FIXME("(%s %s %p): stub\n", debugstr_variant(App), debugstr_variant(Wait), out_Success);
873 return E_NOTIMPL;
876 static HRESULT WINAPI WshShell3_SendKeys(IWshShell3 *iface, BSTR Keys, VARIANT *Wait)
878 FIXME("(%s %p): stub\n", debugstr_w(Keys), Wait);
879 return E_NOTIMPL;
882 static const IWshShell3Vtbl WshShell3Vtbl = {
883 WshShell3_QueryInterface,
884 WshShell3_AddRef,
885 WshShell3_Release,
886 WshShell3_GetTypeInfoCount,
887 WshShell3_GetTypeInfo,
888 WshShell3_GetIDsOfNames,
889 WshShell3_Invoke,
890 WshShell3_get_SpecialFolders,
891 WshShell3_get_Environment,
892 WshShell3_Run,
893 WshShell3_Popup,
894 WshShell3_CreateShortcut,
895 WshShell3_ExpandEnvironmentStrings,
896 WshShell3_RegRead,
897 WshShell3_RegWrite,
898 WshShell3_RegDelete,
899 WshShell3_LogEvent,
900 WshShell3_AppActivate,
901 WshShell3_SendKeys
904 static IWshShell3 WshShell3 = { &WshShell3Vtbl };
906 HRESULT WINAPI WshShellFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
908 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
910 return IWshShell3_QueryInterface(&WshShell3, riid, ppv);