Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / programs / wscript / host.c
blobb7b94a25e537d49871de0333a4cc6380e6caf0c2
1 /*
2 * Copyright 2010 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 <stdarg.h>
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <windef.h>
25 #include <winbase.h>
26 #include <ole2.h>
28 #include "wscript.h"
30 #include <wine/debug.h>
31 #include <wine/unicode.h>
33 #define BUILDVERSION 16535
35 static const WCHAR wshNameW[] = {'W','i','n','d','o','w','s',' ','S','c','r','i','p','t',' ','H','o','s','t',0};
36 static const WCHAR wshVersionW[] = {'5','.','8'};
37 VARIANT_BOOL wshInteractive = VARIANT_TRUE;
39 WINE_DEFAULT_DEBUG_CHANNEL(wscript);
41 static HRESULT WINAPI Host_QueryInterface(IHost *iface, REFIID riid, void **ppv)
43 WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid), ppv);
45 if(IsEqualGUID(&IID_IUnknown, riid)
46 || IsEqualGUID(&IID_IDispatch, riid)
47 || IsEqualGUID(&IID_IHost, riid)) {
48 *ppv = iface;
49 return S_OK;
52 *ppv = NULL;
53 return E_NOINTERFACE;
56 static ULONG WINAPI Host_AddRef(IHost *iface)
58 return 2;
61 static ULONG WINAPI Host_Release(IHost *iface)
63 return 1;
66 static HRESULT WINAPI Host_GetTypeInfoCount(IHost *iface, UINT *pctinfo)
68 WINE_TRACE("(%p)\n", pctinfo);
69 *pctinfo = 1;
70 return S_OK;
73 static HRESULT WINAPI Host_GetTypeInfo(IHost *iface, UINT iTInfo, LCID lcid,
74 ITypeInfo **ppTInfo)
76 WINE_TRACE("(%x %x %p\n", iTInfo, lcid, ppTInfo);
78 ITypeInfo_AddRef(host_ti);
79 *ppTInfo = host_ti;
80 return S_OK;
83 static HRESULT WINAPI Host_GetIDsOfNames(IHost *iface, REFIID riid, LPOLESTR *rgszNames,
84 UINT cNames, LCID lcid, DISPID *rgDispId)
86 WINE_TRACE("(%s %p %d %x %p)\n", wine_dbgstr_guid(riid), rgszNames,
87 cNames, lcid, rgDispId);
89 return ITypeInfo_GetIDsOfNames(host_ti, rgszNames, cNames, rgDispId);
92 static HRESULT WINAPI Host_Invoke(IHost *iface, DISPID dispIdMember, REFIID riid,
93 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
94 EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 WINE_TRACE("(%d %p %p)\n", dispIdMember, pDispParams, pVarResult);
98 return ITypeInfo_Invoke(host_ti, iface, dispIdMember, wFlags, pDispParams,
99 pVarResult, pExcepInfo, puArgErr);
102 static HRESULT WINAPI Host_get_Name(IHost *iface, BSTR *out_Name)
104 WINE_TRACE("(%p)\n", out_Name);
106 if(!(*out_Name = SysAllocString(wshNameW)))
107 return E_OUTOFMEMORY;
108 return S_OK;
111 static HRESULT WINAPI Host_get_Application(IHost *iface, IDispatch **out_Dispatch)
113 WINE_TRACE("(%p)\n", out_Dispatch);
115 *out_Dispatch = (IDispatch*)&host_obj;
116 return S_OK;
119 static HRESULT WINAPI Host_get_FullName(IHost *iface, BSTR *out_Path)
121 WCHAR fullPath[MAX_PATH];
123 WINE_TRACE("(%p)\n", out_Path);
125 if(GetModuleFileNameW(NULL, fullPath, sizeof(fullPath)/sizeof(WCHAR)) == 0)
126 return E_FAIL;
127 if(!(*out_Path = SysAllocString(fullPath)))
128 return E_OUTOFMEMORY;
129 return S_OK;
132 static HRESULT WINAPI Host_get_Path(IHost *iface, BSTR *out_Path)
134 WCHAR path[MAX_PATH];
135 int howMany;
136 WCHAR *pos;
138 WINE_TRACE("(%p)\n", out_Path);
140 if(GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(WCHAR)) == 0)
141 return E_FAIL;
142 pos = strrchrW(path, '\\');
143 howMany = pos - path;
144 if(!(*out_Path = SysAllocStringLen(path, howMany)))
145 return E_OUTOFMEMORY;
146 return S_OK;
149 static HRESULT WINAPI Host_get_Interactive(IHost *iface, VARIANT_BOOL *out_Interactive)
151 WINE_TRACE("(%p)\n", out_Interactive);
153 *out_Interactive = wshInteractive;
154 return S_OK;
157 static HRESULT WINAPI Host_put_Interactive(IHost *iface, VARIANT_BOOL v)
159 WINE_TRACE("(%x)\n", v);
161 wshInteractive = v;
162 return S_OK;
165 static HRESULT WINAPI Host_Quit(IHost *iface, int ExitCode)
167 WINE_FIXME("(%d)\n", ExitCode);
168 return E_NOTIMPL;
171 static HRESULT WINAPI Host_get_ScriptName(IHost *iface, BSTR *out_ScriptName)
173 WCHAR *scriptName;
175 WINE_TRACE("(%p)\n", out_ScriptName);
177 scriptName = strrchrW(scriptFullName, '\\');
178 ++scriptName;
179 if(!(*out_ScriptName = SysAllocString(scriptName)))
180 return E_OUTOFMEMORY;
181 return S_OK;
184 static HRESULT WINAPI Host_get_ScriptFullName(IHost *iface, BSTR *out_ScriptFullName)
186 WINE_TRACE("(%p)\n", out_ScriptFullName);
188 if(!(*out_ScriptFullName = SysAllocString(scriptFullName)))
189 return E_OUTOFMEMORY;
190 return S_OK;
193 static HRESULT WINAPI Host_get_Arguments(IHost *iface, IArguments2 **out_Arguments)
195 WINE_TRACE("(%p)\n", out_Arguments);
197 *out_Arguments = &arguments_obj;
198 return S_OK;
201 static HRESULT WINAPI Host_get_Version(IHost *iface, BSTR *out_Version)
203 WINE_TRACE("(%p)\n", out_Version);
205 if(!(*out_Version = SysAllocString(wshVersionW)))
206 return E_OUTOFMEMORY;
207 return S_OK;
210 static HRESULT WINAPI Host_get_BuildVersion(IHost *iface, int *out_Build)
212 WINE_TRACE("(%p)\n", out_Build);
214 *out_Build = BUILDVERSION;
215 return S_OK;
218 static HRESULT WINAPI Host_get_Timeout(IHost *iface, LONG *out_Timeout)
220 WINE_FIXME("(%p)\n", out_Timeout);
221 return E_NOTIMPL;
224 static HRESULT WINAPI Host_put_Timeout(IHost *iface, LONG v)
226 WINE_FIXME("(%d)\n", v);
227 return E_NOTIMPL;
230 static HRESULT WINAPI Host_CreateObject(IHost *iface, BSTR ProgID, BSTR Prefix,
231 IDispatch **out_Dispatch)
233 WINE_FIXME("(%s %s %p)\n", wine_dbgstr_w(ProgID), wine_dbgstr_w(Prefix), out_Dispatch);
234 return E_NOTIMPL;
237 static HRESULT WINAPI Host_Echo(IHost *iface, SAFEARRAY *args)
239 WINE_FIXME("(%p)\n", args);
240 return E_NOTIMPL;
243 static HRESULT WINAPI Host_GetObject(IHost *iface, BSTR Pathname, BSTR ProgID,
244 BSTR Prefix, IDispatch **out_Dispatch)
246 WINE_FIXME("(%s %s %s %p)\n", wine_dbgstr_w(Pathname), wine_dbgstr_w(ProgID),
247 wine_dbgstr_w(Prefix), out_Dispatch);
248 return E_NOTIMPL;
251 static HRESULT WINAPI Host_DisconnectObject(IHost *iface, IDispatch *Object)
253 WINE_FIXME("(%p)\n", Object);
254 return E_NOTIMPL;
257 static HRESULT WINAPI Host_Sleep(IHost *iface, LONG Time)
259 WINE_FIXME("(%d)\n", Time);
260 return E_NOTIMPL;
263 static HRESULT WINAPI Host_ConnectObject(IHost *iface, IDispatch *Object, BSTR Prefix)
265 WINE_FIXME("(%p %s)\n", Object, wine_dbgstr_w(Prefix));
266 return E_NOTIMPL;
269 static HRESULT WINAPI Host_get_StdIn(IHost *iface, ITextStream **ppts)
271 WINE_FIXME("(%p)\n", ppts);
272 return E_NOTIMPL;
275 static HRESULT WINAPI Host_get_StdOut(IHost *iface, ITextStream **ppts)
277 WINE_FIXME("(%p)\n", ppts);
278 return E_NOTIMPL;
281 static HRESULT WINAPI Host_get_StdErr(IHost *iface, ITextStream **ppts)
283 WINE_FIXME("(%p)\n", ppts);
284 return E_NOTIMPL;
287 static const IHostVtbl HostVtbl = {
288 Host_QueryInterface,
289 Host_AddRef,
290 Host_Release,
291 Host_GetTypeInfoCount,
292 Host_GetTypeInfo,
293 Host_GetIDsOfNames,
294 Host_Invoke,
295 Host_get_Name,
296 Host_get_Application,
297 Host_get_FullName,
298 Host_get_Path,
299 Host_get_Interactive,
300 Host_put_Interactive,
301 Host_Quit,
302 Host_get_ScriptName,
303 Host_get_ScriptFullName,
304 Host_get_Arguments,
305 Host_get_Version,
306 Host_get_BuildVersion,
307 Host_get_Timeout,
308 Host_put_Timeout,
309 Host_CreateObject,
310 Host_Echo,
311 Host_GetObject,
312 Host_DisconnectObject,
313 Host_Sleep,
314 Host_ConnectObject,
315 Host_get_StdIn,
316 Host_get_StdOut,
317 Host_get_StdErr
320 IHost host_obj = { &HostVtbl };