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 vbsheap_free(&ctx->heap);
176 vbsheap_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:
224 static inline VBScript *impl_from_IActiveScript(IActiveScript *iface)
226 return CONTAINING_RECORD(iface, VBScript, IActiveScript_iface);
229 static HRESULT WINAPI VBScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
231 VBScript *This = impl_from_IActiveScript(iface);
233 if(IsEqualGUID(riid, &IID_IUnknown)) {
234 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
235 *ppv = &This->IActiveScript_iface;
236 }else if(IsEqualGUID(riid, &IID_IActiveScript)) {
237 TRACE("(%p)->(IID_IActiveScript %p)\n", This, ppv);
238 *ppv = &This->IActiveScript_iface;
239 }else if(IsEqualGUID(riid, &IID_IActiveScriptParse)) {
240 TRACE("(%p)->(IID_IActiveScriptParse %p)\n", This, ppv);
241 *ppv = &This->IActiveScriptParse_iface;
242 }else if(IsEqualGUID(riid, &IID_IActiveScriptParseProcedure2)) {
243 TRACE("(%p)->(IID_IActiveScriptParseProcedure2 %p)\n", This, ppv);
244 *ppv = &This->IActiveScriptParseProcedure2_iface;
245 }else if(IsEqualGUID(riid, &IID_IObjectSafety)) {
246 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
247 *ppv = &This->IObjectSafety_iface;
249 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
251 return E_NOINTERFACE;
254 IUnknown_AddRef((IUnknown*)*ppv);
258 static ULONG WINAPI VBScript_AddRef(IActiveScript *iface)
260 VBScript *This = impl_from_IActiveScript(iface);
261 LONG ref = InterlockedIncrement(&This->ref);
263 TRACE("(%p) ref=%d\n", This, ref);
268 static ULONG WINAPI VBScript_Release(IActiveScript *iface)
270 VBScript *This = impl_from_IActiveScript(iface);
271 LONG ref = InterlockedDecrement(&This->ref);
273 TRACE("(%p) ref=%d\n", iface, ref);
277 decrease_state(This, SCRIPTSTATE_CLOSED);
278 destroy_script(This->ctx);
282 IActiveScriptSite_Release(This->site);
289 static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
291 VBScript *This = impl_from_IActiveScript(iface);
295 TRACE("(%p)->(%p)\n", This, pass);
303 if(InterlockedCompareExchange(&This->thread_id, GetCurrentThreadId(), 0))
307 IActiveScriptSite_AddRef(This->site);
309 hres = IActiveScriptSite_GetLCID(This->site, &lcid);
313 return This->ctx ? set_ctx_site(This) : S_OK;
316 static HRESULT WINAPI VBScript_GetScriptSite(IActiveScript *iface, REFIID riid,
319 VBScript *This = impl_from_IActiveScript(iface);
320 FIXME("(%p)->()\n", This);
324 static HRESULT WINAPI VBScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
326 VBScript *This = impl_from_IActiveScript(iface);
328 TRACE("(%p)->(%d)\n", This, ss);
330 if(This->thread_id && GetCurrentThreadId() != This->thread_id)
333 if(ss == SCRIPTSTATE_UNINITIALIZED) {
334 if(This->state == SCRIPTSTATE_CLOSED)
337 decrease_state(This, SCRIPTSTATE_UNINITIALIZED);
345 case SCRIPTSTATE_STARTED:
346 case SCRIPTSTATE_CONNECTED: /* FIXME */
347 if(This->state == SCRIPTSTATE_CLOSED)
350 exec_queued_code(This->ctx);
352 case SCRIPTSTATE_INITIALIZED:
353 FIXME("unimplemented SCRIPTSTATE_INITIALIZED\n");
356 FIXME("unimplemented state %d\n", ss);
360 change_state(This, ss);
364 static HRESULT WINAPI VBScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
366 VBScript *This = impl_from_IActiveScript(iface);
368 TRACE("(%p)->(%p)\n", This, pssState);
373 if(This->thread_id && This->thread_id != GetCurrentThreadId())
376 *pssState = This->state;
380 static HRESULT WINAPI VBScript_Close(IActiveScript *iface)
382 VBScript *This = impl_from_IActiveScript(iface);
384 TRACE("(%p)->()\n", This);
386 if(This->thread_id && This->thread_id != GetCurrentThreadId())
389 decrease_state(This, SCRIPTSTATE_CLOSED);
393 static HRESULT WINAPI VBScript_AddNamedItem(IActiveScript *iface, LPCOLESTR pstrName, DWORD dwFlags)
395 VBScript *This = impl_from_IActiveScript(iface);
397 IDispatch *disp = NULL;
400 TRACE("(%p)->(%s %x)\n", This, debugstr_w(pstrName), dwFlags);
402 if(This->thread_id != GetCurrentThreadId() || !This->ctx || This->state == SCRIPTSTATE_CLOSED)
405 if(dwFlags & SCRIPTITEM_GLOBALMEMBERS) {
408 hres = IActiveScriptSite_GetItemInfo(This->site, pstrName, SCRIPTINFO_IUNKNOWN, &unk, NULL);
410 WARN("GetItemInfo failed: %08x\n", hres);
414 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
415 IUnknown_Release(unk);
417 WARN("object does not implement IDispatch\n");
421 if(This->ctx->host_global)
422 IDispatch_Release(This->ctx->host_global);
423 IDispatch_AddRef(disp);
424 This->ctx->host_global = disp;
427 item = heap_alloc(sizeof(*item));
430 IDispatch_Release(disp);
431 return E_OUTOFMEMORY;
435 item->flags = dwFlags;
436 item->name = heap_strdupW(pstrName);
439 IDispatch_Release(disp);
441 return E_OUTOFMEMORY;
444 list_add_tail(&This->ctx->named_items, &item->entry);
448 static HRESULT WINAPI VBScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
449 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
451 VBScript *This = impl_from_IActiveScript(iface);
452 FIXME("(%p)->()\n", This);
456 static HRESULT WINAPI VBScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName, IDispatch **ppdisp)
458 VBScript *This = impl_from_IActiveScript(iface);
460 TRACE("(%p)->(%p)\n", This, ppdisp);
465 if(This->thread_id != GetCurrentThreadId() || !This->ctx || !This->ctx->script_obj) {
470 *ppdisp = (IDispatch*)&This->ctx->script_obj->IDispatchEx_iface;
471 IDispatch_AddRef(*ppdisp);
475 static HRESULT WINAPI VBScript_GetCurrentScriptThreadID(IActiveScript *iface,
476 SCRIPTTHREADID *pstridThread)
478 VBScript *This = impl_from_IActiveScript(iface);
479 FIXME("(%p)->()\n", This);
483 static HRESULT WINAPI VBScript_GetScriptThreadID(IActiveScript *iface,
484 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
486 VBScript *This = impl_from_IActiveScript(iface);
487 FIXME("(%p)->()\n", This);
491 static HRESULT WINAPI VBScript_GetScriptThreadState(IActiveScript *iface,
492 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
494 VBScript *This = impl_from_IActiveScript(iface);
495 FIXME("(%p)->()\n", This);
499 static HRESULT WINAPI VBScript_InterruptScriptThread(IActiveScript *iface,
500 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
502 VBScript *This = impl_from_IActiveScript(iface);
503 FIXME("(%p)->()\n", This);
507 static HRESULT WINAPI VBScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
509 VBScript *This = impl_from_IActiveScript(iface);
510 FIXME("(%p)->()\n", This);
514 static const IActiveScriptVtbl VBScriptVtbl = {
515 VBScript_QueryInterface,
518 VBScript_SetScriptSite,
519 VBScript_GetScriptSite,
520 VBScript_SetScriptState,
521 VBScript_GetScriptState,
523 VBScript_AddNamedItem,
525 VBScript_GetScriptDispatch,
526 VBScript_GetCurrentScriptThreadID,
527 VBScript_GetScriptThreadID,
528 VBScript_GetScriptThreadState,
529 VBScript_InterruptScriptThread,
533 static inline VBScript *impl_from_IActiveScriptParse(IActiveScriptParse *iface)
535 return CONTAINING_RECORD(iface, VBScript, IActiveScriptParse_iface);
538 static HRESULT WINAPI VBScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
540 VBScript *This = impl_from_IActiveScriptParse(iface);
541 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
544 static ULONG WINAPI VBScriptParse_AddRef(IActiveScriptParse *iface)
546 VBScript *This = impl_from_IActiveScriptParse(iface);
547 return IActiveScript_AddRef(&This->IActiveScript_iface);
550 static ULONG WINAPI VBScriptParse_Release(IActiveScriptParse *iface)
552 VBScript *This = impl_from_IActiveScriptParse(iface);
553 return IActiveScript_Release(&This->IActiveScript_iface);
556 static HRESULT WINAPI VBScriptParse_InitNew(IActiveScriptParse *iface)
558 VBScript *This = impl_from_IActiveScriptParse(iface);
559 script_ctx_t *ctx, *old_ctx;
561 TRACE("(%p)\n", This);
566 ctx = heap_alloc_zero(sizeof(script_ctx_t));
568 return E_OUTOFMEMORY;
570 ctx->safeopt = This->safeopt;
571 vbsheap_init(&ctx->heap);
572 list_init(&ctx->objects);
573 list_init(&ctx->code_list);
574 list_init(&ctx->named_items);
576 old_ctx = InterlockedCompareExchangePointer((void**)&This->ctx, ctx, NULL);
582 return This->site ? set_ctx_site(This) : S_OK;
585 static HRESULT WINAPI VBScriptParse_AddScriptlet(IActiveScriptParse *iface,
586 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
587 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
588 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
589 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
591 VBScript *This = impl_from_IActiveScriptParse(iface);
592 FIXME("(%p)->(%s %s %s %s %s %s %s %u %x %p %p)\n", This, debugstr_w(pstrDefaultName),
593 debugstr_w(pstrCode), debugstr_w(pstrItemName), debugstr_w(pstrSubItemName),
594 debugstr_w(pstrEventName), debugstr_w(pstrDelimiter), wine_dbgstr_longlong(dwSourceContextCookie),
595 ulStartingLineNumber, dwFlags, pbstrName, pexcepinfo);
599 static HRESULT WINAPI VBScriptParse_ParseScriptText(IActiveScriptParse *iface,
600 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
601 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
602 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
604 VBScript *This = impl_from_IActiveScriptParse(iface);
608 TRACE("(%p)->(%s %s %p %s %s %u %x %p %p)\n", This, debugstr_w(pstrCode),
609 debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
610 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLine, dwFlags, pvarResult, pexcepinfo);
612 if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
615 hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
619 if(!is_started(This)) {
620 code->pending_exec = TRUE;
624 return exec_global_code(This->ctx, code);
627 static const IActiveScriptParseVtbl VBScriptParseVtbl = {
628 VBScriptParse_QueryInterface,
629 VBScriptParse_AddRef,
630 VBScriptParse_Release,
631 VBScriptParse_InitNew,
632 VBScriptParse_AddScriptlet,
633 VBScriptParse_ParseScriptText
636 static inline VBScript *impl_from_IActiveScriptParseProcedure2(IActiveScriptParseProcedure2 *iface)
638 return CONTAINING_RECORD(iface, VBScript, IActiveScriptParseProcedure2_iface);
641 static HRESULT WINAPI VBScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
643 VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
644 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
647 static ULONG WINAPI VBScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
649 VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
650 return IActiveScript_AddRef(&This->IActiveScript_iface);
653 static ULONG WINAPI VBScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
655 VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
656 return IActiveScript_Release(&This->IActiveScript_iface);
659 static HRESULT WINAPI VBScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
660 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
661 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
662 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
664 VBScript *This = impl_from_IActiveScriptParseProcedure2(iface);
668 TRACE("(%p)->(%s %s %s %s %p %s %s %u %x %p)\n", This, debugstr_w(pstrCode), debugstr_w(pstrFormalParams),
669 debugstr_w(pstrProcedureName), debugstr_w(pstrItemName), punkContext, debugstr_w(pstrDelimiter),
670 wine_dbgstr_longlong(dwSourceContextCookie), ulStartingLineNumber, dwFlags, ppdisp);
672 if(This->thread_id != GetCurrentThreadId() || This->state == SCRIPTSTATE_CLOSED)
675 hres = compile_script(This->ctx, pstrCode, pstrDelimiter, &code);
679 return create_procedure_disp(This->ctx, code, ppdisp);
682 static const IActiveScriptParseProcedure2Vtbl VBScriptParseProcedureVtbl = {
683 VBScriptParseProcedure_QueryInterface,
684 VBScriptParseProcedure_AddRef,
685 VBScriptParseProcedure_Release,
686 VBScriptParseProcedure_ParseProcedureText,
689 static inline VBScript *impl_from_IObjectSafety(IObjectSafety *iface)
691 return CONTAINING_RECORD(iface, VBScript, IObjectSafety_iface);
694 static HRESULT WINAPI VBScriptSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
696 VBScript *This = impl_from_IObjectSafety(iface);
697 return IActiveScript_QueryInterface(&This->IActiveScript_iface, riid, ppv);
700 static ULONG WINAPI VBScriptSafety_AddRef(IObjectSafety *iface)
702 VBScript *This = impl_from_IObjectSafety(iface);
703 return IActiveScript_AddRef(&This->IActiveScript_iface);
706 static ULONG WINAPI VBScriptSafety_Release(IObjectSafety *iface)
708 VBScript *This = impl_from_IObjectSafety(iface);
709 return IActiveScript_Release(&This->IActiveScript_iface);
712 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER)
714 static HRESULT WINAPI VBScriptSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
715 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
717 VBScript *This = impl_from_IObjectSafety(iface);
719 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
721 if(!pdwSupportedOptions || !pdwEnabledOptions)
724 *pdwSupportedOptions = SUPPORTED_OPTIONS;
725 *pdwEnabledOptions = This->safeopt;
729 static HRESULT WINAPI VBScriptSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
730 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
732 VBScript *This = impl_from_IObjectSafety(iface);
734 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
736 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
739 This->safeopt = (dwEnabledOptions & dwOptionSetMask) | (This->safeopt & ~dwOptionSetMask) | INTERFACE_USES_DISPEX;
743 static const IObjectSafetyVtbl VBScriptSafetyVtbl = {
744 VBScriptSafety_QueryInterface,
745 VBScriptSafety_AddRef,
746 VBScriptSafety_Release,
747 VBScriptSafety_GetInterfaceSafetyOptions,
748 VBScriptSafety_SetInterfaceSafetyOptions
751 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, void **ppv)
756 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
758 ret = heap_alloc_zero(sizeof(*ret));
760 return E_OUTOFMEMORY;
762 ret->IActiveScript_iface.lpVtbl = &VBScriptVtbl;
763 ret->IActiveScriptParse_iface.lpVtbl = &VBScriptParseVtbl;
764 ret->IActiveScriptParseProcedure2_iface.lpVtbl = &VBScriptParseProcedureVtbl;
765 ret->IObjectSafety_iface.lpVtbl = &VBScriptSafetyVtbl;
768 ret->state = SCRIPTSTATE_UNINITIALIZED;
769 ret->safeopt = INTERFACE_USES_DISPEX;
771 hres = IActiveScript_QueryInterface(&ret->IActiveScript_iface, riid, ppv);
772 IActiveScript_Release(&ret->IActiveScript_iface);
777 IServiceProvider IServiceProvider_iface;
781 IServiceProvider *sp;
784 static inline AXSite *impl_from_IServiceProvider(IServiceProvider *iface)
786 return CONTAINING_RECORD(iface, AXSite, IServiceProvider_iface);
789 static HRESULT WINAPI AXSite_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
791 AXSite *This = impl_from_IServiceProvider(iface);
793 if(IsEqualGUID(&IID_IUnknown, riid)) {
794 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
795 *ppv = &This->IServiceProvider_iface;
796 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
797 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
798 *ppv = &This->IServiceProvider_iface;
800 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
802 return E_NOINTERFACE;
805 IUnknown_AddRef((IUnknown*)*ppv);
809 static ULONG WINAPI AXSite_AddRef(IServiceProvider *iface)
811 AXSite *This = impl_from_IServiceProvider(iface);
812 LONG ref = InterlockedIncrement(&This->ref);
814 TRACE("(%p) ref=%d\n", This, ref);
819 static ULONG WINAPI AXSite_Release(IServiceProvider *iface)
821 AXSite *This = impl_from_IServiceProvider(iface);
822 LONG ref = InterlockedDecrement(&This->ref);
824 TRACE("(%p) ref=%d\n", This, ref);
832 static HRESULT WINAPI AXSite_QueryService(IServiceProvider *iface,
833 REFGUID guidService, REFIID riid, void **ppv)
835 AXSite *This = impl_from_IServiceProvider(iface);
837 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
839 return IServiceProvider_QueryService(This->sp, guidService, riid, ppv);
842 static IServiceProviderVtbl AXSiteVtbl = {
843 AXSite_QueryInterface,
849 IUnknown *create_ax_site(script_ctx_t *ctx)
851 IServiceProvider *sp;
855 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
857 ERR("Could not get IServiceProvider iface: %08x\n", hres);
861 ret = heap_alloc(sizeof(*ret));
863 IServiceProvider_Release(sp);
867 ret->IServiceProvider_iface.lpVtbl = &AXSiteVtbl;
871 return (IUnknown*)&ret->IServiceProvider_iface;