2 * Copyright 2011 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
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
38 #define CTXARG_T DWORDLONG
39 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
43 #define CTXARG_T DWORD
44 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
49 IActiveScript IActiveScript_iface;
50 IActiveScriptParse IActiveScriptParse_iface;
55 IActiveScriptSite *site;
61 static void change_state(VBScript *This, SCRIPTSTATE state)
63 if(This->state == state)
68 IActiveScriptSite_OnStateChange(This->site, state);
71 static HRESULT set_ctx_site(VBScript *This)
73 This->ctx->lcid = This->lcid;
75 IActiveScriptSite_AddRef(This->site);
76 This->ctx->site = This->site;
78 change_state(This, SCRIPTSTATE_INITIALIZED);
82 static void destroy_script(script_ctx_t *ctx)
85 IActiveScriptSite_Release(ctx->site);
89 static void decrease_state(VBScript *This, SCRIPTSTATE state)
92 case SCRIPTSTATE_CONNECTED:
93 case SCRIPTSTATE_STARTED:
94 case SCRIPTSTATE_DISCONNECTED:
95 FIXME("unimplemented state %d\n", This->state);
96 if(state == SCRIPTSTATE_INITIALIZED)
99 case SCRIPTSTATE_INITIALIZED:
100 destroy_script(This->ctx);
104 change_state(This, state);
105 if(state == SCRIPTSTATE_UNINITIALIZED)
108 case SCRIPTSTATE_UNINITIALIZED:
110 IActiveScriptSite_Release(This->site);
120 static inline VBScript *impl_from_IActiveScript(IActiveScript *iface)
122 return CONTAINING_RECORD(iface, VBScript, IActiveScript_iface);
125 static HRESULT WINAPI VBScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
127 VBScript *This = impl_from_IActiveScript(iface);
129 if(IsEqualGUID(riid, &IID_IUnknown)) {
130 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
131 *ppv = &This->IActiveScript_iface;
132 }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
133 TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
134 *ppv = &This->IActiveScript_iface;
135 }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
136 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
137 *ppv = &This->IActiveScriptParse_iface;
139 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
141 return E_NOINTERFACE;
144 IUnknown_AddRef((IUnknown*)*ppv);
148 static ULONG WINAPI VBScript_AddRef(IActiveScript *iface)
150 VBScript *This = impl_from_IActiveScript(iface);
151 LONG ref = InterlockedIncrement(&This->ref);
153 TRACE("(%p) ref=%d\n", This, ref);
158 static ULONG WINAPI VBScript_Release(IActiveScript *iface)
160 VBScript *This = impl_from_IActiveScript(iface);
161 LONG ref = InterlockedDecrement(&This->ref);
163 TRACE("(%p) ref=%d\n", iface, ref);
167 IActiveScriptSite_Release(This->site);
174 static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
176 VBScript *This = impl_from_IActiveScript(iface);
180 TRACE("(%p)->(%p)\n", This, pass);
188 if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
192 IActiveScriptSite_AddRef(This->site);
194 hres = IActiveScriptSite_GetLCID(This->site, &lcid);
198 return This->ctx ? set_ctx_site(This) : S_OK;
201 static HRESULT WINAPI VBScript_GetScriptSite(IActiveScript *iface, REFIID riid,
204 VBScript *This = impl_from_IActiveScript(iface);
205 FIXME("(%p)->()\n", This);
209 static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
211 VBScript *This = impl_from_IActiveScript(iface);
212 FIXME("(%p)->(%d)\n", This, ss);
216 static HRESULT WINAPI VBScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
218 VBScript *This = impl_from_IActiveScript(iface);
219 FIXME("(%p)->(%p)\n", This, pssState);
223 static HRESULT WINAPI VBScript_Close(IActiveScript *iface)
225 VBScript *This = impl_from_IActiveScript(iface);
227 TRACE("(%p)->()\n", This);
229 if(This->thread_id && This->thread_id != GetCurrentThreadId())
232 decrease_state(This, SCRIPTSTATE_CLOSED);
236 static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
238 VBScript *This = impl_from_IActiveScript(iface);
239 FIXME("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
243 static HRESULT WINAPI VBScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
244 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
246 VBScript *This = impl_from_IActiveScript(iface);
247 FIXME("(%p)->()\n", This);
251 static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName, IDispatch **ppdisp)
253 VBScript *This = impl_from_IActiveScript(iface);
254 FIXME("(%p)->(%p)\n", This, ppdisp);
258 static HRESULT WINAPI VBScript_GetCurrentScriptThreadID(IActiveScript *iface,
259 SCRIPTTHREADID *pstridThread)
261 VBScript *This = impl_from_IActiveScript(iface);
262 FIXME("(%p)->()\n", This);
266 static HRESULT WINAPI VBScript_GetScriptThreadID(IActiveScript *iface,
267 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
269 VBScript *This = impl_from_IActiveScript(iface);
270 FIXME("(%p)->()\n", This);
274 static HRESULT WINAPI VBScript_GetScriptThreadState(IActiveScript *iface,
275 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
277 VBScript *This = impl_from_IActiveScript(iface);
278 FIXME("(%p)->()\n", This);
282 static HRESULT WINAPI VBScript_InterruptScriptThread(IActiveScript *iface,
283 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
285 VBScript *This = impl_from_IActiveScript(iface);
286 FIXME("(%p)->()\n", This);
290 static HRESULT WINAPI VBScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
292 VBScript *This = impl_from_IActiveScript(iface);
293 FIXME("(%p)->()\n", This);
297 static const IActiveScriptVtbl VBScriptVtbl = {
298 VBScript_QueryInterface,
301 VBScript_SetScriptSite,
302 VBScript_GetScriptSite,
303 VBScript_SetScriptState,
304 VBScript_GetScriptState,
306 VBScript_AddNamedItem,
308 VBScript_GetScriptDispatch,
309 VBScript_GetCurrentScriptThreadID,
310 VBScript_GetScriptThreadID,
311 VBScript_GetScriptThreadState,
312 VBScript_InterruptScriptThread,
316 static inline VBScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
318 return CONTAINING_RECORD(iface, VBScript, IActiveScriptParse_iface);
321 static HRESULT WINAPI VBScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
323 VBScript *This = impl_from_IActiveScriptParse(iface);
324 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
327 static ULONG WINAPI VBScriptParse_AddRef(IActiveScriptParse *iface)
329 VBScript *This = impl_from_IActiveScriptParse(iface);
330 return IActiveScript_AddRef(&This->IActiveScript_iface);
333 static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
335 VBScript *This = impl_from_IActiveScriptParse(iface);
336 return IActiveScript_Release(&This->IActiveScript_iface);
339 static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
341 VBScript *This = impl_from_IActiveScriptParse(iface);
344 TRACE("(%p)\n", This);
349 ctx = heap_alloc_zero(sizeof(script_ctx_t));
351 return E_OUTOFMEMORY;
353 ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
359 return This->site ? set_ctx_site(This) : S_OK;
362 static HRESULT WINAPI VBScriptParse_AddScriptlet(IActiveScriptParse *iface,
363 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
364 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
365 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
366 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
368 VBScript *This = impl_from_IActiveScriptParse(iface);
369 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
370 debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
371 debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
372 ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
376 static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
377 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
378 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
379 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
381 VBScript *This = impl_from_IActiveScriptParse(iface);
382 FIXME("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
383 debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
384 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
388 static const IActiveScriptParseVtbl VBScriptParseVtbl = {
389 VBScriptParse_QueryInterface,
390 VBScriptParse_AddRef,
391 VBScriptParse_Release,
392 VBScriptParse_InitNew,
393 VBScriptParse_AddScriptlet,
394 VBScriptParse_ParseScriptText
397 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
402 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
404 ret = heap_alloc_zero(sizeof(*ret));
406 return E_OUTOFMEMORY;
408 ret->IActiveScript_iface.lpVtbl = &VBScriptVtbl;
409 ret->IActiveScriptParse_iface.lpVtbl = &VBScriptParseVtbl;
412 ret->state = SCRIPTSTATE_UNINITIALIZED;
414 hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
415 IActiveScript_Release(&ret->IActiveScript_iface);