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
21 #define BUILDVERSION 16535
23 static const WCHAR wshNameW
[] = {'W','i','n','d','o','w','s',' ','S','c','r','i','p','t',' ','H','o','s','t',0};
24 static const WCHAR wshVersionW
[] = {'5','.','8'};
26 VARIANT_BOOL wshInteractive
=
33 static HRESULT
to_string(VARIANT
*src
, BSTR
*dst
)
38 static const WCHAR nullW
[] = {'n','u','l','l',0};
40 if(V_VT(src
) == VT_NULL
) {
41 *dst
= SysAllocString(nullW
);
42 return *dst
? S_OK
: E_OUTOFMEMORY
;
46 hres
= VariantChangeType(&v
, src
, 0, VT_BSTR
);
48 WARN("Could not convert argument %s to string\n", debugstr_variant(src
));
56 static void print_string(const WCHAR
*string
)
58 DWORD count
, ret
, len
, lena
;
62 static const WCHAR windows_script_hostW
[] =
63 {'W','i','n','d','o','w','s',' ','S','c','r','i','p','t',' ','H','o','s','t',0};
64 MessageBoxW(NULL
, string
, windows_script_hostW
, MB_OK
);
68 len
= strlenW(string
);
69 ret
= WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE
), string
, len
, &count
, NULL
);
71 static const WCHAR crnlW
[] = {'\r','\n'};
72 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE
), crnlW
, sizeof(crnlW
)/sizeof(*crnlW
), &count
, NULL
);
76 lena
= WideCharToMultiByte(GetConsoleOutputCP(), 0, string
, len
, NULL
, 0, NULL
, NULL
);
77 buf
= heap_alloc(len
);
81 WideCharToMultiByte(GetConsoleOutputCP(), 0, string
, len
, buf
, lena
, NULL
, NULL
);
82 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE
), buf
, lena
, &count
, FALSE
);
84 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE
), "\r\n", 2, &count
, FALSE
);
87 static HRESULT WINAPI
Host_QueryInterface(IHost
*iface
, REFIID riid
, void **ppv
)
89 WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid
), ppv
);
91 if(IsEqualGUID(&IID_IUnknown
, riid
)
92 || IsEqualGUID(&IID_IDispatch
, riid
)
93 || IsEqualGUID(&IID_IHost
, riid
)) {
102 static ULONG WINAPI
Host_AddRef(IHost
*iface
)
107 static ULONG WINAPI
Host_Release(IHost
*iface
)
112 static HRESULT WINAPI
Host_GetTypeInfoCount(IHost
*iface
, UINT
*pctinfo
)
114 WINE_TRACE("(%p)\n", pctinfo
);
119 static HRESULT WINAPI
Host_GetTypeInfo(IHost
*iface
, UINT iTInfo
, LCID lcid
,
122 WINE_TRACE("(%x %x %p\n", iTInfo
, lcid
, ppTInfo
);
124 ITypeInfo_AddRef(host_ti
);
129 static HRESULT WINAPI
Host_GetIDsOfNames(IHost
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
130 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
132 WINE_TRACE("(%s %p %d %x %p)\n", wine_dbgstr_guid(riid
), rgszNames
,
133 cNames
, lcid
, rgDispId
);
135 return ITypeInfo_GetIDsOfNames(host_ti
, rgszNames
, cNames
, rgDispId
);
138 static HRESULT WINAPI
Host_Invoke(IHost
*iface
, DISPID dispIdMember
, REFIID riid
,
139 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
140 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
142 WINE_TRACE("(%d %p %p)\n", dispIdMember
, pDispParams
, pVarResult
);
144 return ITypeInfo_Invoke(host_ti
, iface
, dispIdMember
, wFlags
, pDispParams
,
145 pVarResult
, pExcepInfo
, puArgErr
);
148 static HRESULT WINAPI
Host_get_Name(IHost
*iface
, BSTR
*out_Name
)
150 WINE_TRACE("(%p)\n", out_Name
);
152 if(!(*out_Name
= SysAllocString(wshNameW
)))
153 return E_OUTOFMEMORY
;
157 static HRESULT WINAPI
Host_get_Application(IHost
*iface
, IDispatch
**out_Dispatch
)
159 WINE_TRACE("(%p)\n", out_Dispatch
);
161 *out_Dispatch
= (IDispatch
*)&host_obj
;
165 static HRESULT WINAPI
Host_get_FullName(IHost
*iface
, BSTR
*out_Path
)
167 WCHAR fullPath
[MAX_PATH
];
169 WINE_TRACE("(%p)\n", out_Path
);
171 if(GetModuleFileNameW(NULL
, fullPath
, sizeof(fullPath
)/sizeof(WCHAR
)) == 0)
173 if(!(*out_Path
= SysAllocString(fullPath
)))
174 return E_OUTOFMEMORY
;
178 static HRESULT WINAPI
Host_get_Path(IHost
*iface
, BSTR
*out_Path
)
180 WCHAR path
[MAX_PATH
];
184 WINE_TRACE("(%p)\n", out_Path
);
186 if(GetModuleFileNameW(NULL
, path
, sizeof(path
)/sizeof(WCHAR
)) == 0)
188 pos
= strrchrW(path
, '\\');
189 howMany
= pos
- path
;
190 if(!(*out_Path
= SysAllocStringLen(path
, howMany
)))
191 return E_OUTOFMEMORY
;
195 static HRESULT WINAPI
Host_get_Interactive(IHost
*iface
, VARIANT_BOOL
*out_Interactive
)
197 WINE_TRACE("(%p)\n", out_Interactive
);
199 *out_Interactive
= wshInteractive
;
203 static HRESULT WINAPI
Host_put_Interactive(IHost
*iface
, VARIANT_BOOL v
)
205 WINE_TRACE("(%x)\n", v
);
211 static HRESULT WINAPI
Host_Quit(IHost
*iface
, int ExitCode
)
213 FIXME("(%d) semi-stub: no script engine clean up\n", ExitCode
);
215 ExitProcess(ExitCode
);
219 static HRESULT WINAPI
Host_get_ScriptName(IHost
*iface
, BSTR
*out_ScriptName
)
223 WINE_TRACE("(%p)\n", out_ScriptName
);
225 scriptName
= strrchrW(scriptFullName
, '\\');
227 if(!(*out_ScriptName
= SysAllocString(scriptName
)))
228 return E_OUTOFMEMORY
;
232 static HRESULT WINAPI
Host_get_ScriptFullName(IHost
*iface
, BSTR
*out_ScriptFullName
)
234 WINE_TRACE("(%p)\n", out_ScriptFullName
);
236 if(!(*out_ScriptFullName
= SysAllocString(scriptFullName
)))
237 return E_OUTOFMEMORY
;
241 static HRESULT WINAPI
Host_get_Arguments(IHost
*iface
, IArguments2
**out_Arguments
)
243 WINE_TRACE("(%p)\n", out_Arguments
);
245 *out_Arguments
= &arguments_obj
;
249 static HRESULT WINAPI
Host_get_Version(IHost
*iface
, BSTR
*out_Version
)
251 WINE_TRACE("(%p)\n", out_Version
);
253 if(!(*out_Version
= SysAllocString(wshVersionW
)))
254 return E_OUTOFMEMORY
;
258 static HRESULT WINAPI
Host_get_BuildVersion(IHost
*iface
, int *out_Build
)
260 WINE_TRACE("(%p)\n", out_Build
);
262 *out_Build
= BUILDVERSION
;
266 static HRESULT WINAPI
Host_get_Timeout(IHost
*iface
, LONG
*out_Timeout
)
268 WINE_FIXME("(%p)\n", out_Timeout
);
272 static HRESULT WINAPI
Host_put_Timeout(IHost
*iface
, LONG v
)
274 WINE_FIXME("(%d)\n", v
);
278 static HRESULT WINAPI
Host_CreateObject(IHost
*iface
, BSTR ProgID
, BSTR Prefix
,
279 IDispatch
**out_Dispatch
)
285 TRACE("(%s %s %p)\n", wine_dbgstr_w(ProgID
), wine_dbgstr_w(Prefix
), out_Dispatch
);
287 if(Prefix
&& *Prefix
) {
288 FIXME("Prefix %s not supported\n", debugstr_w(Prefix
));
292 hres
= CLSIDFromProgID(ProgID
, &guid
);
296 hres
= CoCreateInstance(&guid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
,
297 &IID_IUnknown
, (void**)&unk
);
301 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)out_Dispatch
);
302 IUnknown_Release(unk
);
306 static HRESULT WINAPI
Host_Echo(IHost
*iface
, SAFEARRAY
*args
)
308 WCHAR
*output
= NULL
, *ptr
;
309 unsigned argc
, i
, len
;
315 TRACE("(%p)\n", args
);
317 if(SafeArrayGetDim(args
) != 1) {
318 FIXME("Unsupported args dim %d\n", SafeArrayGetDim(args
));
322 SafeArrayGetLBound(args
, 1, &lbound
);
323 SafeArrayGetUBound(args
, 1, &ubound
);
325 hres
= SafeArrayAccessData(args
, (void**)&argv
);
329 argc
= ubound
-lbound
+1;
330 strs
= heap_alloc_zero(argc
*sizeof(*strs
));
332 SafeArrayUnaccessData(args
);
333 return E_OUTOFMEMORY
;
336 /* Len of spaces between arguments. */
339 for(i
=0; i
< argc
; i
++) {
340 hres
= to_string(argv
+i
, strs
+i
);
344 len
+= SysStringLen(strs
[i
]);
347 SafeArrayUnaccessData(args
);
348 if(SUCCEEDED(hres
)) {
349 ptr
= output
= heap_alloc((len
+1)*sizeof(WCHAR
));
351 for(i
=0; i
< argc
; i
++) {
354 len
= SysStringLen(strs
[i
]);
355 memcpy(ptr
, strs
[i
], len
*sizeof(WCHAR
));
360 hres
= E_OUTOFMEMORY
;
364 for(i
=0; i
< argc
; i
++)
365 SysFreeString(strs
[i
]);
370 print_string(output
);
376 static HRESULT WINAPI
Host_GetObject(IHost
*iface
, BSTR Pathname
, BSTR ProgID
,
377 BSTR Prefix
, IDispatch
**out_Dispatch
)
379 WINE_FIXME("(%s %s %s %p)\n", wine_dbgstr_w(Pathname
), wine_dbgstr_w(ProgID
),
380 wine_dbgstr_w(Prefix
), out_Dispatch
);
384 static HRESULT WINAPI
Host_DisconnectObject(IHost
*iface
, IDispatch
*Object
)
386 WINE_FIXME("(%p)\n", Object
);
390 static HRESULT WINAPI
Host_Sleep(IHost
*iface
, LONG Time
)
392 WINE_FIXME("(%d)\n", Time
);
396 static HRESULT WINAPI
Host_ConnectObject(IHost
*iface
, IDispatch
*Object
, BSTR Prefix
)
398 WINE_FIXME("(%p %s)\n", Object
, wine_dbgstr_w(Prefix
));
402 static HRESULT WINAPI
Host_get_StdIn(IHost
*iface
, ITextStream
**ppts
)
404 WINE_FIXME("(%p)\n", ppts
);
408 static HRESULT WINAPI
Host_get_StdOut(IHost
*iface
, ITextStream
**ppts
)
410 WINE_FIXME("(%p)\n", ppts
);
414 static HRESULT WINAPI
Host_get_StdErr(IHost
*iface
, ITextStream
**ppts
)
416 WINE_FIXME("(%p)\n", ppts
);
420 static const IHostVtbl HostVtbl
= {
424 Host_GetTypeInfoCount
,
429 Host_get_Application
,
432 Host_get_Interactive
,
433 Host_put_Interactive
,
436 Host_get_ScriptFullName
,
439 Host_get_BuildVersion
,
445 Host_DisconnectObject
,
453 IHost host_obj
= { &HostVtbl
};