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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(vbscript
);
31 #define CTXARG_T DWORDLONG
32 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
33 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
37 #define CTXARG_T DWORD
38 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
39 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
44 IActiveScript IActiveScript_iface
;
45 IActiveScriptParse IActiveScriptParse_iface
;
46 IActiveScriptParseProcedure2 IActiveScriptParseProcedure2_iface
;
47 IObjectSafety IObjectSafety_iface
;
53 IActiveScriptSite
*site
;
59 static void change_state(VBScript
*This
, SCRIPTSTATE state
)
61 if(This
->state
== state
)
66 IActiveScriptSite_OnStateChange(This
->site
, state
);
69 static inline BOOL
is_started(VBScript
*This
)
71 return This
->state
== SCRIPTSTATE_STARTED
72 || This
->state
== SCRIPTSTATE_CONNECTED
73 || This
->state
== SCRIPTSTATE_DISCONNECTED
;
76 static HRESULT
exec_global_code(script_ctx_t
*ctx
, vbscode_t
*code
)
80 code
->pending_exec
= FALSE
;
82 IActiveScriptSite_OnEnterScript(ctx
->site
);
83 hres
= exec_script(ctx
, &code
->main_code
, NULL
, NULL
, NULL
);
84 IActiveScriptSite_OnLeaveScript(ctx
->site
);
89 static void exec_queued_code(script_ctx_t
*ctx
)
93 LIST_FOR_EACH_ENTRY(iter
, &ctx
->code_list
, vbscode_t
, entry
) {
94 if(iter
->pending_exec
)
95 exec_global_code(ctx
, iter
);
99 static HRESULT
set_ctx_site(VBScript
*This
)
103 This
->ctx
->lcid
= This
->lcid
;
105 hres
= init_global(This
->ctx
);
109 IActiveScriptSite_AddRef(This
->site
);
110 This
->ctx
->site
= This
->site
;
112 change_state(This
, SCRIPTSTATE_INITIALIZED
);
116 static void release_script(script_ctx_t
*ctx
)
118 class_desc_t
*class_desc
;
120 collect_objects(ctx
);
122 release_dynamic_vars(ctx
->global_vars
);
123 ctx
->global_vars
= NULL
;
125 while(!list_empty(&ctx
->named_items
)) {
126 named_item_t
*iter
= LIST_ENTRY(list_head(&ctx
->named_items
), named_item_t
, entry
);
128 list_remove(&iter
->entry
);
130 IDispatch_Release(iter
->disp
);
131 heap_free(iter
->name
);
136 class_desc
= ctx
->procs
;
137 ctx
->procs
= class_desc
->next
;
139 heap_free(class_desc
);
142 if(ctx
->host_global
) {
143 IDispatch_Release(ctx
->host_global
);
144 ctx
->host_global
= NULL
;
148 IInternetHostSecurityManager_Release(ctx
->secmgr
);
153 IActiveScriptSite_Release(ctx
->site
);
158 IDispatchEx_Release(&ctx
->err_obj
->IDispatchEx_iface
);
162 if(ctx
->global_obj
) {
163 IDispatchEx_Release(&ctx
->global_obj
->IDispatchEx_iface
);
164 ctx
->global_obj
= NULL
;
167 if(ctx
->script_obj
) {
168 ScriptDisp
*script_obj
= ctx
->script_obj
;
170 ctx
->script_obj
= NULL
;
171 script_obj
->ctx
= NULL
;
172 IDispatchEx_Release(&script_obj
->IDispatchEx_iface
);
175 heap_pool_free(&ctx
->heap
);
176 heap_pool_init(&ctx
->heap
);
179 static void destroy_script(script_ctx_t
*ctx
)
181 while(!list_empty(&ctx
->code_list
))
182 release_vbscode(LIST_ENTRY(list_head(&ctx
->code_list
), vbscode_t
, entry
));
188 static void decrease_state(VBScript
*This
, SCRIPTSTATE state
)
190 switch(This
->state
) {
191 case SCRIPTSTATE_CONNECTED
:
192 change_state(This
, SCRIPTSTATE_DISCONNECTED
);
193 if(state
== SCRIPTSTATE_DISCONNECTED
)
196 case SCRIPTSTATE_STARTED
:
197 case SCRIPTSTATE_DISCONNECTED
:
198 if(This
->state
== SCRIPTSTATE_DISCONNECTED
)
199 change_state(This
, SCRIPTSTATE_INITIALIZED
);
200 if(state
== SCRIPTSTATE_INITIALIZED
)
203 case SCRIPTSTATE_INITIALIZED
:
204 case SCRIPTSTATE_UNINITIALIZED
:
205 change_state(This
, state
);
208 IActiveScriptSite_Release(This
->site
);
213 release_script(This
->ctx
);
217 case SCRIPTSTATE_CLOSED
:
223 static inline VBScript
*impl_from_IActiveScript(IActiveScript
*iface
)
225 return CONTAINING_RECORD(iface
, VBScript
, IActiveScript_iface
);
228 static HRESULT WINAPI
VBScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
230 VBScript
*This
= impl_from_IActiveScript(iface
);
232 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
233 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
234 *ppv
= &This
->IActiveScript_iface
;
235 }else if(IsEqualGUID(riid
, &IID_IActiveScript
)) {
236 TRACE("(%p)->(IID_IActiveScript %p)\n", This
, ppv
);
237 *ppv
= &This
->IActiveScript_iface
;
238 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParse
)) {
239 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This
, ppv
);
240 *ppv
= &This
->IActiveScriptParse_iface
;
241 }else if(IsEqualGUID(riid
, &IID_IActiveScriptParseProcedure2
)) {
242 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This
, ppv
);
243 *ppv
= &This
->IActiveScriptParseProcedure2_iface
;
244 }else if(IsEqualGUID(riid
, &IID_IObjectSafety
)) {
245 TRACE("(%p)->(IID_IObjectSafety %p)\n", This
, ppv
);
246 *ppv
= &This
->IObjectSafety_iface
;
248 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
250 return E_NOINTERFACE
;
253 IUnknown_AddRef((IUnknown
*)*ppv
);
257 static ULONG WINAPI
VBScript_AddRef(IActiveScript
*iface
)
259 VBScript
*This
= impl_from_IActiveScript(iface
);
260 LONG ref
= InterlockedIncrement(&This
->ref
);
262 TRACE("(%p) ref=%d\n", This
, ref
);
267 static ULONG WINAPI
VBScript_Release(IActiveScript
*iface
)
269 VBScript
*This
= impl_from_IActiveScript(iface
);
270 LONG ref
= InterlockedDecrement(&This
->ref
);
272 TRACE("(%p) ref=%d\n", iface
, ref
);
276 decrease_state(This
, SCRIPTSTATE_CLOSED
);
277 destroy_script(This
->ctx
);
281 IActiveScriptSite_Release(This
->site
);
288 static HRESULT WINAPI
VBScript_SetScriptSite(IActiveScript
*iface
, IActiveScriptSite
*pass
)
290 VBScript
*This
= impl_from_IActiveScript(iface
);
294 TRACE("(%p)->(%p)\n", This
, pass
);
302 if(InterlockedCompareExchange(&This
->thread_id
, GetCurrentThreadId(), 0))
306 IActiveScriptSite_AddRef(This
->site
);
308 hres
= IActiveScriptSite_GetLCID(This
->site
, &lcid
);
312 return This
->ctx
? set_ctx_site(This
) : S_OK
;
315 static HRESULT WINAPI
VBScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
318 VBScript
*This
= impl_from_IActiveScript(iface
);
319 FIXME("(%p)->()\n", This
);
323 static HRESULT WINAPI
VBScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
325 VBScript
*This
= impl_from_IActiveScript(iface
);
327 TRACE("(%p)->(%d)\n", This
, ss
);
329 if(This
->thread_id
&& GetCurrentThreadId() != This
->thread_id
)
332 if(ss
== SCRIPTSTATE_UNINITIALIZED
) {
333 if(This
->state
== SCRIPTSTATE_CLOSED
)
336 decrease_state(This
, SCRIPTSTATE_UNINITIALIZED
);
344 case SCRIPTSTATE_STARTED
:
345 case SCRIPTSTATE_CONNECTED
: /* FIXME */
346 if(This
->state
== SCRIPTSTATE_CLOSED
)
349 exec_queued_code(This
->ctx
);
351 case SCRIPTSTATE_INITIALIZED
:
352 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
355 FIXME("unimplemented state %d\n", ss
);
359 change_state(This
, ss
);
363 static HRESULT WINAPI
VBScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
365 VBScript
*This
= impl_from_IActiveScript(iface
);
367 TRACE("(%p)->(%p)\n", This
, pssState
);
372 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
375 *pssState
= This
->state
;
379 static HRESULT WINAPI
VBScript_Close(IActiveScript
*iface
)
381 VBScript
*This
= impl_from_IActiveScript(iface
);
383 TRACE("(%p)->()\n", This
);
385 if(This
->thread_id
&& This
->thread_id
!= GetCurrentThreadId())
388 decrease_state(This
, SCRIPTSTATE_CLOSED
);
392 static HRESULT WINAPI
VBScript_AddNamedItem(IActiveScript
*iface
, LPCOLESTR pstrName
, DWORD dwFlags
)
394 VBScript
*This
= impl_from_IActiveScript(iface
);
396 IDispatch
*disp
= NULL
;
399 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(pstrName
), dwFlags
);
401 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| This
->state
== SCRIPTSTATE_CLOSED
)
404 if(dwFlags
& SCRIPTITEM_GLOBALMEMBERS
) {
407 hres
= IActiveScriptSite_GetItemInfo(This
->site
, pstrName
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
409 WARN("GetItemInfo failed: %08x\n", hres
);
413 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
414 IUnknown_Release(unk
);
416 WARN("object does not implement IDispatch\n");
420 if(This
->ctx
->host_global
)
421 IDispatch_Release(This
->ctx
->host_global
);
422 IDispatch_AddRef(disp
);
423 This
->ctx
->host_global
= disp
;
426 item
= heap_alloc(sizeof(*item
));
429 IDispatch_Release(disp
);
430 return E_OUTOFMEMORY
;
434 item
->flags
= dwFlags
;
435 item
->name
= heap_strdupW(pstrName
);
438 IDispatch_Release(disp
);
440 return E_OUTOFMEMORY
;
443 list_add_tail(&This
->ctx
->named_items
, &item
->entry
);
447 static HRESULT WINAPI
VBScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
448 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
450 VBScript
*This
= impl_from_IActiveScript(iface
);
451 FIXME("(%p)->()\n", This
);
455 static HRESULT WINAPI
VBScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
, IDispatch
**ppdisp
)
457 VBScript
*This
= impl_from_IActiveScript(iface
);
459 TRACE("(%p)->(%p)\n", This
, ppdisp
);
464 if(This
->thread_id
!= GetCurrentThreadId() || !This
->ctx
|| !This
->ctx
->script_obj
) {
469 *ppdisp
= (IDispatch
*)&This
->ctx
->script_obj
->IDispatchEx_iface
;
470 IDispatch_AddRef(*ppdisp
);
474 static HRESULT WINAPI
VBScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
475 SCRIPTTHREADID
*pstridThread
)
477 VBScript
*This
= impl_from_IActiveScript(iface
);
478 FIXME("(%p)->()\n", This
);
482 static HRESULT WINAPI
VBScript_GetScriptThreadID(IActiveScript
*iface
,
483 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
485 VBScript
*This
= impl_from_IActiveScript(iface
);
486 FIXME("(%p)->()\n", This
);
490 static HRESULT WINAPI
VBScript_GetScriptThreadState(IActiveScript
*iface
,
491 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
493 VBScript
*This
= impl_from_IActiveScript(iface
);
494 FIXME("(%p)->()\n", This
);
498 static HRESULT WINAPI
VBScript_InterruptScriptThread(IActiveScript
*iface
,
499 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
501 VBScript
*This
= impl_from_IActiveScript(iface
);
502 FIXME("(%p)->()\n", This
);
506 static HRESULT WINAPI
VBScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
508 VBScript
*This
= impl_from_IActiveScript(iface
);
509 FIXME("(%p)->()\n", This
);
513 static const IActiveScriptVtbl VBScriptVtbl
= {
514 VBScript_QueryInterface
,
517 VBScript_SetScriptSite
,
518 VBScript_GetScriptSite
,
519 VBScript_SetScriptState
,
520 VBScript_GetScriptState
,
522 VBScript_AddNamedItem
,
524 VBScript_GetScriptDispatch
,
525 VBScript_GetCurrentScriptThreadID
,
526 VBScript_GetScriptThreadID
,
527 VBScript_GetScriptThreadState
,
528 VBScript_InterruptScriptThread
,
532 static inline VBScript
*impl_from_IActiveScriptParse(IActiveScriptParse
*iface
)
534 return CONTAINING_RECORD(iface
, VBScript
, IActiveScriptParse_iface
);
537 static HRESULT WINAPI
VBScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
539 VBScript
*This
= impl_from_IActiveScriptParse(iface
);
540 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
543 static ULONG WINAPI
VBScriptParse_AddRef(IActiveScriptParse
*iface
)
545 VBScript
*This
= impl_from_IActiveScriptParse(iface
);
546 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
549 static ULONG WINAPI
VBScriptParse_Release(IActiveScriptParse
*iface
)
551 VBScript
*This
= impl_from_IActiveScriptParse(iface
);
552 return IActiveScript_Release(&This
->IActiveScript_iface
);
555 static HRESULT WINAPI
VBScriptParse_InitNew(IActiveScriptParse
*iface
)
557 VBScript
*This
= impl_from_IActiveScriptParse(iface
);
558 script_ctx_t
*ctx
, *old_ctx
;
560 TRACE("(%p)\n", This
);
565 ctx
= heap_alloc_zero(sizeof(script_ctx_t
));
567 return E_OUTOFMEMORY
;
569 ctx
->safeopt
= This
->safeopt
;
570 heap_pool_init(&ctx
->heap
);
571 list_init(&ctx
->objects
);
572 list_init(&ctx
->code_list
);
573 list_init(&ctx
->named_items
);
575 old_ctx
= InterlockedCompareExchangePointer((void**)&This
->ctx
, ctx
, NULL
);
581 return This
->site
? set_ctx_site(This
) : S_OK
;
584 static HRESULT WINAPI
VBScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
585 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
586 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
587 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
588 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
590 VBScript
*This
= impl_from_IActiveScriptParse(iface
);
591 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This
, debugstr_w(pstrDefaultName
),
592 debugstr_w(pstrCode
), debugstr_w(pstrItemName
), debugstr_w(pstrSubItemName
),
593 debugstr_w(pstrEventName
), debugstr_w(pstrDelimiter
), wine_dbgstr_longlong(dwSourceContextCookie
),
594 ulStartingLineNumber
, dwFlags
, pbstrName
, pexcepinfo
);
598 static HRESULT WINAPI
VBScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
599 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
600 LPCOLESTR pstrDelimiter
, CTXARG_T dwSourceContextCookie
, ULONG ulStartingLine
,
601 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
603 VBScript
*This
= impl_from_IActiveScriptParse(iface
);
607 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This
, debugstr_w(pstrCode
),
608 debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
609 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLine
, dwFlags
, pvarResult
, pexcepinfo
);
611 if(This
->thread_id
!= GetCurrentThreadId() || This
->state
== SCRIPTSTATE_CLOSED
)
614 hres
= compile_script(This
->ctx
, pstrCode
, pstrDelimiter
, &code
);
618 if(!is_started(This
)) {
619 code
->pending_exec
= TRUE
;
623 return exec_global_code(This
->ctx
, code
);
626 static const IActiveScriptParseVtbl VBScriptParseVtbl
= {
627 VBScriptParse_QueryInterface
,
628 VBScriptParse_AddRef
,
629 VBScriptParse_Release
,
630 VBScriptParse_InitNew
,
631 VBScriptParse_AddScriptlet
,
632 VBScriptParse_ParseScriptText
635 static inline VBScript
*impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2
*iface
)
637 return CONTAINING_RECORD(iface
, VBScript
, IActiveScriptParseProcedure2_iface
);
640 static HRESULT WINAPI
VBScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
642 VBScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
643 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
646 static ULONG WINAPI
VBScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
648 VBScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
649 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
652 static ULONG WINAPI
VBScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
654 VBScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
655 return IActiveScript_Release(&This
->IActiveScript_iface
);
658 static HRESULT WINAPI
VBScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
659 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
660 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
661 CTXARG_T dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
663 VBScript
*This
= impl_from_IActiveScriptParseProcedure2(iface
);
667 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This
, debugstr_w(pstrCode
), debugstr_w(pstrFormalParams
),
668 debugstr_w(pstrProcedureName
), debugstr_w(pstrItemName
), punkContext
, debugstr_w(pstrDelimiter
),
669 wine_dbgstr_longlong(dwSourceContextCookie
), ulStartingLineNumber
, dwFlags
, ppdisp
);
671 if(This
->thread_id
!= GetCurrentThreadId() || This
->state
== SCRIPTSTATE_CLOSED
)
674 hres
= compile_script(This
->ctx
, pstrCode
, pstrDelimiter
, &code
);
678 return create_procedure_disp(This
->ctx
, code
, ppdisp
);
681 static const IActiveScriptParseProcedure2Vtbl VBScriptParseProcedureVtbl
= {
682 VBScriptParseProcedure_QueryInterface
,
683 VBScriptParseProcedure_AddRef
,
684 VBScriptParseProcedure_Release
,
685 VBScriptParseProcedure_ParseProcedureText
,
688 static inline VBScript
*impl_from_IObjectSafety(IObjectSafety
*iface
)
690 return CONTAINING_RECORD(iface
, VBScript
, IObjectSafety_iface
);
693 static HRESULT WINAPI
VBScriptSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
695 VBScript
*This
= impl_from_IObjectSafety(iface
);
696 return IActiveScript_QueryInterface(&This
->IActiveScript_iface
, riid
, ppv
);
699 static ULONG WINAPI
VBScriptSafety_AddRef(IObjectSafety
*iface
)
701 VBScript
*This
= impl_from_IObjectSafety(iface
);
702 return IActiveScript_AddRef(&This
->IActiveScript_iface
);
705 static ULONG WINAPI
VBScriptSafety_Release(IObjectSafety
*iface
)
707 VBScript
*This
= impl_from_IObjectSafety(iface
);
708 return IActiveScript_Release(&This
->IActiveScript_iface
);
711 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
713 static HRESULT WINAPI
VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
714 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
716 VBScript
*This
= impl_from_IObjectSafety(iface
);
718 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
720 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
723 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
724 *pdwEnabledOptions
= This
->safeopt
;
728 static HRESULT WINAPI
VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
729 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
731 VBScript
*This
= impl_from_IObjectSafety(iface
);
733 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
735 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
738 This
->safeopt
= (dwEnabledOptions
& dwOptionSetMask
) | (This
->safeopt
& ~dwOptionSetMask
) | INTERFACE_USES_DISPEX
;
742 static const IObjectSafetyVtbl VBScriptSafetyVtbl
= {
743 VBScriptSafety_QueryInterface
,
744 VBScriptSafety_AddRef
,
745 VBScriptSafety_Release
,
746 VBScriptSafety_GetInterfaceSafetyOptions
,
747 VBScriptSafety_SetInterfaceSafetyOptions
750 HRESULT WINAPI
VBScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
755 TRACE("(%p %s %p)\n", pUnkOuter
, debugstr_guid(riid
), ppv
);
757 ret
= heap_alloc_zero(sizeof(*ret
));
759 return E_OUTOFMEMORY
;
761 ret
->IActiveScript_iface
.lpVtbl
= &VBScriptVtbl
;
762 ret
->IActiveScriptParse_iface
.lpVtbl
= &VBScriptParseVtbl
;
763 ret
->IActiveScriptParseProcedure2_iface
.lpVtbl
= &VBScriptParseProcedureVtbl
;
764 ret
->IObjectSafety_iface
.lpVtbl
= &VBScriptSafetyVtbl
;
767 ret
->state
= SCRIPTSTATE_UNINITIALIZED
;
768 ret
->safeopt
= INTERFACE_USES_DISPEX
;
770 hres
= IActiveScript_QueryInterface(&ret
->IActiveScript_iface
, riid
, ppv
);
771 IActiveScript_Release(&ret
->IActiveScript_iface
);
776 IServiceProvider IServiceProvider_iface
;
780 IServiceProvider
*sp
;
783 static inline AXSite
*impl_from_IServiceProvider(IServiceProvider
*iface
)
785 return CONTAINING_RECORD(iface
, AXSite
, IServiceProvider_iface
);
788 static HRESULT WINAPI
AXSite_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
790 AXSite
*This
= impl_from_IServiceProvider(iface
);
792 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
793 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
794 *ppv
= &This
->IServiceProvider_iface
;
795 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
796 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
797 *ppv
= &This
->IServiceProvider_iface
;
799 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
801 return E_NOINTERFACE
;
804 IUnknown_AddRef((IUnknown
*)*ppv
);
808 static ULONG WINAPI
AXSite_AddRef(IServiceProvider
*iface
)
810 AXSite
*This
= impl_from_IServiceProvider(iface
);
811 LONG ref
= InterlockedIncrement(&This
->ref
);
813 TRACE("(%p) ref=%d\n", This
, ref
);
818 static ULONG WINAPI
AXSite_Release(IServiceProvider
*iface
)
820 AXSite
*This
= impl_from_IServiceProvider(iface
);
821 LONG ref
= InterlockedDecrement(&This
->ref
);
823 TRACE("(%p) ref=%d\n", This
, ref
);
831 static HRESULT WINAPI
AXSite_QueryService(IServiceProvider
*iface
,
832 REFGUID guidService
, REFIID riid
, void **ppv
)
834 AXSite
*This
= impl_from_IServiceProvider(iface
);
836 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
838 return IServiceProvider_QueryService(This
->sp
, guidService
, riid
, ppv
);
841 static IServiceProviderVtbl AXSiteVtbl
= {
842 AXSite_QueryInterface
,
848 IUnknown
*create_ax_site(script_ctx_t
*ctx
)
850 IServiceProvider
*sp
;
854 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
856 ERR("Could not get IServiceProvider iface: %08x\n", hres
);
860 ret
= heap_alloc(sizeof(*ret
));
862 IServiceProvider_Release(sp
);
866 ret
->IServiceProvider_iface
.lpVtbl
= &AXSiteVtbl
;
870 return (IUnknown
*)&ret
->IServiceProvider_iface
;