netstat: Initial implementation.
[wine] / dlls / wshom.ocx / shell.c
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "wshom_private.h"
20 #include "wshom.h"
21
22 #include "shlobj.h"
23
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(wshom);
28
29 static const char *debugstr_variant(const VARIANT *v)
30 {
31     if(!v)
32         return "(null)";
33
34     switch(V_VT(v)) {
35     case VT_EMPTY:
36         return "{VT_EMPTY}";
37     case VT_NULL:
38         return "{VT_NULL}";
39     case VT_I4:
40         return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
41     case VT_R8:
42         return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
43     case VT_BSTR:
44         return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
45     case VT_DISPATCH:
46         return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
47     case VT_BOOL:
48         return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
49     case VT_UNKNOWN:
50         return wine_dbg_sprintf("{VT_UNKNOWN: %p}", V_UNKNOWN(v));
51     case VT_UINT:
52         return wine_dbg_sprintf("{VT_UINT: %u}", V_UINT(v));
53     case VT_BSTR|VT_BYREF:
54         return wine_dbg_sprintf("{VT_BSTR|VT_BYREF: ptr %p, data %s}",
55             V_BSTRREF(v), debugstr_w(V_BSTRREF(v) ? *V_BSTRREF(v) : NULL));
56     default:
57         return wine_dbg_sprintf("{vt %d}", V_VT(v));
58     }
59 }
60
61 static IWshShell3 WshShell3;
62
63 typedef struct
64 {
65     IWshCollection IWshCollection_iface;
66     LONG ref;
67 } WshCollection;
68
69 typedef struct
70 {
71     IWshShortcut IWshShortcut_iface;
72     LONG ref;
73
74     IShellLinkW *link;
75     BSTR path_link;
76 } WshShortcut;
77
78 static inline WshCollection *impl_from_IWshCollection( IWshCollection *iface )
79 {
80     return CONTAINING_RECORD(iface, WshCollection, IWshCollection_iface);
81 }
82
83 static inline WshShortcut *impl_from_IWshShortcut( IWshShortcut *iface )
84 {
85     return CONTAINING_RECORD(iface, WshShortcut, IWshShortcut_iface);
86 }
87
88 static HRESULT WINAPI WshCollection_QueryInterface(IWshCollection *iface, REFIID riid, void **ppv)
89 {
90     WshCollection *This = impl_from_IWshCollection(iface);
91
92     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
93
94     if (IsEqualGUID(riid, &IID_IUnknown)  ||
95         IsEqualGUID(riid, &IID_IDispatch) ||
96         IsEqualGUID(riid, &IID_IWshCollection))
97     {
98         *ppv = iface;
99     }else {
100         FIXME("Unknown iface %s\n", debugstr_guid(riid));
101         *ppv = NULL;
102         return E_NOINTERFACE;
103     }
104
105     IUnknown_AddRef((IUnknown*)*ppv);
106     return S_OK;
107 }
108
109 static ULONG WINAPI WshCollection_AddRef(IWshCollection *iface)
110 {
111     WshCollection *This = impl_from_IWshCollection(iface);
112     LONG ref = InterlockedIncrement(&This->ref);
113     TRACE("(%p) ref = %d\n", This, ref);
114     return ref;
115 }
116
117 static ULONG WINAPI WshCollection_Release(IWshCollection *iface)
118 {
119     WshCollection *This = impl_from_IWshCollection(iface);
120     LONG ref = InterlockedDecrement(&This->ref);
121     TRACE("(%p) ref = %d\n", This, ref);
122
123     if (!ref)
124         HeapFree(GetProcessHeap(), 0, This);
125
126     return ref;
127 }
128
129 static HRESULT WINAPI WshCollection_GetTypeInfoCount(IWshCollection *iface, UINT *pctinfo)
130 {
131     WshCollection *This = impl_from_IWshCollection(iface);
132     TRACE("(%p)->(%p)\n", This, pctinfo);
133     *pctinfo = 1;
134     return S_OK;
135 }
136
137 static HRESULT WINAPI WshCollection_GetTypeInfo(IWshCollection *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
138 {
139     WshCollection *This = impl_from_IWshCollection(iface);
140     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
141     return get_typeinfo(IWshCollection_tid, ppTInfo);
142 }
143
144 static HRESULT WINAPI WshCollection_GetIDsOfNames(IWshCollection *iface, REFIID riid, LPOLESTR *rgszNames,
145         UINT cNames, LCID lcid, DISPID *rgDispId)
146 {
147     WshCollection *This = impl_from_IWshCollection(iface);
148     ITypeInfo *typeinfo;
149     HRESULT hr;
150
151     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
152
153     hr = get_typeinfo(IWshCollection_tid, &typeinfo);
154     if(SUCCEEDED(hr))
155     {
156         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
157         ITypeInfo_Release(typeinfo);
158     }
159
160     return hr;
161 }
162
163 static HRESULT WINAPI WshCollection_Invoke(IWshCollection *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
164         WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
165 {
166     WshCollection *This = impl_from_IWshCollection(iface);
167     ITypeInfo *typeinfo;
168     HRESULT hr;
169
170     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
171           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
172
173     hr = get_typeinfo(IWshCollection_tid, &typeinfo);
174     if(SUCCEEDED(hr))
175     {
176         hr = ITypeInfo_Invoke(typeinfo, &This->IWshCollection_iface, dispIdMember, wFlags,
177                 pDispParams, pVarResult, pExcepInfo, puArgErr);
178         ITypeInfo_Release(typeinfo);
179     }
180
181     return hr;
182 }
183
184 static HRESULT WINAPI WshCollection_Item(IWshCollection *iface, VARIANT *index, VARIANT *value)
185 {
186     WshCollection *This = impl_from_IWshCollection(iface);
187     static const WCHAR allusersdesktopW[] = {'A','l','l','U','s','e','r','s','D','e','s','k','t','o','p',0};
188     static const WCHAR allusersprogramsW[] = {'A','l','l','U','s','e','r','s','P','r','o','g','r','a','m','s',0};
189     static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
190     PIDLIST_ABSOLUTE pidl;
191     WCHAR pathW[MAX_PATH];
192     int kind = 0;
193     BSTR folder;
194     HRESULT hr;
195
196     TRACE("(%p)->(%s %p)\n", This, debugstr_variant(index), value);
197
198     if (V_VT(index) != VT_BSTR)
199     {
200         FIXME("only BSTR index supported, got %d\n", V_VT(index));
201         return E_NOTIMPL;
202     }
203
204     folder = V_BSTR(index);
205     if (!strcmpiW(folder, desktopW))
206         kind = CSIDL_DESKTOP;
207     else if (!strcmpiW(folder, allusersdesktopW))
208         kind = CSIDL_COMMON_DESKTOPDIRECTORY;
209     else if (!strcmpiW(folder, allusersprogramsW))
210         kind = CSIDL_COMMON_PROGRAMS;
211     else
212     {
213         FIXME("folder kind %s not supported\n", debugstr_w(folder));
214         return E_NOTIMPL;
215     }
216
217     hr = SHGetSpecialFolderLocation(NULL, kind, &pidl);
218     if (hr != S_OK) return hr;
219
220     if (SHGetPathFromIDListW(pidl, pathW))
221     {
222         V_VT(value) = VT_BSTR;
223         V_BSTR(value) = SysAllocString(pathW);
224         hr = V_BSTR(value) ? S_OK : E_OUTOFMEMORY;
225     }
226     else
227         hr = E_FAIL;
228
229     CoTaskMemFree(pidl);
230
231     return hr;
232 }
233
234 static HRESULT WINAPI WshCollection_Count(IWshCollection *iface, LONG *count)
235 {
236     WshCollection *This = impl_from_IWshCollection(iface);
237     FIXME("(%p)->(%p): stub\n", This, count);
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI WshCollection_get_length(IWshCollection *iface, LONG *count)
242 {
243     WshCollection *This = impl_from_IWshCollection(iface);
244     FIXME("(%p)->(%p): stub\n", This, count);
245     return E_NOTIMPL;
246 }
247
248 static HRESULT WINAPI WshCollection__NewEnum(IWshCollection *iface, IUnknown *Enum)
249 {
250     WshCollection *This = impl_from_IWshCollection(iface);
251     FIXME("(%p)->(%p): stub\n", This, Enum);
252     return E_NOTIMPL;
253 }
254
255 static const IWshCollectionVtbl WshCollectionVtbl = {
256     WshCollection_QueryInterface,
257     WshCollection_AddRef,
258     WshCollection_Release,
259     WshCollection_GetTypeInfoCount,
260     WshCollection_GetTypeInfo,
261     WshCollection_GetIDsOfNames,
262     WshCollection_Invoke,
263     WshCollection_Item,
264     WshCollection_Count,
265     WshCollection_get_length,
266     WshCollection__NewEnum
267 };
268
269 static HRESULT WshCollection_Create(IWshCollection **collection)
270 {
271     WshCollection *This;
272
273     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
274     if (!This) return E_OUTOFMEMORY;
275
276     This->IWshCollection_iface.lpVtbl = &WshCollectionVtbl;
277     This->ref = 1;
278
279     *collection = &This->IWshCollection_iface;
280
281     return S_OK;
282 }
283
284 /* IWshShortcut */
285 static HRESULT WINAPI WshShortcut_QueryInterface(IWshShortcut *iface, REFIID riid, void **ppv)
286 {
287     WshShortcut *This = impl_from_IWshShortcut(iface);
288
289     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
290
291     if (IsEqualGUID(riid, &IID_IUnknown)  ||
292         IsEqualGUID(riid, &IID_IDispatch) ||
293         IsEqualGUID(riid, &IID_IWshShortcut))
294     {
295         *ppv = iface;
296     }else {
297         FIXME("Unknown iface %s\n", debugstr_guid(riid));
298         *ppv = NULL;
299         return E_NOINTERFACE;
300     }
301
302     IUnknown_AddRef((IUnknown*)*ppv);
303     return S_OK;
304 }
305
306 static ULONG WINAPI WshShortcut_AddRef(IWshShortcut *iface)
307 {
308     WshShortcut *This = impl_from_IWshShortcut(iface);
309     LONG ref = InterlockedIncrement(&This->ref);
310     TRACE("(%p) ref = %d\n", This, ref);
311     return ref;
312 }
313
314 static ULONG WINAPI WshShortcut_Release(IWshShortcut *iface)
315 {
316     WshShortcut *This = impl_from_IWshShortcut(iface);
317     LONG ref = InterlockedDecrement(&This->ref);
318     TRACE("(%p) ref = %d\n", This, ref);
319
320     if (!ref)
321     {
322         SysFreeString(This->path_link);
323         IShellLinkW_Release(This->link);
324         HeapFree(GetProcessHeap(), 0, This);
325     }
326
327     return ref;
328 }
329
330 static HRESULT WINAPI WshShortcut_GetTypeInfoCount(IWshShortcut *iface, UINT *pctinfo)
331 {
332     WshShortcut *This = impl_from_IWshShortcut(iface);
333     TRACE("(%p)->(%p)\n", This, pctinfo);
334     *pctinfo = 1;
335     return S_OK;
336 }
337
338 static HRESULT WINAPI WshShortcut_GetTypeInfo(IWshShortcut *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
339 {
340     WshShortcut *This = impl_from_IWshShortcut(iface);
341     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
342     return get_typeinfo(IWshShortcut_tid, ppTInfo);
343 }
344
345 static HRESULT WINAPI WshShortcut_GetIDsOfNames(IWshShortcut *iface, REFIID riid, LPOLESTR *rgszNames,
346         UINT cNames, LCID lcid, DISPID *rgDispId)
347 {
348     WshShortcut *This = impl_from_IWshShortcut(iface);
349     ITypeInfo *typeinfo;
350     HRESULT hr;
351
352     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
353
354     hr = get_typeinfo(IWshShortcut_tid, &typeinfo);
355     if(SUCCEEDED(hr))
356     {
357         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
358         ITypeInfo_Release(typeinfo);
359     }
360
361     return hr;
362 }
363
364 static HRESULT WINAPI WshShortcut_Invoke(IWshShortcut *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
365         WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
366 {
367     WshShortcut *This = impl_from_IWshShortcut(iface);
368     ITypeInfo *typeinfo;
369     HRESULT hr;
370
371     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
372           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
373
374     hr = get_typeinfo(IWshShortcut_tid, &typeinfo);
375     if(SUCCEEDED(hr))
376     {
377         hr = ITypeInfo_Invoke(typeinfo, &This->IWshShortcut_iface, dispIdMember, wFlags,
378                 pDispParams, pVarResult, pExcepInfo, puArgErr);
379         ITypeInfo_Release(typeinfo);
380     }
381
382     return hr;
383 }
384
385 static HRESULT WINAPI WshShortcut_get_FullName(IWshShortcut *iface, BSTR *name)
386 {
387     WshShortcut *This = impl_from_IWshShortcut(iface);
388     FIXME("(%p)->(%p): stub\n", This, name);
389     return E_NOTIMPL;
390 }
391
392 static HRESULT WINAPI WshShortcut_get_Arguments(IWshShortcut *iface, BSTR *Arguments)
393 {
394     WshShortcut *This = impl_from_IWshShortcut(iface);
395     FIXME("(%p)->(%p): stub\n", This, Arguments);
396     return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI WshShortcut_put_Arguments(IWshShortcut *iface, BSTR Arguments)
400 {
401     WshShortcut *This = impl_from_IWshShortcut(iface);
402     FIXME("(%p)->(%s): stub\n", This, debugstr_w(Arguments));
403     return E_NOTIMPL;
404 }
405
406 static HRESULT WINAPI WshShortcut_get_Description(IWshShortcut *iface, BSTR *Description)
407 {
408     WshShortcut *This = impl_from_IWshShortcut(iface);
409     FIXME("(%p)->(%p): stub\n", This, Description);
410     return E_NOTIMPL;
411 }
412
413 static HRESULT WINAPI WshShortcut_put_Description(IWshShortcut *iface, BSTR Description)
414 {
415     WshShortcut *This = impl_from_IWshShortcut(iface);
416     TRACE("(%p)->(%s)\n", This, debugstr_w(Description));
417     return IShellLinkW_SetDescription(This->link, Description);
418 }
419
420 static HRESULT WINAPI WshShortcut_get_Hotkey(IWshShortcut *iface, BSTR *Hotkey)
421 {
422     WshShortcut *This = impl_from_IWshShortcut(iface);
423     FIXME("(%p)->(%p): stub\n", This, Hotkey);
424     return E_NOTIMPL;
425 }
426
427 static HRESULT WINAPI WshShortcut_put_Hotkey(IWshShortcut *iface, BSTR Hotkey)
428 {
429     WshShortcut *This = impl_from_IWshShortcut(iface);
430     FIXME("(%p)->(%s): stub\n", This, debugstr_w(Hotkey));
431     return E_NOTIMPL;
432 }
433
434 static HRESULT WINAPI WshShortcut_get_IconLocation(IWshShortcut *iface, BSTR *IconPath)
435 {
436     WshShortcut *This = impl_from_IWshShortcut(iface);
437     FIXME("(%p)->(%p): stub\n", This, IconPath);
438     return E_NOTIMPL;
439 }
440
441 static HRESULT WINAPI WshShortcut_put_IconLocation(IWshShortcut *iface, BSTR IconPath)
442 {
443     WshShortcut *This = impl_from_IWshShortcut(iface);
444     FIXME("(%p)->(%s): stub\n", This, debugstr_w(IconPath));
445     return E_NOTIMPL;
446 }
447
448 static HRESULT WINAPI WshShortcut_put_RelativePath(IWshShortcut *iface, BSTR rhs)
449 {
450     WshShortcut *This = impl_from_IWshShortcut(iface);
451     FIXME("(%p)->(%s): stub\n", This, debugstr_w(rhs));
452     return E_NOTIMPL;
453 }
454
455 static HRESULT WINAPI WshShortcut_get_TargetPath(IWshShortcut *iface, BSTR *Path)
456 {
457     WshShortcut *This = impl_from_IWshShortcut(iface);
458     FIXME("(%p)->(%p): stub\n", This, Path);
459     return E_NOTIMPL;
460 }
461
462 static HRESULT WINAPI WshShortcut_put_TargetPath(IWshShortcut *iface, BSTR Path)
463 {
464     WshShortcut *This = impl_from_IWshShortcut(iface);
465     TRACE("(%p)->(%s)\n", This, debugstr_w(Path));
466     return IShellLinkW_SetPath(This->link, Path);
467 }
468
469 static HRESULT WINAPI WshShortcut_get_WindowStyle(IWshShortcut *iface, int *ShowCmd)
470 {
471     WshShortcut *This = impl_from_IWshShortcut(iface);
472     TRACE("(%p)->(%p)\n", This, ShowCmd);
473     return IShellLinkW_GetShowCmd(This->link, ShowCmd);
474 }
475
476 static HRESULT WINAPI WshShortcut_put_WindowStyle(IWshShortcut *iface, int ShowCmd)
477 {
478     WshShortcut *This = impl_from_IWshShortcut(iface);
479     TRACE("(%p)->(%d)\n", This, ShowCmd);
480     return IShellLinkW_SetShowCmd(This->link, ShowCmd);
481 }
482
483 static HRESULT WINAPI WshShortcut_get_WorkingDirectory(IWshShortcut *iface, BSTR *WorkingDirectory)
484 {
485     WshShortcut *This = impl_from_IWshShortcut(iface);
486     FIXME("(%p)->(%p): stub\n", This, WorkingDirectory);
487     return E_NOTIMPL;
488 }
489
490 static HRESULT WINAPI WshShortcut_put_WorkingDirectory(IWshShortcut *iface, BSTR WorkingDirectory)
491 {
492     WshShortcut *This = impl_from_IWshShortcut(iface);
493     TRACE("(%p)->(%s): stub\n", This, debugstr_w(WorkingDirectory));
494     return IShellLinkW_SetWorkingDirectory(This->link, WorkingDirectory);
495 }
496
497 static HRESULT WINAPI WshShortcut_Load(IWshShortcut *iface, BSTR PathLink)
498 {
499     WshShortcut *This = impl_from_IWshShortcut(iface);
500     FIXME("(%p)->(%s): stub\n", This, debugstr_w(PathLink));
501     return E_NOTIMPL;
502 }
503
504 static HRESULT WINAPI WshShortcut_Save(IWshShortcut *iface)
505 {
506     WshShortcut *This = impl_from_IWshShortcut(iface);
507     IPersistFile *file;
508     HRESULT hr;
509
510     TRACE("(%p)\n", This);
511
512     IShellLinkW_QueryInterface(This->link, &IID_IPersistFile, (void**)&file);
513     hr = IPersistFile_Save(file, This->path_link, TRUE);
514     IPersistFile_Release(file);
515
516     return hr;
517 }
518
519 static const IWshShortcutVtbl WshShortcutVtbl = {
520     WshShortcut_QueryInterface,
521     WshShortcut_AddRef,
522     WshShortcut_Release,
523     WshShortcut_GetTypeInfoCount,
524     WshShortcut_GetTypeInfo,
525     WshShortcut_GetIDsOfNames,
526     WshShortcut_Invoke,
527     WshShortcut_get_FullName,
528     WshShortcut_get_Arguments,
529     WshShortcut_put_Arguments,
530     WshShortcut_get_Description,
531     WshShortcut_put_Description,
532     WshShortcut_get_Hotkey,
533     WshShortcut_put_Hotkey,
534     WshShortcut_get_IconLocation,
535     WshShortcut_put_IconLocation,
536     WshShortcut_put_RelativePath,
537     WshShortcut_get_TargetPath,
538     WshShortcut_put_TargetPath,
539     WshShortcut_get_WindowStyle,
540     WshShortcut_put_WindowStyle,
541     WshShortcut_get_WorkingDirectory,
542     WshShortcut_put_WorkingDirectory,
543     WshShortcut_Load,
544     WshShortcut_Save
545 };
546
547 static HRESULT WshShortcut_Create(const WCHAR *path, IDispatch **shortcut)
548 {
549     WshShortcut *This;
550     HRESULT hr;
551
552     *shortcut = NULL;
553
554     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
555     if (!This) return E_OUTOFMEMORY;
556
557     This->IWshShortcut_iface.lpVtbl = &WshShortcutVtbl;
558     This->ref = 1;
559
560     hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
561             &IID_IShellLinkW, (void**)&This->link);
562     if (FAILED(hr))
563     {
564         HeapFree(GetProcessHeap(), 0, This);
565         return hr;
566     }
567
568     This->path_link = SysAllocString(path);
569     *shortcut = (IDispatch*)&This->IWshShortcut_iface;
570
571     return S_OK;
572 }
573
574 static HRESULT WINAPI WshShell3_QueryInterface(IWshShell3 *iface, REFIID riid, void **ppv)
575 {
576     TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
577
578     if(IsEqualGUID(riid, &IID_IUnknown)  ||
579        IsEqualGUID(riid, &IID_IDispatch) ||
580        IsEqualGUID(riid, &IID_IWshShell3))
581     {
582         *ppv = iface;
583     }else {
584         FIXME("Unknown iface %s\n", debugstr_guid(riid));
585         *ppv = NULL;
586         return E_NOINTERFACE;
587     }
588
589     IWshShell3_AddRef(iface);
590     return S_OK;
591 }
592
593 static ULONG WINAPI WshShell3_AddRef(IWshShell3 *iface)
594 {
595     TRACE("()\n");
596     return 2;
597 }
598
599 static ULONG WINAPI WshShell3_Release(IWshShell3 *iface)
600 {
601     TRACE("()\n");
602     return 2;
603 }
604
605 static HRESULT WINAPI WshShell3_GetTypeInfoCount(IWshShell3 *iface, UINT *pctinfo)
606 {
607     TRACE("(%p)\n", pctinfo);
608     *pctinfo = 1;
609     return S_OK;
610 }
611
612 static HRESULT WINAPI WshShell3_GetTypeInfo(IWshShell3 *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
613 {
614     TRACE("(%u %u %p)\n", iTInfo, lcid, ppTInfo);
615     return get_typeinfo(IWshShell3_tid, ppTInfo);
616 }
617
618 static HRESULT WINAPI WshShell3_GetIDsOfNames(IWshShell3 *iface, REFIID riid, LPOLESTR *rgszNames,
619         UINT cNames, LCID lcid, DISPID *rgDispId)
620 {
621     ITypeInfo *typeinfo;
622     HRESULT hr;
623
624     TRACE("(%s %p %u %u %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
625
626     hr = get_typeinfo(IWshShell3_tid, &typeinfo);
627     if(SUCCEEDED(hr))
628     {
629         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
630         ITypeInfo_Release(typeinfo);
631     }
632
633     return hr;
634 }
635
636 static HRESULT WINAPI WshShell3_Invoke(IWshShell3 *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
637         WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
638 {
639     ITypeInfo *typeinfo;
640     HRESULT hr;
641
642     TRACE("(%d %s %d %d %p %p %p %p)\n", dispIdMember, debugstr_guid(riid),
643           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
644
645     hr = get_typeinfo(IWshShell3_tid, &typeinfo);
646     if(SUCCEEDED(hr))
647     {
648         hr = ITypeInfo_Invoke(typeinfo, &WshShell3, dispIdMember, wFlags,
649                 pDispParams, pVarResult, pExcepInfo, puArgErr);
650         ITypeInfo_Release(typeinfo);
651     }
652
653     return hr;
654 }
655
656 static HRESULT WINAPI WshShell3_get_SpecialFolders(IWshShell3 *iface, IWshCollection **folders)
657 {
658     TRACE("(%p)\n", folders);
659     return WshCollection_Create(folders);
660 }
661
662 static HRESULT WINAPI WshShell3_get_Environment(IWshShell3 *iface, VARIANT *Type, IWshEnvironment **out_Env)
663 {
664     FIXME("(%p %p): stub\n", Type, out_Env);
665     return E_NOTIMPL;
666 }
667
668 static HRESULT WINAPI WshShell3_Run(IWshShell3 *iface, BSTR Command, VARIANT *WindowStyle, VARIANT *WaitOnReturn, int *out_ExitCode)
669 {
670     FIXME("(%s %s %p): stub\n", debugstr_variant(WindowStyle), debugstr_variant(WaitOnReturn), out_ExitCode);
671     return E_NOTIMPL;
672 }
673
674 static HRESULT WINAPI WshShell3_Popup(IWshShell3 *iface, BSTR Text, VARIANT* SecondsToWait, VARIANT *Title, VARIANT *Type, int *button)
675 {
676     FIXME("(%s %s %s %s %p): stub\n", debugstr_w(Text), debugstr_variant(SecondsToWait),
677         debugstr_variant(Title), debugstr_variant(Type), button);
678     return E_NOTIMPL;
679 }
680
681 static HRESULT WINAPI WshShell3_CreateShortcut(IWshShell3 *iface, BSTR PathLink, IDispatch** Shortcut)
682 {
683     TRACE("(%s %p)\n", debugstr_w(PathLink), Shortcut);
684     return WshShortcut_Create(PathLink, Shortcut);
685 }
686
687 static HRESULT WINAPI WshShell3_ExpandEnvironmentStrings(IWshShell3 *iface, BSTR Src, BSTR* out_Dst)
688 {
689     FIXME("(%s %p): stub\n", debugstr_w(Src), out_Dst);
690     return E_NOTIMPL;
691 }
692
693 static HRESULT WINAPI WshShell3_RegRead(IWshShell3 *iface, BSTR Name, VARIANT* out_Value)
694 {
695     FIXME("(%s %p): stub\n", debugstr_w(Name), out_Value);
696     return E_NOTIMPL;
697 }
698
699 static HRESULT WINAPI WshShell3_RegWrite(IWshShell3 *iface, BSTR Name, VARIANT *Value, VARIANT *Type)
700 {
701     FIXME("(%s %s %s): stub\n", debugstr_w(Name), debugstr_variant(Value), debugstr_variant(Type));
702     return E_NOTIMPL;
703 }
704
705 static HRESULT WINAPI WshShell3_RegDelete(IWshShell3 *iface, BSTR Name)
706 {
707     FIXME("(%s): stub\n", debugstr_w(Name));
708     return E_NOTIMPL;
709 }
710
711 static HRESULT WINAPI WshShell3_LogEvent(IWshShell3 *iface, VARIANT *Type, BSTR Message, BSTR Target, VARIANT_BOOL *out_Success)
712 {
713     FIXME("(%s %s %s %p): stub\n", debugstr_variant(Type), debugstr_w(Message), debugstr_w(Target), out_Success);
714     return E_NOTIMPL;
715 }
716
717 static HRESULT WINAPI WshShell3_AppActivate(IWshShell3 *iface, VARIANT *App, VARIANT *Wait, VARIANT_BOOL *out_Success)
718 {
719     FIXME("(%s %s %p): stub\n", debugstr_variant(App), debugstr_variant(Wait), out_Success);
720     return E_NOTIMPL;
721 }
722
723 static HRESULT WINAPI WshShell3_SendKeys(IWshShell3 *iface, BSTR Keys, VARIANT *Wait)
724 {
725     FIXME("(%s %p): stub\n", debugstr_w(Keys), Wait);
726     return E_NOTIMPL;
727 }
728
729 static const IWshShell3Vtbl WshShell3Vtbl = {
730     WshShell3_QueryInterface,
731     WshShell3_AddRef,
732     WshShell3_Release,
733     WshShell3_GetTypeInfoCount,
734     WshShell3_GetTypeInfo,
735     WshShell3_GetIDsOfNames,
736     WshShell3_Invoke,
737     WshShell3_get_SpecialFolders,
738     WshShell3_get_Environment,
739     WshShell3_Run,
740     WshShell3_Popup,
741     WshShell3_CreateShortcut,
742     WshShell3_ExpandEnvironmentStrings,
743     WshShell3_RegRead,
744     WshShell3_RegWrite,
745     WshShell3_RegDelete,
746     WshShell3_LogEvent,
747     WshShell3_AppActivate,
748     WshShell3_SendKeys
749 };
750
751 static IWshShell3 WshShell3 = { &WshShell3Vtbl };
752
753 HRESULT WINAPI WshShellFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
754 {
755     TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
756
757     return IWshShell3_QueryInterface(&WshShell3, riid, ppv);
758 }