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"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(wshom
);
29 const char *debugstr_variant(const VARIANT
*v
)
40 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v
));
42 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v
));
44 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v
)));
46 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v
));
48 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v
));
50 return wine_dbg_sprintf("{VT_UNKNOWN: %p}", V_UNKNOWN(v
));
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
));
57 return wine_dbg_sprintf("{vt %d}", V_VT(v
));
61 static IWshShell3 WshShell3
;
65 IWshCollection IWshCollection_iface
;
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
))
86 FIXME("Unknown iface %s\n", debugstr_guid(riid
));
91 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
110 HeapFree(GetProcessHeap(), 0, This
);
115 static HRESULT WINAPI
WshCollection_GetTypeInfoCount(IWshCollection
*iface
, UINT
*pctinfo
)
117 WshCollection
*This
= impl_from_IWshCollection(iface
);
118 TRACE("(%p)->(%p)\n", This
, pctinfo
);
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
);
137 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
139 hr
= get_typeinfo(IWshCollection_tid
, &typeinfo
);
142 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
143 ITypeInfo_Release(typeinfo
);
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
);
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
);
162 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IWshCollection_iface
, dispIdMember
, wFlags
,
163 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
164 ITypeInfo_Release(typeinfo
);
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
];
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
));
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
;
196 FIXME("folder kind %s not supported\n", debugstr_w(folder
));
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
;
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
);
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
);
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
);
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
,
248 WshCollection_get_length
,
249 WshCollection__NewEnum
252 static HRESULT
WshCollection_Create(IWshCollection
**collection
)
256 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
257 if (!This
) return E_OUTOFMEMORY
;
259 This
->IWshCollection_iface
.lpVtbl
= &WshCollectionVtbl
;
262 *collection
= &This
->IWshCollection_iface
;
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
))
277 FIXME("Unknown iface %s\n", debugstr_guid(riid
));
279 return E_NOINTERFACE
;
282 IWshShell3_AddRef(iface
);
286 static ULONG WINAPI
WshShell3_AddRef(IWshShell3
*iface
)
292 static ULONG WINAPI
WshShell3_Release(IWshShell3
*iface
)
298 static HRESULT WINAPI
WshShell3_GetTypeInfoCount(IWshShell3
*iface
, UINT
*pctinfo
)
300 TRACE("(%p)\n", pctinfo
);
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
)
317 TRACE("(%s %p %u %u %p)\n", debugstr_guid(riid
), rgszNames
, cNames
, lcid
, rgDispId
);
319 hr
= get_typeinfo(IWshShell3_tid
, &typeinfo
);
322 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
323 ITypeInfo_Release(typeinfo
);
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
)
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
);
341 hr
= ITypeInfo_Invoke(typeinfo
, &WshShell3
, dispIdMember
, wFlags
,
342 pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
343 ITypeInfo_Release(typeinfo
);
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
);
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
);
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
);
374 static HRESULT WINAPI
WshShell3_CreateShortcut(IWshShell3
*iface
, BSTR PathLink
, IDispatch
** out_Shortcut
)
376 FIXME("(%s %p): stub\n", debugstr_w(PathLink
), out_Shortcut
);
380 static HRESULT WINAPI
WshShell3_ExpandEnvironmentStrings(IWshShell3
*iface
, BSTR Src
, BSTR
* out_Dst
)
382 FIXME("(%s %p): stub\n", debugstr_w(Src
), out_Dst
);
386 static HRESULT WINAPI
WshShell3_RegRead(IWshShell3
*iface
, BSTR Name
, VARIANT
* out_Value
)
388 FIXME("(%s %p): stub\n", debugstr_w(Name
), out_Value
);
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
));
398 static HRESULT WINAPI
WshShell3_RegDelete(IWshShell3
*iface
, BSTR Name
)
400 FIXME("(%s): stub\n", debugstr_w(Name
));
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
);
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
);
416 static HRESULT WINAPI
WshShell3_SendKeys(IWshShell3
*iface
, BSTR Keys
, VARIANT
*Wait
)
418 FIXME("(%s %p): stub\n", debugstr_w(Keys
), Wait
);
422 static const IWshShell3Vtbl WshShell3Vtbl
= {
423 WshShell3_QueryInterface
,
426 WshShell3_GetTypeInfoCount
,
427 WshShell3_GetTypeInfo
,
428 WshShell3_GetIDsOfNames
,
430 WshShell3_get_SpecialFolders
,
431 WshShell3_get_Environment
,
434 WshShell3_CreateShortcut
,
435 WshShell3_ExpandEnvironmentStrings
,
440 WshShell3_AppActivate
,
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
);