wscript.exe: Added script engine host implementation.

This commit is contained in:
Jacek Caban 2010-07-27 15:52:17 +02:00 committed by Alexandre Julliard
parent 28efdcb521
commit 89ca878d1b
2 changed files with 179 additions and 1 deletions

View File

@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = wscript.exe
APPMODE = -mwindows -municode
IMPORTS = ole32 advapi32
IMPORTS = uuid ole32 advapi32
EXTRADEFS = -DWINE_NO_UNICODE_MACROS
C_SRCS = \

View File

@ -18,16 +18,119 @@
#include <stdarg.h>
#define COBJMACROS
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <ole2.h>
#include <activscp.h>
#include <wine/debug.h>
#include <wine/unicode.h>
WINE_DEFAULT_DEBUG_CHANNEL(wscript);
static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface,
REFIID riid, void **ppv)
{
if(IsEqualGUID(riid, &IID_IUnknown)) {
WINE_TRACE("(IID_IUnknown %p)\n", ppv);
*ppv = iface;
}else if(IsEqualGUID(riid, &IID_IActiveScriptSite)) {
WINE_TRACE("(IID_IActiveScriptSite %p)\n", ppv);
*ppv = iface;
}else {
*ppv = NULL;
WINE_TRACE("(%s %p)\n", wine_dbgstr_guid(riid), ppv);
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
{
return 2;
}
static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
{
return 1;
}
static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
{
WINE_TRACE("()\n");
*plcid = GetUserDefaultLCID();
return S_OK;
}
static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface,
LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppunkItem, ITypeInfo **ppti)
{
WINE_FIXME("(%s %x %p %p)\n", wine_dbgstr_w(pstrName), dwReturnMask, ppunkItem, ppti);
return E_NOTIMPL;
}
static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface,
BSTR *pbstrVersion)
{
WINE_FIXME("()\n");
return E_NOTIMPL;
}
static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
{
WINE_FIXME("()\n");
return E_NOTIMPL;
}
static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface,
SCRIPTSTATE ssScriptState)
{
WINE_TRACE("(%x)\n", ssScriptState);
return S_OK;
}
static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface,
IActiveScriptError *pscripterror)
{
WINE_FIXME("()\n");
return E_NOTIMPL;
}
static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
{
WINE_TRACE("()\n");
return S_OK;
}
static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
{
WINE_TRACE("()\n");
return S_OK;
}
static IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
ActiveScriptSite_QueryInterface,
ActiveScriptSite_AddRef,
ActiveScriptSite_Release,
ActiveScriptSite_GetLCID,
ActiveScriptSite_GetItemInfo,
ActiveScriptSite_GetDocVersionString,
ActiveScriptSite_OnScriptTerminate,
ActiveScriptSite_OnStateChange,
ActiveScriptSite_OnScriptError,
ActiveScriptSite_OnEnterScript,
ActiveScriptSite_OnLeaveScript
};
IActiveScriptSite script_site = { &ActiveScriptSiteVtbl };
static BOOL get_engine_clsid(const WCHAR *ext, CLSID *clsid)
{
WCHAR fileid[64], progid[64];
@ -68,8 +171,64 @@ static BOOL get_engine_clsid(const WCHAR *ext, CLSID *clsid)
return SUCCEEDED(hres);
}
static HRESULT create_engine(CLSID *clsid, IActiveScript **script_ret,
IActiveScriptParse **parser)
{
IActiveScript *script;
IUnknown *unk;
HRESULT hres;
hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
&IID_IUnknown, (void**)&unk);
if(FAILED(hres))
return FALSE;
hres = IUnknown_QueryInterface(unk, &IID_IActiveScript, (void**)&script);
IUnknown_Release(unk);
if(FAILED(hres))
return FALSE;
hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)parser);
if(FAILED(hres)) {
IActiveScript_Release(script);
return FALSE;
}
*script_ret = script;
return TRUE;
}
static HRESULT init_engine(IActiveScript *script, IActiveScriptParse *parser)
{
HRESULT hres;
static const WCHAR wscriptW[] = {'W','S','c','r','i','p','t',0};
static const WCHAR wshW[] = {'W','S','H',0};
hres = IActiveScript_SetScriptSite(script, &script_site);
if(FAILED(hres))
return FALSE;
hres = IActiveScriptParse64_InitNew(parser);
if(FAILED(hres))
return FALSE;
hres = IActiveScript_AddNamedItem(script, wscriptW, SCRIPTITEM_ISVISIBLE);
if(FAILED(hres))
return FALSE;
hres = IActiveScript_AddNamedItem(script, wshW, SCRIPTITEM_ISVISIBLE);
if(FAILED(hres))
return FALSE;
hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_INITIALIZED);
return SUCCEEDED(hres);
}
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
{
IActiveScriptParse *parser;
IActiveScript *script;
const WCHAR *ext;
CLSID clsid;
@ -86,5 +245,24 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cm
return 1;
}
CoInitialize(NULL);
if(!create_engine(&clsid, &script, &parser)) {
WINE_FIXME("Could not create script engine\n");
CoUninitialize();
return 1;
}
if(init_engine(script, parser)) {
IActiveScript_Close(script);
}else {
WINE_FIXME("Script initialization failed\n");
}
IActiveScript_Release(script);
IUnknown_Release(parser);
CoUninitialize();
return 0;
}