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
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
=
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
)) {
62 static ULONG WINAPI
Host_AddRef(IHost
*iface
)
67 static ULONG WINAPI
Host_Release(IHost
*iface
)
72 static HRESULT WINAPI
Host_GetTypeInfoCount(IHost
*iface
, UINT
*pctinfo
)
74 WINE_TRACE("(%p)\n", pctinfo
);
79 static HRESULT WINAPI
Host_GetTypeInfo(IHost
*iface
, UINT iTInfo
, LCID lcid
,
82 WINE_TRACE("(%x %x %p\n", iTInfo
, lcid
, ppTInfo
);
84 ITypeInfo_AddRef(host_ti
);
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
;
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
;
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)
133 if(!(*out_Path
= SysAllocString(fullPath
)))
134 return E_OUTOFMEMORY
;
138 static HRESULT WINAPI
Host_get_Path(IHost
*iface
, BSTR
*out_Path
)
140 WCHAR path
[MAX_PATH
];
144 WINE_TRACE("(%p)\n", out_Path
);
146 if(GetModuleFileNameW(NULL
, path
, sizeof(path
)/sizeof(WCHAR
)) == 0)
148 pos
= strrchrW(path
, '\\');
149 howMany
= pos
- path
;
150 if(!(*out_Path
= SysAllocStringLen(path
, howMany
)))
151 return E_OUTOFMEMORY
;
155 static HRESULT WINAPI
Host_get_Interactive(IHost
*iface
, VARIANT_BOOL
*out_Interactive
)
157 WINE_TRACE("(%p)\n", out_Interactive
);
159 *out_Interactive
= wshInteractive
;
163 static HRESULT WINAPI
Host_put_Interactive(IHost
*iface
, VARIANT_BOOL v
)
165 WINE_TRACE("(%x)\n", v
);
171 static HRESULT WINAPI
Host_Quit(IHost
*iface
, int ExitCode
)
173 WINE_FIXME("(%d)\n", ExitCode
);
177 static HRESULT WINAPI
Host_get_ScriptName(IHost
*iface
, BSTR
*out_ScriptName
)
181 WINE_TRACE("(%p)\n", out_ScriptName
);
183 scriptName
= strrchrW(scriptFullName
, '\\');
185 if(!(*out_ScriptName
= SysAllocString(scriptName
)))
186 return E_OUTOFMEMORY
;
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
;
199 static HRESULT WINAPI
Host_get_Arguments(IHost
*iface
, IArguments2
**out_Arguments
)
201 WINE_TRACE("(%p)\n", out_Arguments
);
203 *out_Arguments
= &arguments_obj
;
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
;
216 static HRESULT WINAPI
Host_get_BuildVersion(IHost
*iface
, int *out_Build
)
218 WINE_TRACE("(%p)\n", out_Build
);
220 *out_Build
= BUILDVERSION
;
224 static HRESULT WINAPI
Host_get_Timeout(IHost
*iface
, LONG
*out_Timeout
)
226 WINE_FIXME("(%p)\n", out_Timeout
);
230 static HRESULT WINAPI
Host_put_Timeout(IHost
*iface
, LONG v
)
232 WINE_FIXME("(%d)\n", v
);
236 static HRESULT WINAPI
Host_CreateObject(IHost
*iface
, BSTR ProgID
, BSTR Prefix
,
237 IDispatch
**out_Dispatch
)
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
));
250 hres
= CLSIDFromProgID(ProgID
, &guid
);
254 hres
= CoCreateInstance(&guid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
|CLSCTX_REMOTE_SERVER
,
255 &IID_IUnknown
, (void**)&unk
);
259 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)out_Dispatch
);
260 IUnknown_Release(unk
);
264 static HRESULT WINAPI
Host_Echo(IHost
*iface
, SAFEARRAY
*args
)
266 WINE_FIXME("(%p)\n", args
);
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
);
278 static HRESULT WINAPI
Host_DisconnectObject(IHost
*iface
, IDispatch
*Object
)
280 WINE_FIXME("(%p)\n", Object
);
284 static HRESULT WINAPI
Host_Sleep(IHost
*iface
, LONG Time
)
286 WINE_FIXME("(%d)\n", Time
);
290 static HRESULT WINAPI
Host_ConnectObject(IHost
*iface
, IDispatch
*Object
, BSTR Prefix
)
292 WINE_FIXME("(%p %s)\n", Object
, wine_dbgstr_w(Prefix
));
296 static HRESULT WINAPI
Host_get_StdIn(IHost
*iface
, ITextStream
**ppts
)
298 WINE_FIXME("(%p)\n", ppts
);
302 static HRESULT WINAPI
Host_get_StdOut(IHost
*iface
, ITextStream
**ppts
)
304 WINE_FIXME("(%p)\n", ppts
);
308 static HRESULT WINAPI
Host_get_StdErr(IHost
*iface
, ITextStream
**ppts
)
310 WINE_FIXME("(%p)\n", ppts
);
314 static const IHostVtbl HostVtbl
= {
318 Host_GetTypeInfoCount
,
323 Host_get_Application
,
326 Host_get_Interactive
,
327 Host_put_Interactive
,
330 Host_get_ScriptFullName
,
333 Host_get_BuildVersion
,
339 Host_DisconnectObject
,
347 IHost host_obj
= { &HostVtbl
};