wshom.ocx: Implement IWshCollection::Item() for public desktop case.
[wine/multimedia.git] / dlls / wshom.ocx / shell.c
blobbd5cb263f730350e105447a54d9af6858addc409
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 "shlobj.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(wshom);
29 const char *debugstr_variant(const VARIANT *v)
31 if(!v)
32 return "(null)";
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));
61 static IWshShell3 WshShell3;
63 typedef struct
65 IWshCollection IWshCollection_iface;
66 LONG ref;
67 } WshCollection;
69 static inline WshCollection *impl_from_IWshCollection( IWshCollection *iface )
71 return CONTAINING_RECORD(iface, WshCollection, IWshCollection_iface);
74 static HRESULT WINAPI WshCollection_QueryInterface(IWshCollection *iface, REFIID riid, void **ppv)
76 WshCollection *This = impl_from_IWshCollection(iface);
78 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
80 if (IsEqualGUID(riid, &IID_IUnknown) ||
81 IsEqualGUID(riid, &IID_IDispatch) ||
82 IsEqualGUID(riid, &IID_IWshCollection))
84 *ppv = iface;
85 }else {
86 FIXME("Unknown iface %s\n", debugstr_guid(riid));
87 *ppv = NULL;
88 return E_NOINTERFACE;
91 IUnknown_AddRef((IUnknown*)*ppv);
92 return S_OK;
95 static ULONG WINAPI WshCollection_AddRef(IWshCollection *iface)
97 WshCollection *This = impl_from_IWshCollection(iface);
98 LONG ref = InterlockedIncrement(&This->ref);
99 TRACE("(%p) ref = %d\n", This, ref);
100 return ref;
103 static ULONG WINAPI WshCollection_Release(IWshCollection *iface)
105 WshCollection *This = impl_from_IWshCollection(iface);
106 LONG ref = InterlockedDecrement(&This->ref);
107 TRACE("(%p) ref = %d\n", This, ref);
109 if (!ref)
110 HeapFree(GetProcessHeap(), 0, This);
112 return ref;
115 static HRESULT WINAPI WshCollection_GetTypeInfoCount(IWshCollection *iface, UINT *pctinfo)
117 WshCollection *This = impl_from_IWshCollection(iface);
118 TRACE("(%p)->(%p)\n", This, pctinfo);
119 *pctinfo = 1;
120 return S_OK;
123 static HRESULT WINAPI WshCollection_GetTypeInfo(IWshCollection *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
125 WshCollection *This = impl_from_IWshCollection(iface);
126 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
127 return get_typeinfo(IWshCollection_tid, ppTInfo);
130 static HRESULT WINAPI WshCollection_GetIDsOfNames(IWshCollection *iface, REFIID riid, LPOLESTR *rgszNames,
131 UINT cNames, LCID lcid, DISPID *rgDispId)
133 WshCollection *This = impl_from_IWshCollection(iface);
134 ITypeInfo *typeinfo;
135 HRESULT hr;
137 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
139 hr = get_typeinfo(IWshCollection_tid, &typeinfo);
140 if(SUCCEEDED(hr))
142 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
143 ITypeInfo_Release(typeinfo);
146 return hr;
149 static HRESULT WINAPI WshCollection_Invoke(IWshCollection *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
150 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
152 WshCollection *This = impl_from_IWshCollection(iface);
153 ITypeInfo *typeinfo;
154 HRESULT hr;
156 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
157 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
159 hr = get_typeinfo(IWshCollection_tid, &typeinfo);
160 if(SUCCEEDED(hr))
162 hr = ITypeInfo_Invoke(typeinfo, &This->IWshCollection_iface, dispIdMember, wFlags,
163 pDispParams, pVarResult, pExcepInfo, puArgErr);
164 ITypeInfo_Release(typeinfo);
167 return hr;
170 static HRESULT WINAPI WshCollection_Item(IWshCollection *iface, VARIANT *index, VARIANT *value)
172 WshCollection *This = impl_from_IWshCollection(iface);
173 static const WCHAR allusersdesktopW[] = {'A','l','l','U','s','e','r','s','D','e','s','k','t','o','p',0};
174 static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
175 PIDLIST_ABSOLUTE pidl;
176 WCHAR pathW[MAX_PATH];
177 int kind = 0;
178 BSTR folder;
179 HRESULT hr;
181 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(index), value);
183 if (V_VT(index) != VT_BSTR)
185 FIXME("only BSTR index supported, got %d\n", V_VT(index));
186 return E_NOTIMPL;
189 folder = V_BSTR(index);
190 if (!strcmpiW(folder, desktopW))
191 kind = CSIDL_DESKTOP;
192 else if (!strcmpiW(folder, allusersdesktopW))
193 kind = CSIDL_COMMON_DESKTOPDIRECTORY;
194 else
196 FIXME("folder kind %s not supported\n", debugstr_w(folder));
197 return E_NOTIMPL;
200 hr = SHGetSpecialFolderLocation(NULL, kind, &pidl);
201 if (hr != S_OK) return hr;
203 if (SHGetPathFromIDListW(pidl, pathW))
205 V_VT(value) = VT_BSTR;
206 V_BSTR(value) = SysAllocString(pathW);
207 hr = V_BSTR(value) ? S_OK : E_OUTOFMEMORY;
209 else
210 hr = E_FAIL;
212 CoTaskMemFree(pidl);
214 return hr;
217 static HRESULT WINAPI WshCollection_Count(IWshCollection *iface, LONG *count)
219 WshCollection *This = impl_from_IWshCollection(iface);
220 FIXME("(%p)->(%p): stub\n", This, count);
221 return E_NOTIMPL;
224 static HRESULT WINAPI WshCollection_get_length(IWshCollection *iface, LONG *count)
226 WshCollection *This = impl_from_IWshCollection(iface);
227 FIXME("(%p)->(%p): stub\n", This, count);
228 return E_NOTIMPL;
231 static HRESULT WINAPI WshCollection__NewEnum(IWshCollection *iface, IUnknown *Enum)
233 WshCollection *This = impl_from_IWshCollection(iface);
234 FIXME("(%p)->(%p): stub\n", This, Enum);
235 return E_NOTIMPL;
238 static const IWshCollectionVtbl WshCollectionVtbl = {
239 WshCollection_QueryInterface,
240 WshCollection_AddRef,
241 WshCollection_Release,
242 WshCollection_GetTypeInfoCount,
243 WshCollection_GetTypeInfo,
244 WshCollection_GetIDsOfNames,
245 WshCollection_Invoke,
246 WshCollection_Item,
247 WshCollection_Count,
248 WshCollection_get_length,
249 WshCollection__NewEnum
252 static HRESULT WshCollection_Create(IWshCollection **collection)
254 WshCollection *This;
256 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
257 if (!This) return E_OUTOFMEMORY;
259 This->IWshCollection_iface.lpVtbl = &WshCollectionVtbl;
260 This->ref = 1;
262 *collection = &This->IWshCollection_iface;
264 return S_OK;
267 static HRESULT WINAPI WshShell3_QueryInterface(IWshShell3 *iface, REFIID riid, void **ppv)
269 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
271 if(IsEqualGUID(riid, &IID_IUnknown) ||
272 IsEqualGUID(riid, &IID_IDispatch) ||
273 IsEqualGUID(riid, &IID_IWshShell3))
275 *ppv = iface;
276 }else {
277 FIXME("Unknown iface %s\n", debugstr_guid(riid));
278 *ppv = NULL;
279 return E_NOINTERFACE;
282 IWshShell3_AddRef(iface);
283 return S_OK;
286 static ULONG WINAPI WshShell3_AddRef(IWshShell3 *iface)
288 TRACE("()\n");
289 return 2;
292 static ULONG WINAPI WshShell3_Release(IWshShell3 *iface)
294 TRACE("()\n");
295 return 2;
298 static HRESULT WINAPI WshShell3_GetTypeInfoCount(IWshShell3 *iface, UINT *pctinfo)
300 TRACE("(%p)\n", pctinfo);
301 *pctinfo = 1;
302 return S_OK;
305 static HRESULT WINAPI WshShell3_GetTypeInfo(IWshShell3 *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
307 TRACE("(%u %u %p)\n", iTInfo, lcid, ppTInfo);
308 return get_typeinfo(IWshShell3_tid, ppTInfo);
311 static HRESULT WINAPI WshShell3_GetIDsOfNames(IWshShell3 *iface, REFIID riid, LPOLESTR *rgszNames,
312 UINT cNames, LCID lcid, DISPID *rgDispId)
314 ITypeInfo *typeinfo;
315 HRESULT hr;
317 TRACE("(%s %p %u %u %p)\n", debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
319 hr = get_typeinfo(IWshShell3_tid, &typeinfo);
320 if(SUCCEEDED(hr))
322 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
323 ITypeInfo_Release(typeinfo);
326 return hr;
329 static HRESULT WINAPI WshShell3_Invoke(IWshShell3 *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
330 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
332 ITypeInfo *typeinfo;
333 HRESULT hr;
335 TRACE("(%d %s %d %d %p %p %p %p)\n", dispIdMember, debugstr_guid(riid),
336 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
338 hr = get_typeinfo(IWshShell3_tid, &typeinfo);
339 if(SUCCEEDED(hr))
341 hr = ITypeInfo_Invoke(typeinfo, &WshShell3, dispIdMember, wFlags,
342 pDispParams, pVarResult, pExcepInfo, puArgErr);
343 ITypeInfo_Release(typeinfo);
346 return hr;
349 static HRESULT WINAPI WshShell3_get_SpecialFolders(IWshShell3 *iface, IWshCollection **folders)
351 TRACE("(%p)\n", folders);
352 return WshCollection_Create(folders);
355 static HRESULT WINAPI WshShell3_get_Environment(IWshShell3 *iface, VARIANT *Type, IWshEnvironment **out_Env)
357 FIXME("(%p %p): stub\n", Type, out_Env);
358 return E_NOTIMPL;
361 static HRESULT WINAPI WshShell3_Run(IWshShell3 *iface, BSTR Command, VARIANT *WindowStyle, VARIANT *WaitOnReturn, int *out_ExitCode)
363 FIXME("(%s %s %p): stub\n", debugstr_variant(WindowStyle), debugstr_variant(WaitOnReturn), out_ExitCode);
364 return E_NOTIMPL;
367 static HRESULT WINAPI WshShell3_Popup(IWshShell3 *iface, BSTR Text, VARIANT* SecondsToWait, VARIANT *Title, VARIANT *Type, int *button)
369 FIXME("(%s %s %s %s %p): stub\n", debugstr_w(Text), debugstr_variant(SecondsToWait),
370 debugstr_variant(Title), debugstr_variant(Type), button);
371 return E_NOTIMPL;
374 static HRESULT WINAPI WshShell3_CreateShortcut(IWshShell3 *iface, BSTR PathLink, IDispatch** out_Shortcut)
376 FIXME("(%s %p): stub\n", debugstr_w(PathLink), out_Shortcut);
377 return E_NOTIMPL;
380 static HRESULT WINAPI WshShell3_ExpandEnvironmentStrings(IWshShell3 *iface, BSTR Src, BSTR* out_Dst)
382 FIXME("(%s %p): stub\n", debugstr_w(Src), out_Dst);
383 return E_NOTIMPL;
386 static HRESULT WINAPI WshShell3_RegRead(IWshShell3 *iface, BSTR Name, VARIANT* out_Value)
388 FIXME("(%s %p): stub\n", debugstr_w(Name), out_Value);
389 return E_NOTIMPL;
392 static HRESULT WINAPI WshShell3_RegWrite(IWshShell3 *iface, BSTR Name, VARIANT *Value, VARIANT *Type)
394 FIXME("(%s %s %s): stub\n", debugstr_w(Name), debugstr_variant(Value), debugstr_variant(Type));
395 return E_NOTIMPL;
398 static HRESULT WINAPI WshShell3_RegDelete(IWshShell3 *iface, BSTR Name)
400 FIXME("(%s): stub\n", debugstr_w(Name));
401 return E_NOTIMPL;
404 static HRESULT WINAPI WshShell3_LogEvent(IWshShell3 *iface, VARIANT *Type, BSTR Message, BSTR Target, VARIANT_BOOL *out_Success)
406 FIXME("(%s %s %s %p): stub\n", debugstr_variant(Type), debugstr_w(Message), debugstr_w(Target), out_Success);
407 return E_NOTIMPL;
410 static HRESULT WINAPI WshShell3_AppActivate(IWshShell3 *iface, VARIANT *App, VARIANT *Wait, VARIANT_BOOL *out_Success)
412 FIXME("(%s %s %p): stub\n", debugstr_variant(App), debugstr_variant(Wait), out_Success);
413 return E_NOTIMPL;
416 static HRESULT WINAPI WshShell3_SendKeys(IWshShell3 *iface, BSTR Keys, VARIANT *Wait)
418 FIXME("(%s %p): stub\n", debugstr_w(Keys), Wait);
419 return E_NOTIMPL;
422 static const IWshShell3Vtbl WshShell3Vtbl = {
423 WshShell3_QueryInterface,
424 WshShell3_AddRef,
425 WshShell3_Release,
426 WshShell3_GetTypeInfoCount,
427 WshShell3_GetTypeInfo,
428 WshShell3_GetIDsOfNames,
429 WshShell3_Invoke,
430 WshShell3_get_SpecialFolders,
431 WshShell3_get_Environment,
432 WshShell3_Run,
433 WshShell3_Popup,
434 WshShell3_CreateShortcut,
435 WshShell3_ExpandEnvironmentStrings,
436 WshShell3_RegRead,
437 WshShell3_RegWrite,
438 WshShell3_RegDelete,
439 WshShell3_LogEvent,
440 WshShell3_AppActivate,
441 WshShell3_SendKeys
444 static IWshShell3 WshShell3 = { &WshShell3Vtbl };
446 HRESULT WINAPI WshShellFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
448 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
450 return IWshShell3_QueryInterface(&WshShell3, riid, ppv);