2010-07-29 14:58:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define CONST_VTABLE
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <ole2.h>
|
|
|
|
|
|
|
|
#include "wscript.h"
|
|
|
|
|
|
|
|
#include <wine/debug.h>
|
2011-07-20 21:47:29 +02:00
|
|
|
#include <wine/unicode.h>
|
2010-07-29 14:58:38 +02:00
|
|
|
|
2011-07-04 23:28:52 +02:00
|
|
|
#define BUILDVERSION 16535
|
|
|
|
|
2011-06-28 13:37:36 +02:00
|
|
|
static const WCHAR wshNameW[] = {'W','i','n','d','o','w','s',' ','S','c','r','i','p','t',' ','H','o','s','t',0};
|
2011-06-28 13:38:56 +02:00
|
|
|
static const WCHAR wshVersionW[] = {'5','.','8'};
|
2014-04-14 13:15:02 +02:00
|
|
|
|
|
|
|
VARIANT_BOOL wshInteractive =
|
|
|
|
#ifndef CSCRIPT_BUILD
|
|
|
|
VARIANT_TRUE;
|
|
|
|
#else
|
|
|
|
VARIANT_FALSE;
|
|
|
|
#endif
|
2011-06-28 13:37:36 +02:00
|
|
|
|
2010-07-29 14:58:38 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wscript);
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_QueryInterface(IHost *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)
|
|
|
|
|| IsEqualGUID(&IID_IDispatch, riid)
|
|
|
|
|| IsEqualGUID(&IID_IHost, riid)) {
|
|
|
|
*ppv = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Host_AddRef(IHost *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Host_Release(IHost *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_GetTypeInfoCount(IHost *iface, UINT *pctinfo)
|
|
|
|
{
|
|
|
|
WINE_TRACE("(%p)\n", pctinfo);
|
|
|
|
*pctinfo = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_GetTypeInfo(IHost *iface, UINT iTInfo, LCID lcid,
|
|
|
|
ITypeInfo **ppTInfo)
|
|
|
|
{
|
2010-07-30 13:56:49 +02:00
|
|
|
WINE_TRACE("(%x %x %p\n", iTInfo, lcid, ppTInfo);
|
|
|
|
|
|
|
|
ITypeInfo_AddRef(host_ti);
|
|
|
|
*ppTInfo = host_ti;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_GetIDsOfNames(IHost *iface, REFIID riid, LPOLESTR *rgszNames,
|
|
|
|
UINT cNames, LCID lcid, DISPID *rgDispId)
|
|
|
|
{
|
2010-07-30 13:56:49 +02:00
|
|
|
WINE_TRACE("(%s %p %d %x %p)\n", wine_dbgstr_guid(riid), rgszNames,
|
2010-07-29 14:58:38 +02:00
|
|
|
cNames, lcid, rgDispId);
|
2010-07-30 13:56:49 +02:00
|
|
|
|
|
|
|
return ITypeInfo_GetIDsOfNames(host_ti, rgszNames, cNames, rgDispId);
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_Invoke(IHost *iface, DISPID dispIdMember, REFIID riid,
|
|
|
|
LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
|
|
|
|
EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
2010-07-30 13:56:49 +02:00
|
|
|
WINE_TRACE("(%d %p %p)\n", dispIdMember, pDispParams, pVarResult);
|
|
|
|
|
|
|
|
return ITypeInfo_Invoke(host_ti, iface, dispIdMember, wFlags, pDispParams,
|
|
|
|
pVarResult, pExcepInfo, puArgErr);
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Name(IHost *iface, BSTR *out_Name)
|
|
|
|
{
|
2011-06-28 13:37:36 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_Name);
|
|
|
|
|
|
|
|
if(!(*out_Name = SysAllocString(wshNameW)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Application(IHost *iface, IDispatch **out_Dispatch)
|
|
|
|
{
|
2011-08-23 15:16:19 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_Dispatch);
|
|
|
|
|
|
|
|
*out_Dispatch = (IDispatch*)&host_obj;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_FullName(IHost *iface, BSTR *out_Path)
|
|
|
|
{
|
2011-07-20 21:47:18 +02:00
|
|
|
WCHAR fullPath[MAX_PATH];
|
|
|
|
|
|
|
|
WINE_TRACE("(%p)\n", out_Path);
|
|
|
|
|
|
|
|
if(GetModuleFileNameW(NULL, fullPath, sizeof(fullPath)/sizeof(WCHAR)) == 0)
|
|
|
|
return E_FAIL;
|
|
|
|
if(!(*out_Path = SysAllocString(fullPath)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Path(IHost *iface, BSTR *out_Path)
|
|
|
|
{
|
2011-07-20 21:47:29 +02:00
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
int howMany;
|
|
|
|
WCHAR *pos;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p)\n", out_Path);
|
|
|
|
|
|
|
|
if(GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(WCHAR)) == 0)
|
|
|
|
return E_FAIL;
|
|
|
|
pos = strrchrW(path, '\\');
|
|
|
|
howMany = pos - path;
|
|
|
|
if(!(*out_Path = SysAllocStringLen(path, howMany)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Interactive(IHost *iface, VARIANT_BOOL *out_Interactive)
|
|
|
|
{
|
2011-08-23 15:16:08 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_Interactive);
|
|
|
|
|
|
|
|
*out_Interactive = wshInteractive;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_put_Interactive(IHost *iface, VARIANT_BOOL v)
|
|
|
|
{
|
2011-08-23 15:16:15 +02:00
|
|
|
WINE_TRACE("(%x)\n", v);
|
|
|
|
|
|
|
|
wshInteractive = v;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_Quit(IHost *iface, int ExitCode)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%d)\n", ExitCode);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_ScriptName(IHost *iface, BSTR *out_ScriptName)
|
|
|
|
{
|
2011-07-20 21:47:38 +02:00
|
|
|
WCHAR *scriptName;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p)\n", out_ScriptName);
|
|
|
|
|
|
|
|
scriptName = strrchrW(scriptFullName, '\\');
|
|
|
|
++scriptName;
|
|
|
|
if(!(*out_ScriptName = SysAllocString(scriptName)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_ScriptFullName(IHost *iface, BSTR *out_ScriptFullName)
|
|
|
|
{
|
2011-07-20 21:47:47 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_ScriptFullName);
|
|
|
|
|
|
|
|
if(!(*out_ScriptFullName = SysAllocString(scriptFullName)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Arguments(IHost *iface, IArguments2 **out_Arguments)
|
|
|
|
{
|
2011-08-23 15:15:48 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_Arguments);
|
|
|
|
|
|
|
|
*out_Arguments = &arguments_obj;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Version(IHost *iface, BSTR *out_Version)
|
|
|
|
{
|
2011-06-28 13:38:56 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_Version);
|
|
|
|
|
|
|
|
if(!(*out_Version = SysAllocString(wshVersionW)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_BuildVersion(IHost *iface, int *out_Build)
|
|
|
|
{
|
2011-07-04 23:28:52 +02:00
|
|
|
WINE_TRACE("(%p)\n", out_Build);
|
|
|
|
|
|
|
|
*out_Build = BUILDVERSION;
|
|
|
|
return S_OK;
|
2010-07-29 14:58:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_Timeout(IHost *iface, LONG *out_Timeout)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p)\n", out_Timeout);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_put_Timeout(IHost *iface, LONG v)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%d)\n", v);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_CreateObject(IHost *iface, BSTR ProgID, BSTR Prefix,
|
|
|
|
IDispatch **out_Dispatch)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%s %s %p)\n", wine_dbgstr_w(ProgID), wine_dbgstr_w(Prefix), out_Dispatch);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_Echo(IHost *iface, SAFEARRAY *args)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p)\n", args);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_GetObject(IHost *iface, BSTR Pathname, BSTR ProgID,
|
|
|
|
BSTR Prefix, IDispatch **out_Dispatch)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%s %s %s %p)\n", wine_dbgstr_w(Pathname), wine_dbgstr_w(ProgID),
|
|
|
|
wine_dbgstr_w(Prefix), out_Dispatch);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_DisconnectObject(IHost *iface, IDispatch *Object)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p)\n", Object);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_Sleep(IHost *iface, LONG Time)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%d)\n", Time);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_ConnectObject(IHost *iface, IDispatch *Object, BSTR Prefix)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p %s)\n", Object, wine_dbgstr_w(Prefix));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_StdIn(IHost *iface, ITextStream **ppts)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p)\n", ppts);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_StdOut(IHost *iface, ITextStream **ppts)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p)\n", ppts);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Host_get_StdErr(IHost *iface, ITextStream **ppts)
|
|
|
|
{
|
|
|
|
WINE_FIXME("(%p)\n", ppts);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IHostVtbl HostVtbl = {
|
|
|
|
Host_QueryInterface,
|
|
|
|
Host_AddRef,
|
|
|
|
Host_Release,
|
|
|
|
Host_GetTypeInfoCount,
|
|
|
|
Host_GetTypeInfo,
|
|
|
|
Host_GetIDsOfNames,
|
|
|
|
Host_Invoke,
|
|
|
|
Host_get_Name,
|
|
|
|
Host_get_Application,
|
|
|
|
Host_get_FullName,
|
|
|
|
Host_get_Path,
|
|
|
|
Host_get_Interactive,
|
|
|
|
Host_put_Interactive,
|
|
|
|
Host_Quit,
|
|
|
|
Host_get_ScriptName,
|
|
|
|
Host_get_ScriptFullName,
|
|
|
|
Host_get_Arguments,
|
|
|
|
Host_get_Version,
|
|
|
|
Host_get_BuildVersion,
|
|
|
|
Host_get_Timeout,
|
|
|
|
Host_put_Timeout,
|
|
|
|
Host_CreateObject,
|
|
|
|
Host_Echo,
|
|
|
|
Host_GetObject,
|
|
|
|
Host_DisconnectObject,
|
|
|
|
Host_Sleep,
|
|
|
|
Host_ConnectObject,
|
|
|
|
Host_get_StdIn,
|
|
|
|
Host_get_StdOut,
|
|
|
|
Host_get_StdErr
|
|
|
|
};
|
|
|
|
|
|
|
|
IHost host_obj = { &HostVtbl };
|