ReactOS 0.4.15-dev-7693-gd0e2924
script.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winuser.h"
#include "msidefs.h"
#include "msipriv.h"
#include "activscp.h"
#include "oleauto.h"
#include "wine/debug.h"
#include "msiserver.h"
Include dependency graph for script.c:

Go to the source code of this file.

Classes

struct  MsiActiveScriptSite
 

Macros

#define COBJMACROS
 
#define IActiveScriptParse_Release   IActiveScriptParse32_Release
 
#define IActiveScriptParse_InitNew   IActiveScriptParse32_InitNew
 
#define IActiveScriptParse_ParseScriptText   IActiveScriptParse32_ParseScriptText
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msi)
 
static MsiActiveScriptSiteimpl_from_IActiveScriptSite (IActiveScriptSite *iface)
 
static HRESULT WINAPI MsiActiveScriptSite_QueryInterface (IActiveScriptSite *iface, REFIID riid, void **obj)
 
static ULONG WINAPI MsiActiveScriptSite_AddRef (IActiveScriptSite *iface)
 
static ULONG WINAPI MsiActiveScriptSite_Release (IActiveScriptSite *iface)
 
static HRESULT WINAPI MsiActiveScriptSite_GetLCID (IActiveScriptSite *iface, LCID *plcid)
 
static HRESULT WINAPI MsiActiveScriptSite_GetItemInfo (IActiveScriptSite *iface, LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
 
static HRESULT WINAPI MsiActiveScriptSite_GetDocVersionString (IActiveScriptSite *iface, BSTR *pbstrVersion)
 
static HRESULT WINAPI MsiActiveScriptSite_OnScriptTerminate (IActiveScriptSite *iface, const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
 
static HRESULT WINAPI MsiActiveScriptSite_OnStateChange (IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
 
static HRESULT WINAPI MsiActiveScriptSite_OnScriptError (IActiveScriptSite *iface, IActiveScriptError *pscripterror)
 
static HRESULT WINAPI MsiActiveScriptSite_OnEnterScript (IActiveScriptSite *iface)
 
static HRESULT WINAPI MsiActiveScriptSite_OnLeaveScript (IActiveScriptSite *iface)
 
static HRESULT create_activescriptsite (MsiActiveScriptSite **obj)
 
static UINT map_return_value (LONG val)
 
DWORD call_script (MSIHANDLE hPackage, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action)
 

Variables

static const struct IActiveScriptSiteVtbl activescriptsitevtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file script.c.

◆ IActiveScriptParse_InitNew

#define IActiveScriptParse_InitNew   IActiveScriptParse32_InitNew

Definition at line 47 of file script.c.

◆ IActiveScriptParse_ParseScriptText

#define IActiveScriptParse_ParseScriptText   IActiveScriptParse32_ParseScriptText

Definition at line 48 of file script.c.

◆ IActiveScriptParse_Release

#define IActiveScriptParse_Release   IActiveScriptParse32_Release

Definition at line 46 of file script.c.

Function Documentation

◆ call_script()

DWORD call_script ( MSIHANDLE  hPackage,
INT  type,
LPCWSTR  script,
LPCWSTR  function,
LPCWSTR  action 
)

Definition at line 288 of file script.c.

289{
290 HRESULT hr;
291 IActiveScript *pActiveScript = NULL;
292 IActiveScriptParse *pActiveScriptParse = NULL;
293 MsiActiveScriptSite *scriptsite;
294 IDispatch *pDispatch = NULL;
295 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
296 DISPID dispid;
297 CLSID clsid;
298 VARIANT var;
300
302
303 /* Create MsiActiveScriptSite object */
304 hr = create_activescriptsite(&scriptsite);
305 if (hr != S_OK) goto done;
306
307 /* Create an installer object */
308 hr = create_msiserver(NULL, (void**)&scriptsite->installer);
309 if (hr != S_OK) goto done;
310
311 /* Create a session object */
312 hr = create_session(hPackage, scriptsite->installer, &scriptsite->session);
313 if (hr != S_OK) goto done;
314
315 /* Create the scripting engine */
318 hr = CLSIDFromProgID(L"JScript", &clsid);
320 hr = CLSIDFromProgID(L"VBScript", &clsid);
321 else {
322 ERR("Unknown script type %d\n", type);
323 goto done;
324 }
325 if (FAILED(hr)) {
326 ERR("Could not find CLSID for Windows Script\n");
327 goto done;
328 }
329 hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IActiveScript, (void **)&pActiveScript);
330 if (FAILED(hr)) {
331 ERR("Could not instantiate class for Windows Script\n");
332 goto done;
333 }
334
335 hr = IActiveScript_QueryInterface(pActiveScript, &IID_IActiveScriptParse, (void **)&pActiveScriptParse);
336 if (FAILED(hr)) goto done;
337
338 hr = IActiveScript_SetScriptSite(pActiveScript, &scriptsite->IActiveScriptSite_iface);
339 if (FAILED(hr)) goto done;
340
341 hr = IActiveScriptParse_InitNew(pActiveScriptParse);
342 if (FAILED(hr)) goto done;
343
344 hr = IActiveScript_AddNamedItem(pActiveScript, L"Session", SCRIPTITEM_GLOBALMEMBERS|SCRIPTITEM_ISVISIBLE);
345 if (FAILED(hr)) goto done;
346
347 hr = IActiveScriptParse_ParseScriptText(pActiveScriptParse, script, NULL, NULL, NULL, 0, 0, 0L, NULL, NULL);
348 if (FAILED(hr)) goto done;
349
350 hr = IActiveScript_SetScriptState(pActiveScript, SCRIPTSTATE_CONNECTED);
351 if (FAILED(hr)) goto done;
352
353 /* Call a function if necessary through the IDispatch interface */
354 if (function && function[0]) {
355 TRACE("Calling function %s\n", debugstr_w(function));
356
357 hr = IActiveScript_GetScriptDispatch(pActiveScript, NULL, &pDispatch);
358 if (FAILED(hr)) goto done;
359
360 hr = IDispatch_GetIDsOfNames(pDispatch, &IID_NULL, (WCHAR **)&function, 1,LOCALE_USER_DEFAULT, &dispid);
361 if (FAILED(hr)) goto done;
362
363 hr = IDispatch_Invoke(pDispatch, dispid, &IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, &var, NULL, NULL);
364 if (FAILED(hr)) goto done;
365
366 hr = VariantChangeType(&var, &var, 0, VT_I4);
367 if (FAILED(hr)) goto done;
368
370
372 } else {
373 /* If no function to be called, MSI behavior is to succeed */
375 }
376
377done:
378
379 if (pDispatch) IDispatch_Release(pDispatch);
380 if (pActiveScript) IActiveScript_Release(pActiveScript);
381 if (pActiveScriptParse) IActiveScriptParse_Release(pActiveScriptParse);
382 if (scriptsite)
383 {
384 if (scriptsite->session) IDispatch_Release(scriptsite->session);
385 if (scriptsite->installer) IDispatch_Release(scriptsite->installer);
386 IActiveScriptSite_Release(&scriptsite->IActiveScriptSite_iface);
387 }
388 CoUninitialize(); /* must call even if CoInitialize failed */
389 return ret;
390}
@ SCRIPTSTATE_CONNECTED
Definition: activscp.idl:59
#define ERR(fmt,...)
Definition: debug.h:110
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
@ VT_I4
Definition: compat.h:2298
#define IActiveScriptParse_InitNew
Definition: script.c:40
#define IActiveScriptParse_ParseScriptText
Definition: script.c:41
#define IActiveScriptParse_Release
Definition: script.c:39
HRESULT create_session(MSIHANDLE msiHandle, IDispatch *installer, IDispatch **disp)
Definition: automation.c:2440
HRESULT create_msiserver(IUnknown *outer, void **ppObj)
Definition: automation.c:2421
static UINT map_return_value(LONG val)
Definition: script.c:271
static HRESULT create_activescriptsite(MsiActiveScriptSite **obj)
Definition: script.c:249
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI DECLSPEC_HOTPATCH CLSIDFromProgID(LPCOLESTR progid, LPCLSID clsid)
Definition: compobj.c:2602
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_w
Definition: kernel32.h:32
const char * var
Definition: shader.c:5666
static VARIANTARG static DISPID
Definition: ordinal.c:52
REFCLSID clsid
Definition: msctf.c:82
@ msidbCustomActionTypeJScript
Definition: msidefs.h:119
@ msidbCustomActionTypeVBScript
Definition: msidefs.h:120
script
Definition: msipriv.h:383
struct stdole::DISPPARAMS DISPPARAMS
#define LOCALE_USER_DEFAULT
#define L(x)
Definition: ntvdm.h:50
#define DISPATCH_METHOD
Definition: oleauto.h:1006
#define V_I4(A)
Definition: oleauto.h:247
#define IID_NULL
Definition: guiddef.h:98
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
IDispatch * installer
Definition: script.c:57
IDispatch * session
Definition: script.c:58
IActiveScriptSite IActiveScriptSite_iface
Definition: script.c:56
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
int ret
#define ERROR_INSTALL_FAILURE
Definition: winerror.h:961
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ACTION_CallScript().

◆ create_activescriptsite()

static HRESULT create_activescriptsite ( MsiActiveScriptSite **  obj)
static

Definition at line 249 of file script.c.

250{
252
253 TRACE("(%p)\n", obj);
254
255 *obj = NULL;
256
257 object = msi_alloc( sizeof(MsiActiveScriptSite) );
258 if (!object)
259 return E_OUTOFMEMORY;
260
261 object->IActiveScriptSite_iface.lpVtbl = &activescriptsitevtbl;
262 object->ref = 1;
263 object->installer = NULL;
264 object->session = NULL;
265
266 *obj = object;
267
268 return S_OK;
269}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static const struct IActiveScriptSiteVtbl activescriptsitevtbl
Definition: script.c:234
static void * msi_alloc(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1142

Referenced by call_script().

◆ impl_from_IActiveScriptSite()

static MsiActiveScriptSite * impl_from_IActiveScriptSite ( IActiveScriptSite iface)
inlinestatic

Definition at line 62 of file script.c.

63{
64 return CONTAINING_RECORD(iface, MsiActiveScriptSite, IActiveScriptSite_iface);
65}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ map_return_value()

static UINT map_return_value ( LONG  val)
static

Definition at line 271 of file script.c.

272{
273 switch (val)
274 {
275 case 0:
276 case IDOK:
277 case IDIGNORE: return ERROR_SUCCESS;
278 case IDCANCEL: return ERROR_INSTALL_USEREXIT;
279 case IDRETRY: return ERROR_INSTALL_SUSPEND;
280 case IDABORT:
281 default: return ERROR_INSTALL_FAILURE;
282 }
283}
GLuint GLfloat * val
Definition: glext.h:7180
#define ERROR_INSTALL_USEREXIT
Definition: winerror.h:960
#define ERROR_INSTALL_SUSPEND
Definition: winerror.h:962
#define IDCANCEL
Definition: winuser.h:830
#define IDOK
Definition: winuser.h:829
#define IDIGNORE
Definition: winuser.h:833
#define IDABORT
Definition: winuser.h:831
#define IDRETRY
Definition: winuser.h:832

Referenced by call_script().

◆ MsiActiveScriptSite_AddRef()

static ULONG WINAPI MsiActiveScriptSite_AddRef ( IActiveScriptSite iface)
static

Definition at line 89 of file script.c.

90{
93 TRACE( "(%p)->(%lu)\n", This, ref );
94 return ref;
95}
#define InterlockedIncrement
Definition: armddk.h:53
static ScriptHost * impl_from_IActiveScriptSite(IActiveScriptSite *iface)
Definition: script.c:223
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ MsiActiveScriptSite_GetDocVersionString()

static HRESULT WINAPI MsiActiveScriptSite_GetDocVersionString ( IActiveScriptSite iface,
BSTR pbstrVersion 
)
static

Definition at line 150 of file script.c.

151{
153 TRACE("(%p)->(%p)\n", This, pbstrVersion);
154 return E_NOTIMPL;
155}
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ MsiActiveScriptSite_GetItemInfo()

static HRESULT WINAPI MsiActiveScriptSite_GetItemInfo ( IActiveScriptSite iface,
LPCOLESTR  pstrName,
DWORD  dwReturnMask,
IUnknown **  ppiunkItem,
ITypeInfo **  ppti 
)
static

Definition at line 117 of file script.c.

118{
120
121 TRACE( "(%p)->(%p, %lu, %p, %p)\n", This, pstrName, dwReturnMask, ppiunkItem, ppti );
122
123 /* Determine the kind of pointer that is requested, and make sure placeholder is valid */
124 if (dwReturnMask & SCRIPTINFO_ITYPEINFO) {
125 if (!ppti) return E_INVALIDARG;
126 *ppti = NULL;
127 }
128 if (dwReturnMask & SCRIPTINFO_IUNKNOWN) {
129 if (!ppiunkItem) return E_INVALIDARG;
130 *ppiunkItem = NULL;
131 }
132
133 /* Are we looking for the session object? */
134 if (!wcscmp(L"Session", pstrName)) {
135 if (dwReturnMask & SCRIPTINFO_ITYPEINFO) {
137 if (SUCCEEDED(hr))
138 ITypeInfo_AddRef(*ppti);
139 return hr;
140 }
141 else if (dwReturnMask & SCRIPTINFO_IUNKNOWN) {
142 IDispatch_QueryInterface(This->session, &IID_IUnknown, (void **)ppiunkItem);
143 return S_OK;
144 }
145 }
146
148}
HRESULT get_typeinfo(enum type_id tid, ITypeInfo **ret)
Definition: apps.c:124
const GUID IID_IUnknown
#define E_INVALIDARG
Definition: ddrawi.h:101
#define SUCCEEDED(hr)
Definition: intsafe.h:50
@ Session_tid
Definition: msipriv.h:1122
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define TYPE_E_ELEMENTNOTFOUND
Definition: winerror.h:2539

◆ MsiActiveScriptSite_GetLCID()

static HRESULT WINAPI MsiActiveScriptSite_GetLCID ( IActiveScriptSite iface,
LCID plcid 
)
static

Definition at line 110 of file script.c.

111{
113 TRACE("(%p)->(%p)\n", This, plcid);
114 return E_NOTIMPL; /* Script will use system-defined locale */
115}

◆ MsiActiveScriptSite_OnEnterScript()

static HRESULT WINAPI MsiActiveScriptSite_OnEnterScript ( IActiveScriptSite iface)
static

Definition at line 220 of file script.c.

221{
223 TRACE("(%p)\n", This);
224 return S_OK;
225}

◆ MsiActiveScriptSite_OnLeaveScript()

static HRESULT WINAPI MsiActiveScriptSite_OnLeaveScript ( IActiveScriptSite iface)
static

Definition at line 227 of file script.c.

228{
230 TRACE("(%p)\n", This);
231 return S_OK;
232}

◆ MsiActiveScriptSite_OnScriptError()

static HRESULT WINAPI MsiActiveScriptSite_OnScriptError ( IActiveScriptSite iface,
IActiveScriptError pscripterror 
)
static

Definition at line 199 of file script.c.

200{
203 HRESULT hr;
204
205 TRACE("(%p)->(%p)\n", This, pscripterror);
206
207 memset(&exception, 0, sizeof(EXCEPINFO));
208 hr = IActiveScriptError_GetExceptionInfo(pscripterror, &exception);
209 if (SUCCEEDED(hr))
210 {
211 ERR("script error: %s\n", debugstr_w(exception.bstrDescription));
212 SysFreeString(exception.bstrSource);
213 SysFreeString(exception.bstrDescription);
214 SysFreeString(exception.bstrHelpFile);
215 }
216
217 return S_OK;
218}
#define exception
Definition: math.h:26
struct stdole::EXCEPINFO EXCEPINFO
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
#define memset(x, y, z)
Definition: compat.h:39

◆ MsiActiveScriptSite_OnScriptTerminate()

static HRESULT WINAPI MsiActiveScriptSite_OnScriptTerminate ( IActiveScriptSite iface,
const VARIANT pvarResult,
const EXCEPINFO *  pexcepinfo 
)
static

Definition at line 157 of file script.c.

158{
160 TRACE("(%p)->(%p, %p)\n", This, pvarResult, pexcepinfo);
161 return S_OK;
162}

◆ MsiActiveScriptSite_OnStateChange()

static HRESULT WINAPI MsiActiveScriptSite_OnStateChange ( IActiveScriptSite iface,
SCRIPTSTATE  ssScriptState 
)
static

Definition at line 164 of file script.c.

165{
166 switch (ssScriptState) {
168 TRACE("State: Uninitialized.\n");
169 break;
170
172 TRACE("State: Initialized.\n");
173 break;
174
176 TRACE("State: Started.\n");
177 break;
178
180 TRACE("State: Connected.\n");
181 break;
182
184 TRACE("State: Disconnected.\n");
185 break;
186
188 TRACE("State: Closed.\n");
189 break;
190
191 default:
192 ERR("Unknown State: %d\n", ssScriptState);
193 break;
194 }
195
196 return S_OK;
197}
@ SCRIPTSTATE_INITIALIZED
Definition: activscp.idl:62
@ SCRIPTSTATE_DISCONNECTED
Definition: activscp.idl:60
@ SCRIPTSTATE_STARTED
Definition: activscp.idl:58
@ SCRIPTSTATE_UNINITIALIZED
Definition: activscp.idl:57
@ SCRIPTSTATE_CLOSED
Definition: activscp.idl:61

◆ MsiActiveScriptSite_QueryInterface()

static HRESULT WINAPI MsiActiveScriptSite_QueryInterface ( IActiveScriptSite iface,
REFIID  riid,
void **  obj 
)
static

Definition at line 70 of file script.c.

71{
73
74 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), obj);
75
77 IsEqualGUID(riid, &IID_IActiveScriptSite))
78 {
79 IActiveScriptSite_AddRef(iface);
80 *obj = iface;
81 return S_OK;
82 }
83
84 *obj = NULL;
85
86 return E_NOINTERFACE;
87}
REFIID riid
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ MsiActiveScriptSite_Release()

static ULONG WINAPI MsiActiveScriptSite_Release ( IActiveScriptSite iface)
static

Definition at line 97 of file script.c.

98{
101
102 TRACE( "(%p)->(%lu)\n", This, ref );
103
104 if (!ref)
105 msi_free(This);
106
107 return ref;
108}
#define InterlockedDecrement
Definition: armddk.h:52
static void msi_free(void *mem)
Definition: msipriv.h:1159

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msi  )

Variable Documentation

◆ activescriptsitevtbl

const struct IActiveScriptSiteVtbl activescriptsitevtbl
static
Initial value:
=
{
}
static ULONG WINAPI MsiActiveScriptSite_AddRef(IActiveScriptSite *iface)
Definition: script.c:89
static ULONG WINAPI MsiActiveScriptSite_Release(IActiveScriptSite *iface)
Definition: script.c:97
static HRESULT WINAPI MsiActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
Definition: script.c:110
static HRESULT WINAPI MsiActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
Definition: script.c:117
static HRESULT WINAPI MsiActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
Definition: script.c:227
static HRESULT WINAPI MsiActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **obj)
Definition: script.c:70
static HRESULT WINAPI MsiActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
Definition: script.c:220
static HRESULT WINAPI MsiActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
Definition: script.c:199
static HRESULT WINAPI MsiActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface, const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
Definition: script.c:157
static HRESULT WINAPI MsiActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
Definition: script.c:150
static HRESULT WINAPI MsiActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
Definition: script.c:164

Definition at line 234 of file script.c.

Referenced by create_activescriptsite().