winex11.drv: Don't memcpy() over the DROPFILES point just after setting it.
[wine.git] / programs / wscript / host.c
blob55d4010216bb161717cedd450c85371756d248a5
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'};
38 VARIANT_BOOL wshInteractive =
39 #ifndef CSCRIPT_BUILD
40 VARIANT_TRUE;
41 #else
42 VARIANT_FALSE;
43 #endif
45 WINE_DEFAULT_DEBUG_CHANNEL(wscript);
47 static HRESULT WINAPI Host_QueryInterface(IHost *iface, REFIID riid, void **ppv)
49 WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid), ppv);
51 if(IsEqualGUID(&IID_IUnknown, riid)
52 || IsEqualGUID(&IID_IDispatch, riid)
53 || IsEqualGUID(&IID_IHost, riid)) {
54 *ppv = iface;
55 return S_OK;
58 *ppv = NULL;
59 return E_NOINTERFACE;
62 static ULONG WINAPI Host_AddRef(IHost *iface)
64 return 2;
67 static ULONG WINAPI Host_Release(IHost *iface)
69 return 1;
72 static HRESULT WINAPI Host_GetTypeInfoCount(IHost *iface, UINT *pctinfo)
74 WINE_TRACE("(%p)\n", pctinfo);
75 *pctinfo = 1;
76 return S_OK;
79 static HRESULT WINAPI Host_GetTypeInfo(IHost *iface, UINT iTInfo, LCID lcid,
80 ITypeInfo **ppTInfo)
82 WINE_TRACE("(%x %x %p\n", iTInfo, lcid, ppTInfo);
84 ITypeInfo_AddRef(host_ti);
85 *ppTInfo = host_ti;
86 return S_OK;
89 static HRESULT WINAPI Host_GetIDsOfNames(IHost *iface, REFIID riid, LPOLESTR *rgszNames,
90 UINT cNames, LCID lcid, DISPID *rgDispId)
92 WINE_TRACE("(%s %p %d %x %p)\n", wine_dbgstr_guid(riid), rgszNames,
93 cNames, lcid, rgDispId);
95 return ITypeInfo_GetIDsOfNames(host_ti, rgszNames, cNames, rgDispId);
98 static HRESULT WINAPI Host_Invoke(IHost *iface, DISPID dispIdMember, REFIID riid,
99 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
100 EXCEPINFO *pExcepInfo, UINT *puArgErr)
102 WINE_TRACE("(%d %p %p)\n", dispIdMember, pDispParams, pVarResult);
104 return ITypeInfo_Invoke(host_ti, iface, dispIdMember, wFlags, pDispParams,
105 pVarResult, pExcepInfo, puArgErr);
108 static HRESULT WINAPI Host_get_Name(IHost *iface, BSTR *out_Name)
110 WINE_TRACE("(%p)\n", out_Name);
112 if(!(*out_Name = SysAllocString(wshNameW)))
113 return E_OUTOFMEMORY;
114 return S_OK;
117 static HRESULT WINAPI Host_get_Application(IHost *iface, IDispatch **out_Dispatch)
119 WINE_TRACE("(%p)\n", out_Dispatch);
121 *out_Dispatch = (IDispatch*)&host_obj;
122 return S_OK;
125 static HRESULT WINAPI Host_get_FullName(IHost *iface, BSTR *out_Path)
127 WCHAR fullPath[MAX_PATH];
129 WINE_TRACE("(%p)\n", out_Path);
131 if(GetModuleFileNameW(NULL, fullPath, sizeof(fullPath)/sizeof(WCHAR)) == 0)
132 return E_FAIL;
133 if(!(*out_Path = SysAllocString(fullPath)))
134 return E_OUTOFMEMORY;
135 return S_OK;
138 static HRESULT WINAPI Host_get_Path(IHost *iface, BSTR *out_Path)
140 WCHAR path[MAX_PATH];
141 int howMany;
142 WCHAR *pos;
144 WINE_TRACE("(%p)\n", out_Path);
146 if(GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(WCHAR)) == 0)
147 return E_FAIL;
148 pos = strrchrW(path, '\\');
149 howMany = pos - path;
150 if(!(*out_Path = SysAllocStringLen(path, howMany)))
151 return E_OUTOFMEMORY;
152 return S_OK;
155 static HRESULT WINAPI Host_get_Interactive(IHost *iface, VARIANT_BOOL *out_Interactive)
157 WINE_TRACE("(%p)\n", out_Interactive);
159 *out_Interactive = wshInteractive;
160 return S_OK;
163 static HRESULT WINAPI Host_put_Interactive(IHost *iface, VARIANT_BOOL v)
165 WINE_TRACE("(%x)\n", v);
167 wshInteractive = v;
168 return S_OK;
171 static HRESULT WINAPI Host_Quit(IHost *iface, int ExitCode)
173 WINE_FIXME("(%d)\n", ExitCode);
174 return E_NOTIMPL;
177 static HRESULT WINAPI Host_get_ScriptName(IHost *iface, BSTR *out_ScriptName)
179 WCHAR *scriptName;
181 WINE_TRACE("(%p)\n", out_ScriptName);
183 scriptName = strrchrW(scriptFullName, '\\');
184 ++scriptName;
185 if(!(*out_ScriptName = SysAllocString(scriptName)))
186 return E_OUTOFMEMORY;
187 return S_OK;
190 static HRESULT WINAPI Host_get_ScriptFullName(IHost *iface, BSTR *out_ScriptFullName)
192 WINE_TRACE("(%p)\n", out_ScriptFullName);
194 if(!(*out_ScriptFullName = SysAllocString(scriptFullName)))
195 return E_OUTOFMEMORY;
196 return S_OK;
199 static HRESULT WINAPI Host_get_Arguments(IHost *iface, IArguments2 **out_Arguments)
201 WINE_TRACE("(%p)\n", out_Arguments);
203 *out_Arguments = &arguments_obj;
204 return S_OK;
207 static HRESULT WINAPI Host_get_Version(IHost *iface, BSTR *out_Version)
209 WINE_TRACE("(%p)\n", out_Version);
211 if(!(*out_Version = SysAllocString(wshVersionW)))
212 return E_OUTOFMEMORY;
213 return S_OK;
216 static HRESULT WINAPI Host_get_BuildVersion(IHost *iface, int *out_Build)
218 WINE_TRACE("(%p)\n", out_Build);
220 *out_Build = BUILDVERSION;
221 return S_OK;
224 static HRESULT WINAPI Host_get_Timeout(IHost *iface, LONG *out_Timeout)
226 WINE_FIXME("(%p)\n", out_Timeout);
227 return E_NOTIMPL;
230 static HRESULT WINAPI Host_put_Timeout(IHost *iface, LONG v)
232 WINE_FIXME("(%d)\n", v);
233 return E_NOTIMPL;
236 static HRESULT WINAPI Host_CreateObject(IHost *iface, BSTR ProgID, BSTR Prefix,
237 IDispatch **out_Dispatch)
239 IUnknown *unk;
240 GUID guid;
241 HRESULT hres;
243 TRACE("(%s %s %p)\n", wine_dbgstr_w(ProgID), wine_dbgstr_w(Prefix), out_Dispatch);
245 if(Prefix && *Prefix) {
246 FIXME("Prefix %s not supported\n", debugstr_w(Prefix));
247 return E_NOTIMPL;
250 hres = CLSIDFromProgID(ProgID, &guid);
251 if(FAILED(hres))
252 return hres;
254 hres = CoCreateInstance(&guid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER|CLSCTX_REMOTE_SERVER,
255 &IID_IUnknown, (void**)&unk);
256 if(FAILED(hres))
257 return hres;
259 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)out_Dispatch);
260 IUnknown_Release(unk);
261 return hres;
264 static HRESULT WINAPI Host_Echo(IHost *iface, SAFEARRAY *args)
266 WINE_FIXME("(%p)\n", args);
267 return E_NOTIMPL;
270 static HRESULT WINAPI Host_GetObject(IHost *iface, BSTR Pathname, BSTR ProgID,
271 BSTR Prefix, IDispatch **out_Dispatch)
273 WINE_FIXME("(%s %s %s %p)\n", wine_dbgstr_w(Pathname), wine_dbgstr_w(ProgID),
274 wine_dbgstr_w(Prefix), out_Dispatch);
275 return E_NOTIMPL;
278 static HRESULT WINAPI Host_DisconnectObject(IHost *iface, IDispatch *Object)
280 WINE_FIXME("(%p)\n", Object);
281 return E_NOTIMPL;
284 static HRESULT WINAPI Host_Sleep(IHost *iface, LONG Time)
286 WINE_FIXME("(%d)\n", Time);
287 return E_NOTIMPL;
290 static HRESULT WINAPI Host_ConnectObject(IHost *iface, IDispatch *Object, BSTR Prefix)
292 WINE_FIXME("(%p %s)\n", Object, wine_dbgstr_w(Prefix));
293 return E_NOTIMPL;
296 static HRESULT WINAPI Host_get_StdIn(IHost *iface, ITextStream **ppts)
298 WINE_FIXME("(%p)\n", ppts);
299 return E_NOTIMPL;
302 static HRESULT WINAPI Host_get_StdOut(IHost *iface, ITextStream **ppts)
304 WINE_FIXME("(%p)\n", ppts);
305 return E_NOTIMPL;
308 static HRESULT WINAPI Host_get_StdErr(IHost *iface, ITextStream **ppts)
310 WINE_FIXME("(%p)\n", ppts);
311 return E_NOTIMPL;
314 static const IHostVtbl HostVtbl = {
315 Host_QueryInterface,
316 Host_AddRef,
317 Host_Release,
318 Host_GetTypeInfoCount,
319 Host_GetTypeInfo,
320 Host_GetIDsOfNames,
321 Host_Invoke,
322 Host_get_Name,
323 Host_get_Application,
324 Host_get_FullName,
325 Host_get_Path,
326 Host_get_Interactive,
327 Host_put_Interactive,
328 Host_Quit,
329 Host_get_ScriptName,
330 Host_get_ScriptFullName,
331 Host_get_Arguments,
332 Host_get_Version,
333 Host_get_BuildVersion,
334 Host_get_Timeout,
335 Host_put_Timeout,
336 Host_CreateObject,
337 Host_Echo,
338 Host_GetObject,
339 Host_DisconnectObject,
340 Host_Sleep,
341 Host_ConnectObject,
342 Host_get_StdIn,
343 Host_get_StdOut,
344 Host_get_StdErr
347 IHost host_obj = { &HostVtbl };