wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / msscript.ocx / msscript.c
blob15d15ab43496472621505e1fccddb86a1c2a073c
1 /*
2 * Copyright 2015 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
19 #define COBJMACROS
21 #include "windows.h"
22 #include "initguid.h"
23 #include "dispex.h"
24 #include "ole2.h"
25 #include "olectl.h"
26 #include "objsafe.h"
27 #include "activscp.h"
28 #include "rpcproxy.h"
29 #include "msscript.h"
30 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
32 #include "wine/debug.h"
33 #include "wine/heap.h"
34 #include "wine/list.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msscript);
38 #ifdef _WIN64
40 #define IActiveScriptParse_Release IActiveScriptParse64_Release
41 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
42 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
44 #else
46 #define IActiveScriptParse_Release IActiveScriptParse32_Release
47 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
48 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
50 #endif
52 struct ScriptControl;
53 typedef struct ConnectionPoint ConnectionPoint;
54 typedef struct ScriptProcedureCollection ScriptProcedureCollection;
55 typedef struct ScriptHost ScriptHost;
57 struct ConnectionPoint {
58 IConnectionPoint IConnectionPoint_iface;
59 ScriptControl *control;
60 const IID *riid;
61 ConnectionPoint *next;
64 struct named_item {
65 struct list entry;
66 BSTR name;
67 IDispatch *disp;
70 struct module_enum {
71 IEnumVARIANT IEnumVARIANT_iface;
72 LONG ref;
74 UINT pos;
75 ScriptHost *host;
76 ScriptControl *control;
79 typedef struct {
80 IScriptModule IScriptModule_iface;
81 LONG ref;
83 BSTR name;
84 ScriptHost *host;
85 IDispatch *script_dispatch;
86 ITypeInfo *script_typeinfo;
87 ITypeComp *script_typecomp;
89 ScriptProcedureCollection *procedures;
90 } ScriptModule;
92 typedef struct {
93 IScriptProcedure IScriptProcedure_iface;
94 LONG ref;
96 ULONG hash;
97 struct list entry;
99 BSTR name;
100 USHORT num_args;
101 VARTYPE ret_type;
102 } ScriptProcedure;
104 struct ScriptProcedureCollection {
105 IScriptProcedureCollection IScriptProcedureCollection_iface;
106 LONG ref;
108 LONG count;
109 ScriptModule *module;
110 struct list hash_table[43];
113 struct procedure_enum {
114 IEnumVARIANT IEnumVARIANT_iface;
115 LONG ref;
117 WORD pos;
118 WORD count;
119 ScriptProcedureCollection *procedures;
122 typedef struct {
123 IScriptError IScriptError_iface;
124 IActiveScriptError *object;
125 LONG ref;
127 HRESULT number;
128 BSTR text;
129 BSTR source;
130 BSTR desc;
131 BSTR help_file;
132 DWORD help_context;
133 ULONG line;
134 LONG column;
136 BOOLEAN info_filled;
137 BOOLEAN text_filled;
138 BOOLEAN pos_filled;
139 } ScriptError;
141 struct ScriptHost {
142 IActiveScriptSite IActiveScriptSite_iface;
143 IActiveScriptSiteWindow IActiveScriptSiteWindow_iface;
144 IServiceProvider IServiceProvider_iface;
145 LONG ref;
147 IActiveScript *script;
148 IActiveScriptParse *parse;
149 ScriptError *error;
150 HWND site_hwnd;
151 SCRIPTSTATE script_state;
152 CLSID clsid;
154 unsigned int module_count;
155 struct list named_items;
158 struct ScriptControl {
159 IScriptControl IScriptControl_iface;
160 IPersistStreamInit IPersistStreamInit_iface;
161 IOleObject IOleObject_iface;
162 IOleControl IOleControl_iface;
163 IQuickActivate IQuickActivate_iface;
164 IViewObjectEx IViewObjectEx_iface;
165 IPointerInactive IPointerInactive_iface;
166 IConnectionPointContainer IConnectionPointContainer_iface;
167 LONG ref;
168 IOleClientSite *site;
169 HWND site_hwnd;
170 SIZEL extent;
171 LONG timeout;
172 VARIANT_BOOL allow_ui;
173 VARIANT_BOOL use_safe_subset;
175 /* connection points */
176 ConnectionPoint *cp_list;
177 ConnectionPoint cp_scsource;
178 ConnectionPoint cp_propnotif;
180 /* IViewObject sink */
181 IAdviseSink *view_sink;
182 DWORD view_sink_flags;
184 /* modules */
185 ScriptModule **modules;
186 IScriptModuleCollection IScriptModuleCollection_iface;
188 ScriptHost *host;
189 ScriptError *error;
192 static HINSTANCE msscript_instance;
194 typedef enum tid_t {
195 IScriptControl_tid,
196 IScriptError_tid,
197 IScriptModuleCollection_tid,
198 IScriptModule_tid,
199 IScriptProcedureCollection_tid,
200 IScriptProcedure_tid,
201 LAST_tid
202 } tid_t;
204 static ITypeLib *typelib;
205 static ITypeInfo *typeinfos[LAST_tid];
207 static REFIID tid_ids[] = {
208 &IID_IScriptControl,
209 &IID_IScriptError,
210 &IID_IScriptModuleCollection,
211 &IID_IScriptModule,
212 &IID_IScriptProcedureCollection,
213 &IID_IScriptProcedure
216 static HRESULT load_typelib(void)
218 HRESULT hres;
219 ITypeLib *tl;
221 hres = LoadRegTypeLib(&LIBID_MSScriptControl, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
222 if(FAILED(hres)) {
223 ERR("LoadRegTypeLib failed: %08x\n", hres);
224 return hres;
227 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
228 ITypeLib_Release(tl);
229 return hres;
232 static HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
234 HRESULT hres;
236 if (!typelib)
237 hres = load_typelib();
238 if (!typelib)
239 return hres;
241 if(!typeinfos[tid]) {
242 ITypeInfo *ti;
244 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
245 if(FAILED(hres)) {
246 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
247 return hres;
250 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
251 ITypeInfo_Release(ti);
254 *typeinfo = typeinfos[tid];
255 ITypeInfo_AddRef(typeinfos[tid]);
256 return S_OK;
259 static void release_typelib(void)
261 unsigned i;
263 if(!typelib)
264 return;
266 for(i = 0; i < ARRAY_SIZE(typeinfos); i++)
267 if(typeinfos[i])
268 ITypeInfo_Release(typeinfos[i]);
270 ITypeLib_Release(typelib);
273 static inline BOOL is_power_of_2(unsigned x)
275 return !(x & (x - 1));
278 static void clear_named_items(ScriptHost *host)
280 struct named_item *item, *item1;
281 LIST_FOR_EACH_ENTRY_SAFE(item, item1, &host->named_items, struct named_item, entry) {
282 list_remove(&item->entry);
283 SysFreeString(item->name);
284 IDispatch_Release(item->disp);
285 heap_free(item);
289 static struct named_item *host_get_named_item(ScriptHost *host, const WCHAR *nameW)
291 struct named_item *item;
293 LIST_FOR_EACH_ENTRY(item, &host->named_items, struct named_item, entry) {
294 if (!wcscmp(item->name, nameW))
295 return item;
298 return NULL;
301 static HRESULT get_script_dispatch(ScriptModule *module, IDispatch **disp)
303 if (!module->script_dispatch)
305 HRESULT hr = IActiveScript_GetScriptDispatch(module->host->script,
306 module->name, &module->script_dispatch);
307 if (FAILED(hr)) return hr;
309 *disp = module->script_dispatch;
310 return S_OK;
313 static HRESULT get_script_typeinfo(ScriptModule *module, ITypeInfo **typeinfo)
315 IDispatch *disp;
316 HRESULT hr;
318 if (!module->script_typeinfo)
320 hr = get_script_dispatch(module, &disp);
321 if (FAILED(hr)) return hr;
323 hr = IDispatch_GetTypeInfo(disp, 0, LOCALE_USER_DEFAULT, &module->script_typeinfo);
324 if (FAILED(hr)) return hr;
326 *typeinfo = module->script_typeinfo;
327 return S_OK;
330 static HRESULT get_script_typecomp(ScriptModule *module, ITypeInfo *typeinfo, ITypeComp **typecomp)
332 HRESULT hr;
334 if (!module->script_typecomp)
336 hr = ITypeInfo_QueryInterface(typeinfo, &IID_ITypeComp, (void**)&module->script_typecomp);
337 if (FAILED(hr)) return hr;
339 *typecomp = module->script_typecomp;
340 return S_OK;
343 static void uncache_module_objects(ScriptModule *module)
345 if (module->script_dispatch)
347 IDispatch_Release(module->script_dispatch);
348 module->script_dispatch = NULL;
350 if (module->script_typeinfo)
352 ITypeInfo_Release(module->script_typeinfo);
353 module->script_typeinfo = NULL;
355 if (module->script_typecomp)
357 ITypeComp_Release(module->script_typecomp);
358 module->script_typecomp = NULL;
362 static HRESULT set_script_state(ScriptHost *host, SCRIPTSTATE state)
364 HRESULT hr;
366 hr = IActiveScript_SetScriptState(host->script, state);
367 if (SUCCEEDED(hr))
368 host->script_state = state;
369 return hr;
372 static HRESULT start_script(ScriptModule *module)
374 HRESULT hr = S_OK;
376 if (module->host->script_state != SCRIPTSTATE_STARTED)
378 hr = set_script_state(module->host, SCRIPTSTATE_STARTED);
379 if (SUCCEEDED(hr)) uncache_module_objects(module);
382 return hr;
385 static HRESULT add_script_object(ScriptHost *host, BSTR name, IDispatch *object, DWORD flags)
387 struct named_item *item;
388 HRESULT hr;
390 if (host_get_named_item(host, name))
391 return E_INVALIDARG;
393 item = heap_alloc(sizeof(*item));
394 if (!item)
395 return E_OUTOFMEMORY;
397 item->name = SysAllocString(name);
398 if (!item->name)
400 heap_free(item);
401 return E_OUTOFMEMORY;
403 IDispatch_AddRef(item->disp = object);
404 list_add_tail(&host->named_items, &item->entry);
406 hr = IActiveScript_AddNamedItem(host->script, name, flags);
407 if (FAILED(hr))
409 list_remove(&item->entry);
410 IDispatch_Release(item->disp);
411 SysFreeString(item->name);
412 heap_free(item);
413 return hr;
416 return hr;
419 static HRESULT parse_script_text(ScriptModule *module, BSTR script_text, DWORD flag, VARIANT *res)
421 EXCEPINFO excepinfo;
422 HRESULT hr;
424 hr = start_script(module);
425 if (FAILED(hr)) return hr;
427 uncache_module_objects(module);
428 if (module->procedures)
429 module->procedures->count = -1;
431 hr = IActiveScriptParse_ParseScriptText(module->host->parse, script_text, module->name,
432 NULL, NULL, 0, 1, flag, res, &excepinfo);
433 /* FIXME: more error handling */
434 return hr;
437 static HRESULT WINAPI sp_caller_QueryInterface(IServiceProvider *iface, REFIID riid, void **obj)
439 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IServiceProvider, riid))
440 *obj = iface;
441 else
443 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
444 *obj = NULL;
445 return E_NOINTERFACE;
448 IUnknown_AddRef((IUnknown*)*obj);
449 return S_OK;
452 static ULONG WINAPI sp_caller_AddRef(IServiceProvider *iface)
454 return 2;
457 static ULONG WINAPI sp_caller_Release(IServiceProvider *iface)
459 return 1;
462 static HRESULT WINAPI sp_caller_QueryService(IServiceProvider *iface, REFGUID service, REFIID riid, void **obj)
464 FIXME("(%p)->(%s %s %p): semi-stub\n", iface, debugstr_guid(service), debugstr_guid(riid), obj);
466 *obj = NULL;
467 if (IsEqualGUID(&SID_GetCaller, service))
468 return S_OK;
470 return E_NOINTERFACE;
473 static const IServiceProviderVtbl sp_caller_vtbl = {
474 sp_caller_QueryInterface,
475 sp_caller_AddRef,
476 sp_caller_Release,
477 sp_caller_QueryService
480 static IServiceProvider sp_caller = { &sp_caller_vtbl };
482 static HRESULT run_procedure(ScriptModule *module, BSTR procedure_name, SAFEARRAY *args, VARIANT *res)
484 IDispatchEx *dispex;
485 IDispatch *disp;
486 DISPPARAMS dp;
487 DISPID dispid;
488 HRESULT hr;
489 UINT i;
491 hr = start_script(module);
492 if (FAILED(hr)) return hr;
494 hr = get_script_dispatch(module, &disp);
495 if (FAILED(hr)) return hr;
497 hr = IDispatch_GetIDsOfNames(disp, &IID_NULL, &procedure_name, 1, LOCALE_USER_DEFAULT, &dispid);
498 if (FAILED(hr)) return hr;
500 dp.cArgs = args->rgsabound[0].cElements;
501 dp.rgdispidNamedArgs = NULL;
502 dp.cNamedArgs = 0;
503 dp.rgvarg = heap_alloc(dp.cArgs * sizeof(*dp.rgvarg));
504 if (!dp.rgvarg) return E_OUTOFMEMORY;
506 hr = SafeArrayLock(args);
507 if (SUCCEEDED(hr))
509 /* The DISPPARAMS are stored in reverse order */
510 for (i = 0; i < dp.cArgs; i++)
511 dp.rgvarg[i] = *(VARIANT*)((char*)(args->pvData) + (dp.cArgs - i - 1) * args->cbElements);
512 SafeArrayUnlock(args);
514 hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
515 if (FAILED(hr))
517 hr = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_USER_DEFAULT,
518 DISPATCH_METHOD, &dp, res, NULL, NULL);
520 else
522 hr = IDispatchEx_InvokeEx(dispex, dispid, LOCALE_USER_DEFAULT,
523 DISPATCH_METHOD, &dp, res, NULL, &sp_caller);
524 IDispatchEx_Release(dispex);
527 heap_free(dp.rgvarg);
529 return hr;
532 static inline ScriptControl *impl_from_IScriptControl(IScriptControl *iface)
534 return CONTAINING_RECORD(iface, ScriptControl, IScriptControl_iface);
537 static inline ScriptControl *impl_from_IOleObject(IOleObject *iface)
539 return CONTAINING_RECORD(iface, ScriptControl, IOleObject_iface);
542 static inline ScriptControl *impl_from_IPersistStreamInit(IPersistStreamInit *iface)
544 return CONTAINING_RECORD(iface, ScriptControl, IPersistStreamInit_iface);
547 static inline ScriptControl *impl_from_IOleControl(IOleControl *iface)
549 return CONTAINING_RECORD(iface, ScriptControl, IOleControl_iface);
552 static inline ScriptControl *impl_from_IQuickActivate(IQuickActivate *iface)
554 return CONTAINING_RECORD(iface, ScriptControl, IQuickActivate_iface);
557 static inline ScriptControl *impl_from_IViewObjectEx(IViewObjectEx *iface)
559 return CONTAINING_RECORD(iface, ScriptControl, IViewObjectEx_iface);
562 static inline ScriptControl *impl_from_IPointerInactive(IPointerInactive *iface)
564 return CONTAINING_RECORD(iface, ScriptControl, IPointerInactive_iface);
567 static inline ScriptControl *impl_from_IConnectionPointContainer(IConnectionPointContainer *iface)
569 return CONTAINING_RECORD(iface, ScriptControl, IConnectionPointContainer_iface);
572 static inline ScriptProcedure *impl_from_IScriptProcedure(IScriptProcedure *iface)
574 return CONTAINING_RECORD(iface, ScriptProcedure, IScriptProcedure_iface);
577 static inline ScriptProcedureCollection *impl_from_IScriptProcedureCollection(IScriptProcedureCollection *iface)
579 return CONTAINING_RECORD(iface, ScriptProcedureCollection, IScriptProcedureCollection_iface);
582 static inline ScriptControl *impl_from_IScriptModuleCollection(IScriptModuleCollection *iface)
584 return CONTAINING_RECORD(iface, ScriptControl, IScriptModuleCollection_iface);
587 static inline ScriptModule *impl_from_IScriptModule(IScriptModule *iface)
589 return CONTAINING_RECORD(iface, ScriptModule, IScriptModule_iface);
592 static inline ScriptError *impl_from_IScriptError(IScriptError *iface)
594 return CONTAINING_RECORD(iface, ScriptError, IScriptError_iface);
597 static inline ConnectionPoint *impl_from_IConnectionPoint(IConnectionPoint *iface)
599 return CONTAINING_RECORD(iface, ConnectionPoint, IConnectionPoint_iface);
602 static inline ScriptHost *impl_from_IActiveScriptSite(IActiveScriptSite *iface)
604 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSite_iface);
607 static inline ScriptHost *impl_from_IActiveScriptSiteWindow(IActiveScriptSiteWindow *iface)
609 return CONTAINING_RECORD(iface, ScriptHost, IActiveScriptSiteWindow_iface);
612 static inline ScriptHost *impl_from_IServiceProvider(IServiceProvider *iface)
614 return CONTAINING_RECORD(iface, ScriptHost, IServiceProvider_iface);
617 static inline struct module_enum *module_enum_from_IEnumVARIANT(IEnumVARIANT *iface)
619 return CONTAINING_RECORD(iface, struct module_enum, IEnumVARIANT_iface);
622 static inline struct procedure_enum *procedure_enum_from_IEnumVARIANT(IEnumVARIANT *iface)
624 return CONTAINING_RECORD(iface, struct procedure_enum, IEnumVARIANT_iface);
627 /* IActiveScriptSite */
628 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
630 ScriptHost *This = impl_from_IActiveScriptSite(iface);
632 if(IsEqualGUID(&IID_IUnknown, riid)) {
633 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
634 *ppv = &This->IActiveScriptSite_iface;
635 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
636 TRACE("(%p)->(IID_IActiveScriptSite %p)\n", This, ppv);
637 *ppv = &This->IActiveScriptSite_iface;
638 }else if(IsEqualGUID(&IID_IActiveScriptSiteWindow, riid)) {
639 TRACE("(%p)->(IID_IActiveScriptSiteWindow %p)\n", This, ppv);
640 *ppv = &This->IActiveScriptSiteWindow_iface;
641 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
642 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
643 *ppv = &This->IServiceProvider_iface;
644 }else {
645 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
646 *ppv = NULL;
647 return E_NOINTERFACE;
650 IUnknown_AddRef((IUnknown*)*ppv);
651 return S_OK;
654 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
656 ScriptHost *This = impl_from_IActiveScriptSite(iface);
657 LONG ref = InterlockedIncrement(&This->ref);
659 TRACE("(%p) ref=%d\n", This, ref);
661 return ref;
664 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
666 ScriptHost *This = impl_from_IActiveScriptSite(iface);
667 LONG ref = InterlockedDecrement(&This->ref);
669 TRACE("(%p) ref=%d\n", This, ref);
671 if(!ref) {
672 clear_named_items(This);
673 heap_free(This);
676 return ref;
679 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *lcid)
681 ScriptHost *This = impl_from_IActiveScriptSite(iface);
683 TRACE("(%p, %p)\n", This, lcid);
685 *lcid = GetUserDefaultLCID();
686 return S_OK;
689 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR name, DWORD mask,
690 IUnknown **unk, ITypeInfo **ti)
692 ScriptHost *This = impl_from_IActiveScriptSite(iface);
693 struct named_item *item;
695 TRACE("(%p, %s, %#x, %p, %p)\n", This, debugstr_w(name), mask, unk, ti);
697 item = host_get_named_item(This, name);
698 if (!item)
699 return TYPE_E_ELEMENTNOTFOUND;
701 if (mask != SCRIPTINFO_IUNKNOWN) {
702 FIXME("mask %#x is not supported\n", mask);
703 return E_NOTIMPL;
706 *unk = (IUnknown*)item->disp;
707 IUnknown_AddRef(*unk);
709 return S_OK;
712 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *version)
714 ScriptHost *This = impl_from_IActiveScriptSite(iface);
716 FIXME("(%p, %p)\n", This, version);
718 return E_NOTIMPL;
721 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface, const VARIANT *result,
722 const EXCEPINFO *ei)
724 ScriptHost *This = impl_from_IActiveScriptSite(iface);
726 FIXME("(%p, %s, %p)\n", This, debugstr_variant(result), ei);
728 return E_NOTIMPL;
731 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE state)
733 ScriptHost *This = impl_from_IActiveScriptSite(iface);
735 FIXME("(%p, %d)\n", This, state);
737 return E_NOTIMPL;
740 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *script_error)
742 ScriptHost *This = impl_from_IActiveScriptSite(iface);
744 TRACE("(%p, %p)\n", This, script_error);
746 if (This->error)
748 IScriptError_Clear(&This->error->IScriptError_iface);
749 IActiveScriptError_AddRef(script_error);
750 This->error->object = script_error;
752 return S_FALSE;
755 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
757 ScriptHost *This = impl_from_IActiveScriptSite(iface);
759 FIXME("(%p)\n", This);
761 return E_NOTIMPL;
764 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
766 ScriptHost *This = impl_from_IActiveScriptSite(iface);
768 FIXME("(%p)\n", This);
770 return E_NOTIMPL;
773 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
774 ActiveScriptSite_QueryInterface,
775 ActiveScriptSite_AddRef,
776 ActiveScriptSite_Release,
777 ActiveScriptSite_GetLCID,
778 ActiveScriptSite_GetItemInfo,
779 ActiveScriptSite_GetDocVersionString,
780 ActiveScriptSite_OnScriptTerminate,
781 ActiveScriptSite_OnStateChange,
782 ActiveScriptSite_OnScriptError,
783 ActiveScriptSite_OnEnterScript,
784 ActiveScriptSite_OnLeaveScript
787 /* IActiveScriptSiteWindow */
788 static HRESULT WINAPI ActiveScriptSiteWindow_QueryInterface(IActiveScriptSiteWindow *iface, REFIID riid, void **obj)
790 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
791 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, obj);
794 static ULONG WINAPI ActiveScriptSiteWindow_AddRef(IActiveScriptSiteWindow *iface)
796 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
797 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
800 static ULONG WINAPI ActiveScriptSiteWindow_Release(IActiveScriptSiteWindow *iface)
802 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
803 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
806 static HRESULT WINAPI ActiveScriptSiteWindow_GetWindow(IActiveScriptSiteWindow *iface, HWND *hwnd)
808 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
810 TRACE("(%p, %p)\n", This, hwnd);
812 if (!hwnd) return E_POINTER;
813 if (This->site_hwnd == ((HWND)-1)) return E_FAIL;
815 *hwnd = This->site_hwnd;
816 return S_OK;
819 static HRESULT WINAPI ActiveScriptSiteWindow_EnableModeless(IActiveScriptSiteWindow *iface, BOOL enable)
821 ScriptHost *This = impl_from_IActiveScriptSiteWindow(iface);
823 FIXME("(%p, %d): stub\n", This, enable);
825 return S_OK;
828 static const IActiveScriptSiteWindowVtbl ActiveScriptSiteWindowVtbl = {
829 ActiveScriptSiteWindow_QueryInterface,
830 ActiveScriptSiteWindow_AddRef,
831 ActiveScriptSiteWindow_Release,
832 ActiveScriptSiteWindow_GetWindow,
833 ActiveScriptSiteWindow_EnableModeless
836 /* IServiceProvider */
837 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **obj)
839 ScriptHost *This = impl_from_IServiceProvider(iface);
840 return IActiveScriptSite_QueryInterface(&This->IActiveScriptSite_iface, riid, obj);
843 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
845 ScriptHost *This = impl_from_IServiceProvider(iface);
846 return IActiveScriptSite_AddRef(&This->IActiveScriptSite_iface);
849 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
851 ScriptHost *This = impl_from_IServiceProvider(iface);
852 return IActiveScriptSite_Release(&This->IActiveScriptSite_iface);
855 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID service,
856 REFIID riid, void **obj)
858 ScriptHost *This = impl_from_IServiceProvider(iface);
860 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(service), debugstr_guid(riid), obj);
862 return E_NOTIMPL;
865 static const IServiceProviderVtbl ServiceProviderVtbl = {
866 ServiceProvider_QueryInterface,
867 ServiceProvider_AddRef,
868 ServiceProvider_Release,
869 ServiceProvider_QueryService
872 static HRESULT WINAPI ScriptProcedure_QueryInterface(IScriptProcedure *iface, REFIID riid, void **ppv)
874 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
876 if (IsEqualGUID(&IID_IDispatch, riid) || IsEqualGUID(&IID_IUnknown, riid) ||
877 IsEqualGUID(&IID_IScriptProcedure, riid))
879 *ppv = &This->IScriptProcedure_iface;
881 else
883 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
884 *ppv = NULL;
885 return E_NOINTERFACE;
888 IUnknown_AddRef((IUnknown*)*ppv);
889 return S_OK;
892 static ULONG WINAPI ScriptProcedure_AddRef(IScriptProcedure *iface)
894 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
895 LONG ref = InterlockedIncrement(&This->ref);
897 TRACE("(%p) ref=%d\n", This, ref);
899 return ref;
902 static ULONG WINAPI ScriptProcedure_Release(IScriptProcedure *iface)
904 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
905 LONG ref = InterlockedDecrement(&This->ref);
907 TRACE("(%p) ref=%d\n", This, ref);
909 if (!ref)
911 list_remove(&This->entry);
912 SysFreeString(This->name);
913 heap_free(This);
915 return ref;
918 static HRESULT WINAPI ScriptProcedure_GetTypeInfoCount(IScriptProcedure *iface, UINT *pctinfo)
920 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
922 TRACE("(%p)->(%p)\n", This, pctinfo);
924 *pctinfo = 1;
925 return S_OK;
928 static HRESULT WINAPI ScriptProcedure_GetTypeInfo(IScriptProcedure *iface, UINT iTInfo,
929 LCID lcid, ITypeInfo **ppTInfo)
931 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
933 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
935 return get_typeinfo(IScriptProcedure_tid, ppTInfo);
938 static HRESULT WINAPI ScriptProcedure_GetIDsOfNames(IScriptProcedure *iface, REFIID riid,
939 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
941 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
942 ITypeInfo *typeinfo;
943 HRESULT hr;
945 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
947 hr = get_typeinfo(IScriptProcedure_tid, &typeinfo);
948 if (SUCCEEDED(hr))
950 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
951 ITypeInfo_Release(typeinfo);
954 return hr;
957 static HRESULT WINAPI ScriptProcedure_Invoke(IScriptProcedure *iface, DISPID dispIdMember,
958 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
959 EXCEPINFO *pExcepInfo, UINT *puArgErr)
961 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
962 ITypeInfo *typeinfo;
963 HRESULT hr;
965 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
966 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
968 hr = get_typeinfo(IScriptProcedure_tid, &typeinfo);
969 if(SUCCEEDED(hr))
971 hr = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
972 pDispParams, pVarResult, pExcepInfo, puArgErr);
973 ITypeInfo_Release(typeinfo);
976 return hr;
979 static HRESULT WINAPI ScriptProcedure_get_Name(IScriptProcedure *iface, BSTR *pbstrName)
981 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
983 TRACE("(%p)->(%p)\n", This, pbstrName);
985 if (!pbstrName) return E_POINTER;
987 *pbstrName = SysAllocString(This->name);
988 return *pbstrName ? S_OK : E_OUTOFMEMORY;
991 static HRESULT WINAPI ScriptProcedure_get_NumArgs(IScriptProcedure *iface, LONG *pcArgs)
993 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
995 TRACE("(%p)->(%p)\n", This, pcArgs);
997 if (!pcArgs) return E_POINTER;
999 *pcArgs = This->num_args;
1000 return S_OK;
1003 static HRESULT WINAPI ScriptProcedure_get_HasReturnValue(IScriptProcedure *iface, VARIANT_BOOL *pfHasReturnValue)
1005 ScriptProcedure *This = impl_from_IScriptProcedure(iface);
1007 TRACE("(%p)->(%p)\n", This, pfHasReturnValue);
1009 if (!pfHasReturnValue) return E_POINTER;
1011 *pfHasReturnValue = (This->ret_type == VT_VOID) ? VARIANT_FALSE : VARIANT_TRUE;
1012 return S_OK;
1015 static const IScriptProcedureVtbl ScriptProcedureVtbl = {
1016 ScriptProcedure_QueryInterface,
1017 ScriptProcedure_AddRef,
1018 ScriptProcedure_Release,
1019 ScriptProcedure_GetTypeInfoCount,
1020 ScriptProcedure_GetTypeInfo,
1021 ScriptProcedure_GetIDsOfNames,
1022 ScriptProcedure_Invoke,
1023 ScriptProcedure_get_Name,
1024 ScriptProcedure_get_NumArgs,
1025 ScriptProcedure_get_HasReturnValue
1028 /* This function always releases the FUNCDESC passed in */
1029 static HRESULT get_script_procedure(ScriptProcedureCollection *procedures, ITypeInfo *typeinfo,
1030 FUNCDESC *desc, IScriptProcedure **procedure)
1032 struct list *proc_list;
1033 ScriptProcedure *proc;
1034 ULONG hash;
1035 HRESULT hr;
1036 BSTR str;
1037 UINT len;
1039 hr = ITypeInfo_GetNames(typeinfo, desc->memid, &str, 1, &len);
1040 if (FAILED(hr)) goto done;
1042 len = SysStringLen(str);
1043 hash = LHashValOfNameSys(sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32, LOCALE_USER_DEFAULT, str);
1044 proc_list = &procedures->hash_table[hash % ARRAY_SIZE(procedures->hash_table)];
1046 /* Try to find it in the hash table */
1047 LIST_FOR_EACH_ENTRY(proc, proc_list, ScriptProcedure, entry)
1049 if (proc->hash == hash && SysStringLen(proc->name) == len &&
1050 !memcmp(proc->name, str, len * sizeof(*str)))
1052 SysFreeString(str);
1053 IScriptProcedure_AddRef(&proc->IScriptProcedure_iface);
1054 *procedure = &proc->IScriptProcedure_iface;
1055 goto done;
1059 if (!(proc = heap_alloc(sizeof(*proc))))
1061 hr = E_OUTOFMEMORY;
1062 SysFreeString(str);
1063 goto done;
1066 proc->IScriptProcedure_iface.lpVtbl = &ScriptProcedureVtbl;
1067 proc->ref = 1;
1068 proc->hash = hash;
1069 proc->name = str;
1070 proc->num_args = desc->cParams + desc->cParamsOpt;
1071 proc->ret_type = desc->elemdescFunc.tdesc.vt;
1072 list_add_tail(proc_list, &proc->entry);
1074 *procedure = &proc->IScriptProcedure_iface;
1076 done:
1077 ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
1078 return hr;
1081 static HRESULT WINAPI procedure_enum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
1083 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1085 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumVARIANT, riid))
1087 *ppv = &This->IEnumVARIANT_iface;
1089 else
1091 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1092 *ppv = NULL;
1093 return E_NOINTERFACE;
1096 IUnknown_AddRef((IUnknown*)*ppv);
1097 return S_OK;
1100 static ULONG WINAPI procedure_enum_AddRef(IEnumVARIANT *iface)
1102 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1103 LONG ref = InterlockedIncrement(&This->ref);
1105 TRACE("(%p) ref=%d\n", This, ref);
1107 return ref;
1110 static ULONG WINAPI procedure_enum_Release(IEnumVARIANT *iface)
1112 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1113 LONG ref = InterlockedDecrement(&This->ref);
1115 TRACE("(%p) ref=%d\n", This, ref);
1117 if (!ref)
1119 IScriptProcedureCollection_Release(&This->procedures->IScriptProcedureCollection_iface);
1120 heap_free(This);
1123 return ref;
1126 static HRESULT WINAPI procedure_enum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
1128 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1129 FUNCDESC *desc;
1130 ITypeInfo *ti;
1131 UINT i, num;
1132 HRESULT hr;
1134 TRACE("(%p)->(%u %p %p)\n", This, celt, rgVar, pCeltFetched);
1136 if (!rgVar) return E_POINTER;
1137 if (!This->procedures->module->host) return E_FAIL;
1139 hr = start_script(This->procedures->module);
1140 if (FAILED(hr)) return hr;
1142 hr = get_script_typeinfo(This->procedures->module, &ti);
1143 if (FAILED(hr)) return hr;
1145 num = min(celt, This->count - This->pos);
1146 for (i = 0; i < num; i++)
1148 hr = ITypeInfo_GetFuncDesc(ti, This->pos + i, &desc);
1149 if (FAILED(hr)) break;
1151 hr = get_script_procedure(This->procedures, ti, desc, (IScriptProcedure**)&V_DISPATCH(rgVar + i));
1152 if (FAILED(hr)) break;
1154 V_VT(rgVar + i) = VT_DISPATCH;
1157 if (FAILED(hr))
1159 while (i--)
1160 VariantClear(rgVar + i);
1161 if (pCeltFetched) *pCeltFetched = 0;
1162 return hr;
1165 This->pos += i;
1167 if (pCeltFetched) *pCeltFetched = i;
1168 return i == celt ? S_OK : S_FALSE;
1171 static HRESULT WINAPI procedure_enum_Skip(IEnumVARIANT *iface, ULONG celt)
1173 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1175 TRACE("(%p)->(%u)\n", This, celt);
1177 if (This->count - This->pos < celt)
1179 This->pos = This->count;
1180 return S_FALSE;
1182 This->pos += celt;
1183 return S_OK;
1186 static HRESULT WINAPI procedure_enum_Reset(IEnumVARIANT *iface)
1188 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1190 TRACE("(%p)\n", This);
1192 This->pos = 0;
1193 return S_OK;
1196 static HRESULT WINAPI procedure_enum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
1198 struct procedure_enum *This = procedure_enum_from_IEnumVARIANT(iface);
1199 struct procedure_enum *clone;
1201 TRACE("(%p)->(%p)\n", This, ppEnum);
1203 if (!ppEnum) return E_POINTER;
1205 if (!(clone = heap_alloc(sizeof(*clone))))
1206 return E_OUTOFMEMORY;
1208 *clone = *This;
1209 clone->ref = 1;
1210 IScriptProcedureCollection_AddRef(&This->procedures->IScriptProcedureCollection_iface);
1212 *ppEnum = &clone->IEnumVARIANT_iface;
1213 return S_OK;
1216 static const IEnumVARIANTVtbl procedure_enum_vtbl = {
1217 procedure_enum_QueryInterface,
1218 procedure_enum_AddRef,
1219 procedure_enum_Release,
1220 procedure_enum_Next,
1221 procedure_enum_Skip,
1222 procedure_enum_Reset,
1223 procedure_enum_Clone
1226 static HRESULT WINAPI ScriptProcedureCollection_QueryInterface(IScriptProcedureCollection *iface, REFIID riid, void **ppv)
1228 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1230 if (IsEqualGUID(&IID_IDispatch, riid) || IsEqualGUID(&IID_IUnknown, riid) ||
1231 IsEqualGUID(&IID_IScriptProcedureCollection, riid))
1233 *ppv = &This->IScriptProcedureCollection_iface;
1235 else
1237 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1238 *ppv = NULL;
1239 return E_NOINTERFACE;
1242 IUnknown_AddRef((IUnknown*)*ppv);
1243 return S_OK;
1246 static ULONG WINAPI ScriptProcedureCollection_AddRef(IScriptProcedureCollection *iface)
1248 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1249 LONG ref = InterlockedIncrement(&This->ref);
1251 TRACE("(%p) ref=%d\n", This, ref);
1253 return ref;
1256 static ULONG WINAPI ScriptProcedureCollection_Release(IScriptProcedureCollection *iface)
1258 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1259 LONG ref = InterlockedDecrement(&This->ref);
1260 UINT i;
1262 TRACE("(%p) ref=%d\n", This, ref);
1264 if (!ref)
1266 /* Unlink any dangling items from the hash table */
1267 for (i = 0; i < ARRAY_SIZE(This->hash_table); i++)
1268 list_remove(&This->hash_table[i]);
1270 This->module->procedures = NULL;
1271 IScriptModule_Release(&This->module->IScriptModule_iface);
1272 heap_free(This);
1274 return ref;
1277 static HRESULT WINAPI ScriptProcedureCollection_GetTypeInfoCount(IScriptProcedureCollection *iface, UINT *pctinfo)
1279 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1281 TRACE("(%p)->(%p)\n", This, pctinfo);
1283 *pctinfo = 1;
1284 return S_OK;
1287 static HRESULT WINAPI ScriptProcedureCollection_GetTypeInfo(IScriptProcedureCollection *iface, UINT iTInfo,
1288 LCID lcid, ITypeInfo **ppTInfo)
1290 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1292 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1294 return get_typeinfo(IScriptProcedureCollection_tid, ppTInfo);
1297 static HRESULT WINAPI ScriptProcedureCollection_GetIDsOfNames(IScriptProcedureCollection *iface, REFIID riid,
1298 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1300 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1301 ITypeInfo *typeinfo;
1302 HRESULT hr;
1304 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1306 hr = get_typeinfo(IScriptProcedureCollection_tid, &typeinfo);
1307 if (SUCCEEDED(hr))
1309 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1310 ITypeInfo_Release(typeinfo);
1313 return hr;
1316 static HRESULT WINAPI ScriptProcedureCollection_Invoke(IScriptProcedureCollection *iface, DISPID dispIdMember,
1317 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1318 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1320 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1321 ITypeInfo *typeinfo;
1322 HRESULT hr;
1324 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1325 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1327 hr = get_typeinfo(IScriptProcedureCollection_tid, &typeinfo);
1328 if(SUCCEEDED(hr))
1330 hr = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
1331 pDispParams, pVarResult, pExcepInfo, puArgErr);
1332 ITypeInfo_Release(typeinfo);
1335 return hr;
1338 static HRESULT WINAPI ScriptProcedureCollection_get__NewEnum(IScriptProcedureCollection *iface, IUnknown **ppenumProcedures)
1340 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1341 struct procedure_enum *proc_enum;
1342 TYPEATTR *attr;
1343 ITypeInfo *ti;
1344 UINT count;
1345 HRESULT hr;
1347 TRACE("(%p)->(%p)\n", This, ppenumProcedures);
1349 if (!ppenumProcedures) return E_POINTER;
1350 if (!This->module->host) return E_FAIL;
1352 hr = start_script(This->module);
1353 if (FAILED(hr)) return hr;
1355 hr = get_script_typeinfo(This->module, &ti);
1356 if (FAILED(hr)) return hr;
1358 hr = ITypeInfo_GetTypeAttr(ti, &attr);
1359 if (FAILED(hr)) return hr;
1361 count = attr->cFuncs;
1362 ITypeInfo_ReleaseTypeAttr(ti, attr);
1364 if (!(proc_enum = heap_alloc(sizeof(*proc_enum))))
1365 return E_OUTOFMEMORY;
1367 proc_enum->IEnumVARIANT_iface.lpVtbl = &procedure_enum_vtbl;
1368 proc_enum->ref = 1;
1369 proc_enum->pos = 0;
1370 proc_enum->count = count;
1371 proc_enum->procedures = This;
1372 IScriptProcedureCollection_AddRef(&This->IScriptProcedureCollection_iface);
1374 *ppenumProcedures = (IUnknown*)&proc_enum->IEnumVARIANT_iface;
1375 return S_OK;
1378 static HRESULT WINAPI ScriptProcedureCollection_get_Item(IScriptProcedureCollection *iface, VARIANT index,
1379 IScriptProcedure **ppdispProcedure)
1381 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1382 ITypeInfo *typeinfo;
1383 FUNCDESC *desc;
1384 HRESULT hr;
1386 TRACE("(%p)->(%s %p)\n", This, wine_dbgstr_variant(&index), ppdispProcedure);
1388 if (!ppdispProcedure) return E_POINTER;
1389 if (!This->module->host) return E_FAIL;
1391 hr = start_script(This->module);
1392 if (FAILED(hr)) return hr;
1394 hr = get_script_typeinfo(This->module, &typeinfo);
1395 if (FAILED(hr)) return hr;
1397 if (V_VT(&index) == VT_BSTR)
1399 struct list *proc_list;
1400 ScriptProcedure *proc;
1401 ITypeComp *comp;
1402 BINDPTR bindptr;
1403 DESCKIND kind;
1404 ULONG hash;
1405 UINT len;
1407 len = SysStringLen(V_BSTR(&index));
1408 hash = LHashValOfNameSys(sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32, LOCALE_USER_DEFAULT, V_BSTR(&index));
1409 proc_list = &This->hash_table[hash % ARRAY_SIZE(This->hash_table)];
1411 /* Try to find it in the hash table */
1412 LIST_FOR_EACH_ENTRY(proc, proc_list, ScriptProcedure, entry)
1414 if (proc->hash == hash && SysStringLen(proc->name) == len &&
1415 !memcmp(proc->name, V_BSTR(&index), len * sizeof(WCHAR)))
1417 IScriptProcedure_AddRef(&proc->IScriptProcedure_iface);
1418 *ppdispProcedure = &proc->IScriptProcedure_iface;
1419 return S_OK;
1423 hr = get_script_typecomp(This->module, typeinfo, &comp);
1424 if (FAILED(hr)) return hr;
1426 hr = ITypeComp_Bind(comp, V_BSTR(&index), hash, INVOKE_FUNC, &typeinfo, &kind, &bindptr);
1427 if (FAILED(hr)) return hr;
1429 switch (kind)
1431 case DESCKIND_FUNCDESC:
1432 hr = get_script_procedure(This, typeinfo, bindptr.lpfuncdesc, ppdispProcedure);
1433 ITypeInfo_Release(typeinfo);
1434 return hr;
1435 case DESCKIND_IMPLICITAPPOBJ:
1436 case DESCKIND_VARDESC:
1437 ITypeInfo_ReleaseVarDesc(typeinfo, bindptr.lpvardesc);
1438 ITypeInfo_Release(typeinfo);
1439 break;
1440 case DESCKIND_TYPECOMP:
1441 ITypeComp_Release(bindptr.lptcomp);
1442 break;
1443 default:
1444 break;
1446 return CTL_E_ILLEGALFUNCTIONCALL;
1449 hr = VariantChangeType(&index, &index, 0, VT_INT);
1450 if (FAILED(hr)) return hr;
1451 if (V_INT(&index) <= 0) return 0x800a0009;
1453 hr = ITypeInfo_GetFuncDesc(typeinfo, V_INT(&index) - 1, &desc);
1454 if (FAILED(hr)) return hr;
1456 return get_script_procedure(This, typeinfo, desc, ppdispProcedure);
1459 static HRESULT WINAPI ScriptProcedureCollection_get_Count(IScriptProcedureCollection *iface, LONG *plCount)
1461 ScriptProcedureCollection *This = impl_from_IScriptProcedureCollection(iface);
1462 TYPEATTR *attr;
1463 ITypeInfo *ti;
1464 HRESULT hr;
1466 TRACE("(%p)->(%p)\n", This, plCount);
1468 if (!plCount) return E_POINTER;
1469 if (!This->module->host) return E_FAIL;
1471 if (This->count == -1)
1473 hr = start_script(This->module);
1474 if (FAILED(hr)) return hr;
1476 hr = get_script_typeinfo(This->module, &ti);
1477 if (FAILED(hr)) return hr;
1479 hr = ITypeInfo_GetTypeAttr(ti, &attr);
1480 if (FAILED(hr)) return hr;
1482 This->count = attr->cFuncs;
1483 ITypeInfo_ReleaseTypeAttr(ti, attr);
1486 *plCount = This->count;
1487 return S_OK;
1490 static const IScriptProcedureCollectionVtbl ScriptProcedureCollectionVtbl = {
1491 ScriptProcedureCollection_QueryInterface,
1492 ScriptProcedureCollection_AddRef,
1493 ScriptProcedureCollection_Release,
1494 ScriptProcedureCollection_GetTypeInfoCount,
1495 ScriptProcedureCollection_GetTypeInfo,
1496 ScriptProcedureCollection_GetIDsOfNames,
1497 ScriptProcedureCollection_Invoke,
1498 ScriptProcedureCollection_get__NewEnum,
1499 ScriptProcedureCollection_get_Item,
1500 ScriptProcedureCollection_get_Count
1503 static void detach_script_host(ScriptHost *host)
1505 if (--host->module_count)
1506 return;
1508 if (host->script) {
1509 IActiveScript_Close(host->script);
1510 IActiveScript_Release(host->script);
1513 if (host->parse)
1514 IActiveScriptParse_Release(host->parse);
1516 if (host->error)
1517 IScriptError_Release(&host->error->IScriptError_iface);
1519 host->parse = NULL;
1520 host->error = NULL;
1521 host->script = NULL;
1524 static void detach_module(ScriptModule *module)
1526 ScriptHost *host = module->host;
1528 if (host) {
1529 module->host = NULL;
1530 detach_script_host(host);
1531 IActiveScriptSite_Release(&host->IActiveScriptSite_iface);
1535 static HRESULT WINAPI ScriptModule_QueryInterface(IScriptModule *iface, REFIID riid, void **ppv)
1537 ScriptModule *This = impl_from_IScriptModule(iface);
1539 if (IsEqualGUID(&IID_IDispatch, riid) || IsEqualGUID(&IID_IUnknown, riid) ||
1540 IsEqualGUID(&IID_IScriptModule, riid))
1542 *ppv = &This->IScriptModule_iface;
1544 else
1546 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1547 *ppv = NULL;
1548 return E_NOINTERFACE;
1551 IUnknown_AddRef((IUnknown*)*ppv);
1552 return S_OK;
1555 static ULONG WINAPI ScriptModule_AddRef(IScriptModule *iface)
1557 ScriptModule *This = impl_from_IScriptModule(iface);
1558 LONG ref = InterlockedIncrement(&This->ref);
1560 TRACE("(%p) ref=%d\n", This, ref);
1562 return ref;
1565 static ULONG WINAPI ScriptModule_Release(IScriptModule *iface)
1567 ScriptModule *This = impl_from_IScriptModule(iface);
1568 LONG ref = InterlockedDecrement(&This->ref);
1570 TRACE("(%p) ref=%d\n", This, ref);
1572 if (!ref)
1574 detach_module(This);
1575 SysFreeString(This->name);
1576 uncache_module_objects(This);
1577 heap_free(This);
1580 return ref;
1583 static HRESULT WINAPI ScriptModule_GetTypeInfoCount(IScriptModule *iface, UINT *pctinfo)
1585 ScriptModule *This = impl_from_IScriptModule(iface);
1587 TRACE("(%p)->(%p)\n", This, pctinfo);
1589 *pctinfo = 1;
1590 return S_OK;
1593 static HRESULT WINAPI ScriptModule_GetTypeInfo(IScriptModule *iface, UINT iTInfo,
1594 LCID lcid, ITypeInfo **ppTInfo)
1596 ScriptModule *This = impl_from_IScriptModule(iface);
1598 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1600 return get_typeinfo(IScriptModule_tid, ppTInfo);
1603 static HRESULT WINAPI ScriptModule_GetIDsOfNames(IScriptModule *iface, REFIID riid,
1604 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1606 ScriptModule *This = impl_from_IScriptModule(iface);
1607 ITypeInfo *typeinfo;
1608 HRESULT hr;
1610 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
1612 hr = get_typeinfo(IScriptModule_tid, &typeinfo);
1613 if (SUCCEEDED(hr))
1615 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1616 ITypeInfo_Release(typeinfo);
1619 return hr;
1622 static HRESULT WINAPI ScriptModule_Invoke(IScriptModule *iface, DISPID dispIdMember,
1623 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1624 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1626 ScriptModule *This = impl_from_IScriptModule(iface);
1627 ITypeInfo *typeinfo;
1628 HRESULT hr;
1630 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1631 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1633 hr = get_typeinfo(IScriptModule_tid, &typeinfo);
1634 if(SUCCEEDED(hr))
1636 hr = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
1637 pDispParams, pVarResult, pExcepInfo, puArgErr);
1638 ITypeInfo_Release(typeinfo);
1641 return hr;
1644 static HRESULT WINAPI ScriptModule_get_Name(IScriptModule *iface, BSTR *pbstrName)
1646 ScriptModule *This = impl_from_IScriptModule(iface);
1648 TRACE("(%p)->(%p)\n", This, pbstrName);
1650 if (!pbstrName) return E_POINTER;
1651 if (!This->host) return E_FAIL;
1653 *pbstrName = SysAllocString(This->name ? This->name : L"Global");
1654 return *pbstrName ? S_OK : E_OUTOFMEMORY;
1657 static HRESULT WINAPI ScriptModule_get_CodeObject(IScriptModule *iface, IDispatch **ppdispObject)
1659 ScriptModule *This = impl_from_IScriptModule(iface);
1660 HRESULT hr;
1662 TRACE("(%p)->(%p)\n", This, ppdispObject);
1664 if (!This->host) return E_FAIL;
1666 hr = start_script(This);
1667 if (FAILED(hr)) return hr;
1669 hr = get_script_dispatch(This, ppdispObject);
1670 if (FAILED(hr)) return hr;
1672 IDispatch_AddRef(*ppdispObject);
1673 return hr;
1676 static HRESULT WINAPI ScriptModule_get_Procedures(IScriptModule *iface, IScriptProcedureCollection **ppdispProcedures)
1678 ScriptModule *This = impl_from_IScriptModule(iface);
1680 TRACE("(%p)->(%p)\n", This, ppdispProcedures);
1682 if (!This->host)
1683 return E_FAIL;
1685 if (This->procedures)
1686 IScriptProcedureCollection_AddRef(&This->procedures->IScriptProcedureCollection_iface);
1687 else
1689 ScriptProcedureCollection *procs;
1690 UINT i;
1692 if (!(procs = heap_alloc(sizeof(*procs))))
1693 return E_OUTOFMEMORY;
1695 procs->IScriptProcedureCollection_iface.lpVtbl = &ScriptProcedureCollectionVtbl;
1696 procs->ref = 1;
1697 procs->count = -1;
1698 procs->module = This;
1699 for (i = 0; i < ARRAY_SIZE(procs->hash_table); i++)
1700 list_init(&procs->hash_table[i]);
1702 This->procedures = procs;
1703 IScriptModule_AddRef(&This->IScriptModule_iface);
1706 *ppdispProcedures = &This->procedures->IScriptProcedureCollection_iface;
1707 return S_OK;
1710 static HRESULT WINAPI ScriptModule_AddCode(IScriptModule *iface, BSTR code)
1712 ScriptModule *This = impl_from_IScriptModule(iface);
1714 TRACE("(%p)->(%s)\n", This, debugstr_w(code));
1716 if (!This->host)
1717 return E_FAIL;
1719 return parse_script_text(This, code, SCRIPTTEXT_ISVISIBLE, NULL);
1722 static HRESULT WINAPI ScriptModule_Eval(IScriptModule *iface, BSTR expression, VARIANT *res)
1724 ScriptModule *This = impl_from_IScriptModule(iface);
1726 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(expression), res);
1728 if (!res)
1729 return E_POINTER;
1730 V_VT(res) = VT_EMPTY;
1731 if (!This->host)
1732 return E_FAIL;
1734 return parse_script_text(This, expression, SCRIPTTEXT_ISEXPRESSION, res);
1737 static HRESULT WINAPI ScriptModule_ExecuteStatement(IScriptModule *iface, BSTR statement)
1739 ScriptModule *This = impl_from_IScriptModule(iface);
1741 TRACE("(%p)->(%s)\n", This, debugstr_w(statement));
1743 if (!This->host)
1744 return E_FAIL;
1746 return parse_script_text(This, statement, 0, NULL);
1749 static HRESULT WINAPI ScriptModule_Run(IScriptModule *iface, BSTR procedure_name, SAFEARRAY **parameters, VARIANT *res)
1751 ScriptModule *This = impl_from_IScriptModule(iface);
1752 SAFEARRAY *sa;
1754 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(procedure_name), parameters, res);
1756 if (!parameters || !res) return E_POINTER;
1757 if (!(sa = *parameters)) return E_POINTER;
1759 V_VT(res) = VT_EMPTY;
1760 if (sa->cDims == 0) return DISP_E_BADINDEX;
1761 if (!(sa->fFeatures & FADF_VARIANT)) return DISP_E_BADVARTYPE;
1762 if (!This->host) return E_FAIL;
1764 return run_procedure(This, procedure_name, sa, res);
1767 static const IScriptModuleVtbl ScriptModuleVtbl = {
1768 ScriptModule_QueryInterface,
1769 ScriptModule_AddRef,
1770 ScriptModule_Release,
1771 ScriptModule_GetTypeInfoCount,
1772 ScriptModule_GetTypeInfo,
1773 ScriptModule_GetIDsOfNames,
1774 ScriptModule_Invoke,
1775 ScriptModule_get_Name,
1776 ScriptModule_get_CodeObject,
1777 ScriptModule_get_Procedures,
1778 ScriptModule_AddCode,
1779 ScriptModule_Eval,
1780 ScriptModule_ExecuteStatement,
1781 ScriptModule_Run
1784 static HRESULT WINAPI module_enum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
1786 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1788 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IEnumVARIANT, riid))
1790 *ppv = &This->IEnumVARIANT_iface;
1792 else
1794 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1795 *ppv = NULL;
1796 return E_NOINTERFACE;
1799 IUnknown_AddRef((IUnknown*)*ppv);
1800 return S_OK;
1803 static ULONG WINAPI module_enum_AddRef(IEnumVARIANT *iface)
1805 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1806 LONG ref = InterlockedIncrement(&This->ref);
1808 TRACE("(%p) ref=%d\n", This, ref);
1810 return ref;
1813 static ULONG WINAPI module_enum_Release(IEnumVARIANT *iface)
1815 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1816 LONG ref = InterlockedDecrement(&This->ref);
1818 TRACE("(%p) ref=%d\n", This, ref);
1820 if (!ref)
1822 IActiveScriptSite_Release(&This->host->IActiveScriptSite_iface);
1823 IScriptControl_Release(&This->control->IScriptControl_iface);
1824 heap_free(This);
1827 return ref;
1830 static HRESULT WINAPI module_enum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
1832 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1833 unsigned int i, num;
1835 TRACE("(%p)->(%u %p %p)\n", This, celt, rgVar, pCeltFetched);
1837 if (!rgVar) return E_POINTER;
1838 if (This->host != This->control->host) return E_FAIL;
1840 num = min(celt, This->host->module_count - This->pos);
1841 for (i = 0; i < num; i++)
1843 V_VT(rgVar + i) = VT_DISPATCH;
1844 V_DISPATCH(rgVar + i) = (IDispatch*)(&This->control->modules[This->pos++]->IScriptModule_iface);
1845 IDispatch_AddRef(V_DISPATCH(rgVar + i));
1848 if (pCeltFetched) *pCeltFetched = i;
1849 return i == celt ? S_OK : S_FALSE;
1852 static HRESULT WINAPI module_enum_Skip(IEnumVARIANT *iface, ULONG celt)
1854 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1856 TRACE("(%p)->(%u)\n", This, celt);
1858 if (This->host != This->control->host) return E_FAIL;
1860 if (This->host->module_count - This->pos < celt)
1862 This->pos = This->host->module_count;
1863 return S_FALSE;
1865 This->pos += celt;
1866 return S_OK;
1869 static HRESULT WINAPI module_enum_Reset(IEnumVARIANT *iface)
1871 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1873 TRACE("(%p)\n", This);
1875 if (This->host != This->control->host) return E_FAIL;
1877 This->pos = 0;
1878 return S_OK;
1881 static HRESULT WINAPI module_enum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
1883 struct module_enum *This = module_enum_from_IEnumVARIANT(iface);
1884 struct module_enum *clone;
1886 TRACE("(%p)->(%p)\n", This, ppEnum);
1888 if (!ppEnum) return E_POINTER;
1889 if (This->host != This->control->host) return E_FAIL;
1891 if (!(clone = heap_alloc(sizeof(*clone))))
1892 return E_OUTOFMEMORY;
1894 *clone = *This;
1895 clone->ref = 1;
1896 IActiveScriptSite_AddRef(&This->host->IActiveScriptSite_iface);
1897 IScriptControl_AddRef(&This->control->IScriptControl_iface);
1899 *ppEnum = &clone->IEnumVARIANT_iface;
1900 return S_OK;
1903 static const IEnumVARIANTVtbl module_enum_vtbl = {
1904 module_enum_QueryInterface,
1905 module_enum_AddRef,
1906 module_enum_Release,
1907 module_enum_Next,
1908 module_enum_Skip,
1909 module_enum_Reset,
1910 module_enum_Clone
1913 static ScriptModule *create_module(ScriptHost *host, BSTR name)
1915 ScriptModule *module;
1917 if (!(module = heap_alloc_zero(sizeof(*module)))) return NULL;
1919 module->IScriptModule_iface.lpVtbl = &ScriptModuleVtbl;
1920 module->ref = 1;
1921 if (name && !(module->name = SysAllocString(name)))
1923 heap_free(module);
1924 return NULL;
1926 module->host = host;
1927 IActiveScriptSite_AddRef(&host->IActiveScriptSite_iface);
1928 return module;
1931 static void release_modules(ScriptControl *control, BOOL force_detach)
1933 unsigned int i, module_count = control->host->module_count;
1935 for (i = 0; i < module_count; i++) {
1936 if (force_detach) detach_module(control->modules[i]);
1937 IScriptModule_Release(&control->modules[i]->IScriptModule_iface);
1940 heap_free(control->modules);
1943 static ScriptModule *find_module(ScriptControl *control, BSTR name)
1945 unsigned int i;
1947 if (!wcsicmp(name, L"Global"))
1948 return control->modules[0];
1950 for (i = 1; i < control->host->module_count; i++)
1952 if (!wcsicmp(name, control->modules[i]->name))
1953 return control->modules[i];
1955 return NULL;
1958 static HRESULT WINAPI ScriptModuleCollection_QueryInterface(IScriptModuleCollection *iface, REFIID riid, void **ppv)
1960 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
1962 if (IsEqualGUID(&IID_IDispatch, riid) || IsEqualGUID(&IID_IUnknown, riid) ||
1963 IsEqualGUID(&IID_IScriptModuleCollection, riid))
1965 *ppv = &This->IScriptModuleCollection_iface;
1967 else
1969 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1970 *ppv = NULL;
1971 return E_NOINTERFACE;
1974 IUnknown_AddRef((IUnknown*)*ppv);
1975 return S_OK;
1978 static ULONG WINAPI ScriptModuleCollection_AddRef(IScriptModuleCollection *iface)
1980 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
1981 return IScriptControl_AddRef(&This->IScriptControl_iface);
1984 static ULONG WINAPI ScriptModuleCollection_Release(IScriptModuleCollection *iface)
1986 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
1987 return IScriptControl_Release(&This->IScriptControl_iface);
1990 static HRESULT WINAPI ScriptModuleCollection_GetTypeInfoCount(IScriptModuleCollection *iface, UINT *pctinfo)
1992 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
1994 TRACE("(%p)->(%p)\n", This, pctinfo);
1996 *pctinfo = 1;
1997 return S_OK;
2000 static HRESULT WINAPI ScriptModuleCollection_GetTypeInfo(IScriptModuleCollection *iface, UINT iTInfo,
2001 LCID lcid, ITypeInfo **ppTInfo)
2003 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2005 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2007 return get_typeinfo(IScriptModuleCollection_tid, ppTInfo);
2010 static HRESULT WINAPI ScriptModuleCollection_GetIDsOfNames(IScriptModuleCollection *iface, REFIID riid,
2011 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2013 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2014 ITypeInfo *typeinfo;
2015 HRESULT hr;
2017 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2019 hr = get_typeinfo(IScriptModuleCollection_tid, &typeinfo);
2020 if (SUCCEEDED(hr))
2022 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2023 ITypeInfo_Release(typeinfo);
2026 return hr;
2029 static HRESULT WINAPI ScriptModuleCollection_Invoke(IScriptModuleCollection *iface, DISPID dispIdMember,
2030 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2031 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2033 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2034 ITypeInfo *typeinfo;
2035 HRESULT hr;
2037 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2038 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2040 hr = get_typeinfo(IScriptModuleCollection_tid, &typeinfo);
2041 if(SUCCEEDED(hr))
2043 hr = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
2044 pDispParams, pVarResult, pExcepInfo, puArgErr);
2045 ITypeInfo_Release(typeinfo);
2048 return hr;
2051 static HRESULT WINAPI ScriptModuleCollection_get__NewEnum(IScriptModuleCollection *iface, IUnknown **ppenumContexts)
2053 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2054 struct module_enum *module_enum;
2056 TRACE("(%p)->(%p)\n", This, ppenumContexts);
2058 if (!ppenumContexts) return E_POINTER;
2059 if (!This->host) return E_FAIL;
2061 if (!(module_enum = heap_alloc(sizeof(*module_enum))))
2062 return E_OUTOFMEMORY;
2064 module_enum->IEnumVARIANT_iface.lpVtbl = &module_enum_vtbl;
2065 module_enum->ref = 1;
2066 module_enum->pos = 0;
2067 module_enum->host = This->host;
2068 module_enum->control = This;
2069 IActiveScriptSite_AddRef(&This->host->IActiveScriptSite_iface);
2070 IScriptControl_AddRef(&This->IScriptControl_iface);
2072 *ppenumContexts = (IUnknown*)&module_enum->IEnumVARIANT_iface;
2073 return S_OK;
2076 static HRESULT WINAPI ScriptModuleCollection_get_Item(IScriptModuleCollection *iface, VARIANT index,
2077 IScriptModule **ppmod)
2079 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2080 ScriptModule *module;
2081 unsigned int i;
2082 HRESULT hr;
2084 TRACE("(%p)->(%s %p)\n", This, wine_dbgstr_variant(&index), ppmod);
2086 if (!ppmod) return E_POINTER;
2087 if (!This->host) return E_FAIL;
2089 if (V_VT(&index) == VT_BSTR)
2091 module = find_module(This, V_BSTR(&index));
2092 if (!module) return CTL_E_ILLEGALFUNCTIONCALL;
2094 else
2096 hr = VariantChangeType(&index, &index, 0, VT_INT);
2097 if (FAILED(hr)) return hr;
2099 i = V_INT(&index) - 1;
2100 if (i >= This->host->module_count) return 0x800a0009;
2102 module = This->modules[i];
2105 *ppmod = &module->IScriptModule_iface;
2106 IScriptModule_AddRef(*ppmod);
2107 return S_OK;
2110 static HRESULT WINAPI ScriptModuleCollection_get_Count(IScriptModuleCollection *iface, LONG *plCount)
2112 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2114 TRACE("(%p)->(%p)\n", This, plCount);
2116 if (!plCount) return E_POINTER;
2117 if (!This->host) return E_FAIL;
2119 *plCount = This->host->module_count;
2120 return S_OK;
2123 static HRESULT WINAPI ScriptModuleCollection_Add(IScriptModuleCollection *iface, BSTR name,
2124 VARIANT *object, IScriptModule **ppmod)
2126 ScriptControl *This = impl_from_IScriptModuleCollection(iface);
2127 ScriptModule *module, **modules;
2128 ScriptHost *host = This->host;
2129 HRESULT hr;
2131 TRACE("(%p)->(%s %s %p)\n", This, wine_dbgstr_w(name), wine_dbgstr_variant(object), ppmod);
2133 if (!ppmod) return E_POINTER;
2134 if (!name || V_VT(object) != VT_DISPATCH) return E_INVALIDARG;
2135 if (!host) return E_FAIL;
2136 if (find_module(This, name)) return E_INVALIDARG;
2138 /* See if we need to grow the array */
2139 if (is_power_of_2(host->module_count))
2141 modules = heap_realloc(This->modules, host->module_count * 2 * sizeof(*This->modules));
2142 if (!modules) return E_OUTOFMEMORY;
2143 This->modules = modules;
2146 if (!(module = create_module(host, name)))
2147 return E_OUTOFMEMORY;
2149 /* If no object, Windows only calls AddNamedItem without adding a NULL object */
2150 if (V_DISPATCH(object))
2151 hr = add_script_object(host, name, V_DISPATCH(object), 0);
2152 else
2153 hr = IActiveScript_AddNamedItem(host->script, name, SCRIPTITEM_CODEONLY);
2155 if (FAILED(hr))
2157 IScriptModule_Release(&module->IScriptModule_iface);
2158 return hr;
2160 This->modules[host->module_count++] = module;
2162 *ppmod = &module->IScriptModule_iface;
2163 IScriptModule_AddRef(*ppmod);
2164 return S_OK;
2167 static const IScriptModuleCollectionVtbl ScriptModuleCollectionVtbl = {
2168 ScriptModuleCollection_QueryInterface,
2169 ScriptModuleCollection_AddRef,
2170 ScriptModuleCollection_Release,
2171 ScriptModuleCollection_GetTypeInfoCount,
2172 ScriptModuleCollection_GetTypeInfo,
2173 ScriptModuleCollection_GetIDsOfNames,
2174 ScriptModuleCollection_Invoke,
2175 ScriptModuleCollection_get__NewEnum,
2176 ScriptModuleCollection_get_Item,
2177 ScriptModuleCollection_get_Count,
2178 ScriptModuleCollection_Add
2181 static void fill_error_info(ScriptError *error)
2183 EXCEPINFO info;
2185 if (error->info_filled) return;
2186 error->info_filled = TRUE;
2188 if (!error->object)
2189 return;
2190 if (FAILED(IActiveScriptError_GetExceptionInfo(error->object, &info)))
2191 return;
2192 if (info.pfnDeferredFillIn)
2193 info.pfnDeferredFillIn(&info);
2195 error->number = info.scode;
2196 error->source = info.bstrSource;
2197 error->desc = info.bstrDescription;
2198 error->help_file = info.bstrHelpFile;
2199 error->help_context = info.dwHelpContext;
2202 static void fill_error_text(ScriptError *error)
2204 if (error->text_filled) return;
2205 error->text_filled = TRUE;
2207 if (error->object)
2208 IActiveScriptError_GetSourceLineText(error->object, &error->text);
2211 static void fill_error_pos(ScriptError *error)
2213 DWORD context;
2214 LONG column;
2215 ULONG line;
2217 if (error->pos_filled) return;
2218 error->pos_filled = TRUE;
2220 if (!error->object)
2221 return;
2222 if (FAILED(IActiveScriptError_GetSourcePosition(error->object, &context, &line, &column)))
2223 return;
2225 error->line = line;
2226 error->column = column;
2229 static HRESULT WINAPI ScriptError_QueryInterface(IScriptError *iface, REFIID riid, void **ppv)
2231 ScriptError *This = impl_from_IScriptError(iface);
2233 if (IsEqualGUID(&IID_IDispatch, riid) || IsEqualGUID(&IID_IUnknown, riid) ||
2234 IsEqualGUID(&IID_IScriptError, riid))
2236 *ppv = &This->IScriptError_iface;
2238 else
2240 WARN("unsupported interface: (%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2241 *ppv = NULL;
2242 return E_NOINTERFACE;
2245 IUnknown_AddRef((IUnknown*)*ppv);
2246 return S_OK;
2249 static ULONG WINAPI ScriptError_AddRef(IScriptError *iface)
2251 ScriptError *This = impl_from_IScriptError(iface);
2252 LONG ref = InterlockedIncrement(&This->ref);
2254 TRACE("(%p) ref=%d\n", This, ref);
2256 return ref;
2259 static ULONG WINAPI ScriptError_Release(IScriptError *iface)
2261 ScriptError *This = impl_from_IScriptError(iface);
2262 LONG ref = InterlockedDecrement(&This->ref);
2264 TRACE("(%p) ref=%d\n", This, ref);
2266 if (!ref)
2268 IScriptError_Clear(&This->IScriptError_iface);
2269 heap_free(This);
2272 return ref;
2275 static HRESULT WINAPI ScriptError_GetTypeInfoCount(IScriptError *iface, UINT *pctinfo)
2277 ScriptError *This = impl_from_IScriptError(iface);
2279 TRACE("(%p)->(%p)\n", This, pctinfo);
2281 *pctinfo = 1;
2282 return S_OK;
2285 static HRESULT WINAPI ScriptError_GetTypeInfo(IScriptError *iface, UINT iTInfo,
2286 LCID lcid, ITypeInfo **ppTInfo)
2288 ScriptError *This = impl_from_IScriptError(iface);
2290 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2292 return get_typeinfo(IScriptError_tid, ppTInfo);
2295 static HRESULT WINAPI ScriptError_GetIDsOfNames(IScriptError *iface, REFIID riid,
2296 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2298 ScriptError *This = impl_from_IScriptError(iface);
2299 ITypeInfo *typeinfo;
2300 HRESULT hr;
2302 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2304 hr = get_typeinfo(IScriptError_tid, &typeinfo);
2305 if (SUCCEEDED(hr))
2307 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2308 ITypeInfo_Release(typeinfo);
2311 return hr;
2314 static HRESULT WINAPI ScriptError_Invoke(IScriptError *iface, DISPID dispIdMember,
2315 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2316 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2318 ScriptError *This = impl_from_IScriptError(iface);
2319 ITypeInfo *typeinfo;
2320 HRESULT hr;
2322 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2323 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2325 hr = get_typeinfo(IScriptError_tid, &typeinfo);
2326 if(SUCCEEDED(hr))
2328 hr = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
2329 pDispParams, pVarResult, pExcepInfo, puArgErr);
2330 ITypeInfo_Release(typeinfo);
2333 return hr;
2336 static HRESULT WINAPI ScriptError_get_Number(IScriptError *iface, LONG *plNumber)
2338 ScriptError *This = impl_from_IScriptError(iface);
2340 TRACE("(%p)->(%p)\n", This, plNumber);
2342 fill_error_info(This);
2343 *plNumber = This->number;
2344 return S_OK;
2347 static HRESULT WINAPI ScriptError_get_Source(IScriptError *iface, BSTR *pbstrSource)
2349 ScriptError *This = impl_from_IScriptError(iface);
2351 TRACE("(%p)->(%p)\n", This, pbstrSource);
2353 fill_error_info(This);
2354 *pbstrSource = SysAllocString(This->source);
2355 return S_OK;
2358 static HRESULT WINAPI ScriptError_get_Description(IScriptError *iface, BSTR *pbstrDescription)
2360 ScriptError *This = impl_from_IScriptError(iface);
2362 TRACE("(%p)->(%p)\n", This, pbstrDescription);
2364 fill_error_info(This);
2365 *pbstrDescription = SysAllocString(This->desc);
2366 return S_OK;
2369 static HRESULT WINAPI ScriptError_get_HelpFile(IScriptError *iface, BSTR *pbstrHelpFile)
2371 ScriptError *This = impl_from_IScriptError(iface);
2373 TRACE("(%p)->(%p)\n", This, pbstrHelpFile);
2375 fill_error_info(This);
2376 *pbstrHelpFile = SysAllocString(This->help_file);
2377 return S_OK;
2380 static HRESULT WINAPI ScriptError_get_HelpContext(IScriptError *iface, LONG *plHelpContext)
2382 ScriptError *This = impl_from_IScriptError(iface);
2384 TRACE("(%p)->(%p)\n", This, plHelpContext);
2386 fill_error_info(This);
2387 *plHelpContext = This->help_context;
2388 return S_OK;
2391 static HRESULT WINAPI ScriptError_get_Text(IScriptError *iface, BSTR *pbstrText)
2393 ScriptError *This = impl_from_IScriptError(iface);
2395 TRACE("(%p)->(%p)\n", This, pbstrText);
2397 fill_error_text(This);
2398 *pbstrText = SysAllocString(This->text);
2399 return S_OK;
2402 static HRESULT WINAPI ScriptError_get_Line(IScriptError *iface, LONG *plLine)
2404 ScriptError *This = impl_from_IScriptError(iface);
2406 TRACE("(%p)->(%p)\n", This, plLine);
2408 fill_error_pos(This);
2409 *plLine = This->line;
2410 return S_OK;
2413 static HRESULT WINAPI ScriptError_get_Column(IScriptError *iface, LONG *plColumn)
2415 ScriptError *This = impl_from_IScriptError(iface);
2417 TRACE("(%p)->(%p)\n", This, plColumn);
2419 fill_error_pos(This);
2420 *plColumn = This->column;
2421 return S_OK;
2424 static HRESULT WINAPI ScriptError_Clear(IScriptError *iface)
2426 ScriptError *This = impl_from_IScriptError(iface);
2428 TRACE("(%p)->()\n", This);
2430 if (This->object)
2432 IActiveScriptError_Release(This->object);
2433 This->object = NULL;
2435 SysFreeString(This->text);
2436 SysFreeString(This->source);
2437 SysFreeString(This->desc);
2438 SysFreeString(This->help_file);
2440 This->number = 0;
2441 This->text = NULL;
2442 This->source = NULL;
2443 This->desc = NULL;
2444 This->help_file = NULL;
2445 This->help_context = 0;
2446 This->line = 0;
2447 This->column = 0;
2449 This->info_filled = FALSE;
2450 This->text_filled = FALSE;
2451 This->pos_filled = FALSE;
2452 return S_OK;
2455 static const IScriptErrorVtbl ScriptErrorVtbl = {
2456 ScriptError_QueryInterface,
2457 ScriptError_AddRef,
2458 ScriptError_Release,
2459 ScriptError_GetTypeInfoCount,
2460 ScriptError_GetTypeInfo,
2461 ScriptError_GetIDsOfNames,
2462 ScriptError_Invoke,
2463 ScriptError_get_Number,
2464 ScriptError_get_Source,
2465 ScriptError_get_Description,
2466 ScriptError_get_HelpFile,
2467 ScriptError_get_HelpContext,
2468 ScriptError_get_Text,
2469 ScriptError_get_Line,
2470 ScriptError_get_Column,
2471 ScriptError_Clear
2474 static HRESULT set_safety_opts(IActiveScript *script, VARIANT_BOOL use_safe_subset)
2476 IObjectSafety *objsafety;
2477 HRESULT hr;
2479 hr = IActiveScript_QueryInterface(script, &IID_IObjectSafety, (void**)&objsafety);
2480 if (FAILED(hr)) {
2481 FIXME("Could not get IObjectSafety, %#x\n", hr);
2482 return hr;
2485 hr = IObjectSafety_SetInterfaceSafetyOptions(objsafety, &IID_IActiveScriptParse, INTERFACESAFE_FOR_UNTRUSTED_DATA,
2486 use_safe_subset ? INTERFACESAFE_FOR_UNTRUSTED_DATA : 0);
2487 IObjectSafety_Release(objsafety);
2488 if (FAILED(hr)) {
2489 FIXME("SetInterfaceSafetyOptions failed, %#x\n", hr);
2490 return hr;
2493 return hr;
2496 static HRESULT init_script_host(ScriptControl *control, const CLSID *clsid, ScriptHost **ret)
2498 ScriptHost *host;
2499 HRESULT hr;
2501 *ret = NULL;
2503 host = heap_alloc(sizeof(*host));
2504 if (!host)
2505 return E_OUTOFMEMORY;
2507 host->IActiveScriptSite_iface.lpVtbl = &ActiveScriptSiteVtbl;
2508 host->IActiveScriptSiteWindow_iface.lpVtbl = &ActiveScriptSiteWindowVtbl;
2509 host->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
2510 host->ref = 1;
2511 host->script = NULL;
2512 host->parse = NULL;
2513 host->clsid = *clsid;
2514 host->module_count = 1;
2515 list_init(&host->named_items);
2517 hr = CoCreateInstance(&host->clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2518 &IID_IActiveScript, (void**)&host->script);
2519 if (FAILED(hr)) {
2520 WARN("Failed to create an instance for %s, %#x\n", debugstr_guid(clsid), hr);
2521 goto failed;
2524 hr = set_safety_opts(host->script, control->use_safe_subset);
2525 if (FAILED(hr)) goto failed;
2527 hr = IActiveScript_SetScriptSite(host->script, &host->IActiveScriptSite_iface);
2528 if (FAILED(hr)) {
2529 WARN("SetScriptSite failed, %#x\n", hr);
2530 goto failed;
2533 hr = IActiveScript_QueryInterface(host->script, &IID_IActiveScriptParse, (void**)&host->parse);
2534 if (FAILED(hr)) {
2535 WARN("Failed to get IActiveScriptParse, %#x\n", hr);
2536 goto failed;
2539 hr = IActiveScriptParse_InitNew(host->parse);
2540 if (FAILED(hr)) {
2541 WARN("InitNew failed, %#x\n", hr);
2542 goto failed;
2544 host->script_state = SCRIPTSTATE_INITIALIZED;
2545 host->site_hwnd = control->allow_ui ? control->site_hwnd : ((HWND)-1);
2546 host->error = control->error;
2547 IScriptError_AddRef(&host->error->IScriptError_iface);
2549 *ret = host;
2550 return S_OK;
2552 failed:
2553 detach_script_host(host);
2554 return hr;
2557 static HRESULT WINAPI ScriptControl_QueryInterface(IScriptControl *iface, REFIID riid, void **ppv)
2559 ScriptControl *This = impl_from_IScriptControl(iface);
2561 if(IsEqualGUID(&IID_IUnknown, riid)) {
2562 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2563 *ppv = &This->IScriptControl_iface;
2564 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
2565 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
2566 *ppv = &This->IScriptControl_iface;
2567 }else if(IsEqualGUID(&IID_IScriptControl, riid)) {
2568 TRACE("(%p)->(IID_IScriptControl %p)\n", This, ppv);
2569 *ppv = &This->IScriptControl_iface;
2570 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
2571 TRACE("(%p)->(IID_IOleObject %p)\n", This, ppv);
2572 *ppv = &This->IOleObject_iface;
2573 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
2574 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
2575 *ppv = &This->IPersistStreamInit_iface;
2576 }else if(IsEqualGUID(&IID_IPersist, riid)) {
2577 TRACE("(%p)->(IID_IPersist %p)\n", This, ppv);
2578 *ppv = &This->IPersistStreamInit_iface;
2579 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
2580 TRACE("(%p)->(IID_IOleControl %p)\n", This, ppv);
2581 *ppv = &This->IOleControl_iface;
2582 }else if(IsEqualGUID(&IID_IQuickActivate, riid)) {
2583 TRACE("(%p)->(IID_IQuickActivate %p)\n", This, ppv);
2584 *ppv = &This->IQuickActivate_iface;
2585 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
2586 TRACE("(%p)->(IID_IViewObject %p)\n", This, ppv);
2587 *ppv = &This->IViewObjectEx_iface;
2588 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
2589 TRACE("(%p)->(IID_IViewObject2 %p)\n", This, ppv);
2590 *ppv = &This->IViewObjectEx_iface;
2591 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
2592 TRACE("(%p)->(IID_IViewObjectEx %p)\n", This, ppv);
2593 *ppv = &This->IViewObjectEx_iface;
2594 }else if(IsEqualGUID(&IID_IPointerInactive, riid)) {
2595 TRACE("(%p)->(IID_IPointerInactive %p)\n", This, ppv);
2596 *ppv = &This->IPointerInactive_iface;
2597 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
2598 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
2599 *ppv = &This->IConnectionPointContainer_iface;
2600 }else {
2601 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2602 *ppv = NULL;
2603 return E_NOINTERFACE;
2606 IUnknown_AddRef((IUnknown*)*ppv);
2607 return S_OK;
2610 static ULONG WINAPI ScriptControl_AddRef(IScriptControl *iface)
2612 ScriptControl *This = impl_from_IScriptControl(iface);
2613 LONG ref = InterlockedIncrement(&This->ref);
2615 TRACE("(%p) ref=%d\n", This, ref);
2617 return ref;
2620 static ULONG WINAPI ScriptControl_Release(IScriptControl *iface)
2622 ScriptControl *This = impl_from_IScriptControl(iface);
2623 LONG ref = InterlockedDecrement(&This->ref);
2625 TRACE("(%p) ref=%d\n", This, ref);
2627 if(!ref) {
2628 if (This->site)
2629 IOleClientSite_Release(This->site);
2630 if (This->host)
2632 release_modules(This, FALSE);
2633 IActiveScriptSite_Release(&This->host->IActiveScriptSite_iface);
2635 IScriptError_Release(&This->error->IScriptError_iface);
2636 heap_free(This);
2639 return ref;
2642 static HRESULT WINAPI ScriptControl_GetTypeInfoCount(IScriptControl *iface, UINT *pctinfo)
2644 ScriptControl *This = impl_from_IScriptControl(iface);
2645 TRACE("(%p)->(%p)\n", This, pctinfo);
2646 *pctinfo = 1;
2647 return S_OK;
2650 static HRESULT WINAPI ScriptControl_GetTypeInfo(IScriptControl *iface, UINT iTInfo,
2651 LCID lcid, ITypeInfo **ppTInfo)
2653 ScriptControl *This = impl_from_IScriptControl(iface);
2654 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
2655 return get_typeinfo(IScriptControl_tid, ppTInfo);
2658 static HRESULT WINAPI ScriptControl_GetIDsOfNames(IScriptControl *iface, REFIID riid,
2659 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2661 ScriptControl *This = impl_from_IScriptControl(iface);
2662 ITypeInfo *typeinfo;
2663 HRESULT hres;
2665 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
2667 hres = get_typeinfo(IScriptControl_tid, &typeinfo);
2668 if(SUCCEEDED(hres)) {
2669 hres = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
2670 ITypeInfo_Release(typeinfo);
2673 return hres;
2676 static HRESULT WINAPI ScriptControl_Invoke(IScriptControl *iface, DISPID dispIdMember,
2677 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2678 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2680 ScriptControl *This = impl_from_IScriptControl(iface);
2681 ITypeInfo *typeinfo;
2682 HRESULT hres;
2684 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
2685 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2687 hres = get_typeinfo(IScriptControl_tid, &typeinfo);
2688 if(SUCCEEDED(hres)) {
2689 hres = ITypeInfo_Invoke(typeinfo, iface, dispIdMember, wFlags,
2690 pDispParams, pVarResult, pExcepInfo, puArgErr);
2691 ITypeInfo_Release(typeinfo);
2694 return hres;
2697 static HRESULT WINAPI ScriptControl_get_Language(IScriptControl *iface, BSTR *p)
2699 ScriptControl *This = impl_from_IScriptControl(iface);
2700 LPOLESTR progidW;
2701 HRESULT hr;
2703 TRACE("(%p)->(%p)\n", This, p);
2705 if (!p)
2706 return E_POINTER;
2708 *p = NULL;
2710 if (!This->host)
2711 return S_OK;
2713 hr = ProgIDFromCLSID(&This->host->clsid, &progidW);
2714 if (FAILED(hr))
2715 return hr;
2717 *p = SysAllocString(progidW);
2718 CoTaskMemFree(progidW);
2719 return *p ? S_OK : E_OUTOFMEMORY;
2722 static HRESULT WINAPI ScriptControl_put_Language(IScriptControl *iface, BSTR language)
2724 ScriptControl *This = impl_from_IScriptControl(iface);
2725 CLSID clsid;
2726 HRESULT hres;
2728 TRACE("(%p)->(%s)\n", This, debugstr_w(language));
2730 if (language && FAILED(CLSIDFromProgID(language, &clsid)))
2731 return CTL_E_INVALIDPROPERTYVALUE;
2733 if (This->host) {
2734 release_modules(This, TRUE);
2735 IActiveScriptSite_Release(&This->host->IActiveScriptSite_iface);
2736 This->host = NULL;
2739 if (!language)
2740 return S_OK;
2742 hres = init_script_host(This, &clsid, &This->host);
2743 if (FAILED(hres))
2744 return hres;
2746 /* Alloc global module */
2747 This->modules = heap_alloc_zero(sizeof(*This->modules));
2748 if (This->modules) {
2749 This->modules[0] = create_module(This->host, NULL);
2750 if (!This->modules[0]) {
2751 heap_free(This->modules);
2752 This->modules = NULL;
2753 hres = E_OUTOFMEMORY;
2756 else
2757 hres = E_OUTOFMEMORY;
2759 if (FAILED(hres)) {
2760 detach_script_host(This->host);
2761 This->host = NULL;
2763 return hres;
2766 static HRESULT WINAPI ScriptControl_get_State(IScriptControl *iface, ScriptControlStates *p)
2768 ScriptControl *This = impl_from_IScriptControl(iface);
2769 SCRIPTSTATE state;
2770 HRESULT hres;
2772 TRACE("(%p)->(%p)\n", This, p);
2774 if(!p)
2775 return E_POINTER;
2777 if(!This->host)
2778 return E_FAIL;
2780 hres = IActiveScript_GetScriptState(This->host->script, &state);
2781 if (FAILED(hres)) return hres;
2783 switch (state)
2785 case SCRIPTSTATE_INITIALIZED:
2786 case SCRIPTSTATE_STARTED:
2787 *p = Initialized;
2788 break;
2789 case SCRIPTSTATE_CONNECTED:
2790 *p = Connected;
2791 break;
2792 default:
2793 WARN("unexpected state %d\n", state);
2794 return E_FAIL;
2796 return S_OK;
2799 static HRESULT WINAPI ScriptControl_put_State(IScriptControl *iface, ScriptControlStates state)
2801 ScriptControl *This = impl_from_IScriptControl(iface);
2802 TRACE("(%p)->(%x)\n", This, state);
2804 if(!This->host)
2805 return E_FAIL;
2807 if(state != Initialized && state != Connected)
2808 return CTL_E_INVALIDPROPERTYVALUE;
2810 return IActiveScript_SetScriptState(This->host->script, state == Connected ? SCRIPTSTATE_CONNECTED : SCRIPTSTATE_STARTED);
2813 static HRESULT WINAPI ScriptControl_put_SitehWnd(IScriptControl *iface, LONG hwnd)
2815 ScriptControl *This = impl_from_IScriptControl(iface);
2817 TRACE("(%p)->(%x)\n", This, hwnd);
2819 if (hwnd && !IsWindow(LongToHandle(hwnd)))
2820 return CTL_E_INVALIDPROPERTYVALUE;
2822 This->site_hwnd = LongToHandle(hwnd);
2823 if (This->host)
2824 This->host->site_hwnd = This->allow_ui ? This->site_hwnd : ((HWND)-1);
2825 return S_OK;
2828 static HRESULT WINAPI ScriptControl_get_SitehWnd(IScriptControl *iface, LONG *p)
2830 ScriptControl *This = impl_from_IScriptControl(iface);
2832 TRACE("(%p)->(%p)\n", This, p);
2834 if (!p) return E_POINTER;
2836 *p = HandleToLong(This->site_hwnd);
2837 return S_OK;
2840 static HRESULT WINAPI ScriptControl_get_Timeout(IScriptControl *iface, LONG *p)
2842 ScriptControl *This = impl_from_IScriptControl(iface);
2844 TRACE("(%p)->(%p)\n", This, p);
2846 if (!p)
2847 return E_POINTER;
2849 *p = This->timeout;
2850 return S_OK;
2853 static HRESULT WINAPI ScriptControl_put_Timeout(IScriptControl *iface, LONG timeout)
2855 ScriptControl *This = impl_from_IScriptControl(iface);
2857 TRACE("(%p)->(%d)\n", This, timeout);
2859 if (timeout < -1)
2860 return CTL_E_INVALIDPROPERTYVALUE;
2862 if (timeout != -1)
2863 FIXME("execution timeout ignored\n");
2865 This->timeout = timeout;
2866 return S_OK;
2869 static HRESULT WINAPI ScriptControl_get_AllowUI(IScriptControl *iface, VARIANT_BOOL *p)
2871 ScriptControl *This = impl_from_IScriptControl(iface);
2872 TRACE("(%p)->(%p)\n", This, p);
2874 if(!p)
2875 return E_POINTER;
2877 *p = This->allow_ui;
2878 return S_OK;
2881 static HRESULT WINAPI ScriptControl_put_AllowUI(IScriptControl *iface, VARIANT_BOOL allow_ui)
2883 ScriptControl *This = impl_from_IScriptControl(iface);
2884 TRACE("(%p)->(%x)\n", This, allow_ui);
2886 This->allow_ui = allow_ui;
2887 if (This->host)
2888 This->host->site_hwnd = allow_ui ? This->site_hwnd : ((HWND)-1);
2889 return S_OK;
2892 static HRESULT WINAPI ScriptControl_get_UseSafeSubset(IScriptControl *iface, VARIANT_BOOL *p)
2894 ScriptControl *This = impl_from_IScriptControl(iface);
2895 TRACE("(%p)->(%p)\n", This, p);
2897 if(!p)
2898 return E_POINTER;
2900 *p = This->use_safe_subset;
2901 return S_OK;
2904 static HRESULT WINAPI ScriptControl_put_UseSafeSubset(IScriptControl *iface, VARIANT_BOOL use_safe_subset)
2906 ScriptControl *This = impl_from_IScriptControl(iface);
2907 TRACE("(%p)->(%x)\n", This, use_safe_subset);
2909 if (This->host && This->use_safe_subset != use_safe_subset)
2910 set_safety_opts(This->host->script, use_safe_subset);
2912 This->use_safe_subset = use_safe_subset;
2913 return S_OK;
2916 static HRESULT WINAPI ScriptControl_get_Modules(IScriptControl *iface, IScriptModuleCollection **p)
2918 ScriptControl *This = impl_from_IScriptControl(iface);
2920 TRACE("(%p)->(%p)\n", This, p);
2922 if (!This->host) return E_FAIL;
2924 *p = &This->IScriptModuleCollection_iface;
2925 IScriptControl_AddRef(iface);
2926 return S_OK;
2929 static HRESULT WINAPI ScriptControl_get_Error(IScriptControl *iface, IScriptError **p)
2931 ScriptControl *This = impl_from_IScriptControl(iface);
2933 TRACE("(%p)->(%p)\n", This, p);
2935 if (!p) return E_POINTER;
2937 *p = &This->error->IScriptError_iface;
2938 IScriptError_AddRef(*p);
2939 return S_OK;
2942 static HRESULT WINAPI ScriptControl_get_CodeObject(IScriptControl *iface, IDispatch **p)
2944 ScriptControl *This = impl_from_IScriptControl(iface);
2946 TRACE("(%p)->(%p)\n", This, p);
2948 if (!This->host) return E_FAIL;
2950 return IScriptModule_get_CodeObject(&This->modules[0]->IScriptModule_iface, p);
2953 static HRESULT WINAPI ScriptControl_get_Procedures(IScriptControl *iface, IScriptProcedureCollection **p)
2955 ScriptControl *This = impl_from_IScriptControl(iface);
2957 TRACE("(%p)->(%p)\n", This, p);
2959 if (!This->host) return E_FAIL;
2961 return IScriptModule_get_Procedures(&This->modules[0]->IScriptModule_iface, p);
2964 static HRESULT WINAPI ScriptControl__AboutBox(IScriptControl *iface)
2966 ScriptControl *This = impl_from_IScriptControl(iface);
2967 FIXME("(%p)\n", This);
2968 return E_NOTIMPL;
2971 static HRESULT WINAPI ScriptControl_AddObject(IScriptControl *iface, BSTR name, IDispatch *object, VARIANT_BOOL add_members)
2973 ScriptControl *This = impl_from_IScriptControl(iface);
2974 DWORD flags = SCRIPTITEM_ISVISIBLE | SCRIPTITEM_ISSOURCE;
2976 TRACE("(%p)->(%s %p %x)\n", This, debugstr_w(name), object, add_members);
2978 if (!object)
2979 return E_INVALIDARG;
2981 if (!This->host)
2982 return E_FAIL;
2984 if (add_members)
2985 flags |= SCRIPTITEM_GLOBALMEMBERS;
2986 return add_script_object(This->host, name, object, flags);
2989 static HRESULT WINAPI ScriptControl_Reset(IScriptControl *iface)
2991 ScriptControl *This = impl_from_IScriptControl(iface);
2993 TRACE("(%p)\n", This);
2995 if (!This->host)
2996 return E_FAIL;
2998 clear_named_items(This->host);
2999 return set_script_state(This->host, SCRIPTSTATE_INITIALIZED);
3002 static HRESULT WINAPI ScriptControl_AddCode(IScriptControl *iface, BSTR code)
3004 ScriptControl *This = impl_from_IScriptControl(iface);
3006 TRACE("(%p)->(%s).\n", This, debugstr_w(code));
3008 if (!This->host)
3009 return E_FAIL;
3011 return parse_script_text(This->modules[0], code, SCRIPTTEXT_ISVISIBLE, NULL);
3014 static HRESULT WINAPI ScriptControl_Eval(IScriptControl *iface, BSTR expression, VARIANT *res)
3016 ScriptControl *This = impl_from_IScriptControl(iface);
3018 TRACE("(%p)->(%s, %p).\n", This, debugstr_w(expression), res);
3020 if (!res)
3021 return E_POINTER;
3022 V_VT(res) = VT_EMPTY;
3023 if (!This->host)
3024 return E_FAIL;
3026 return parse_script_text(This->modules[0], expression, SCRIPTTEXT_ISEXPRESSION, res);
3029 static HRESULT WINAPI ScriptControl_ExecuteStatement(IScriptControl *iface, BSTR statement)
3031 ScriptControl *This = impl_from_IScriptControl(iface);
3033 TRACE("(%p)->(%s)\n", This, debugstr_w(statement));
3035 if (!This->host)
3036 return E_FAIL;
3038 return parse_script_text(This->modules[0], statement, 0, NULL);
3041 static HRESULT WINAPI ScriptControl_Run(IScriptControl *iface, BSTR procedure_name, SAFEARRAY **parameters, VARIANT *res)
3043 ScriptControl *This = impl_from_IScriptControl(iface);
3044 SAFEARRAY *sa;
3046 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(procedure_name), parameters, res);
3048 if (!parameters || !res) return E_POINTER;
3049 if (!(sa = *parameters)) return E_POINTER;
3051 V_VT(res) = VT_EMPTY;
3052 if (sa->cDims == 0) return DISP_E_BADINDEX;
3053 if (!(sa->fFeatures & FADF_VARIANT)) return DISP_E_BADVARTYPE;
3054 if (!This->host) return E_FAIL;
3056 return run_procedure(This->modules[0], procedure_name, sa, res);
3059 static const IScriptControlVtbl ScriptControlVtbl = {
3060 ScriptControl_QueryInterface,
3061 ScriptControl_AddRef,
3062 ScriptControl_Release,
3063 ScriptControl_GetTypeInfoCount,
3064 ScriptControl_GetTypeInfo,
3065 ScriptControl_GetIDsOfNames,
3066 ScriptControl_Invoke,
3067 ScriptControl_get_Language,
3068 ScriptControl_put_Language,
3069 ScriptControl_get_State,
3070 ScriptControl_put_State,
3071 ScriptControl_put_SitehWnd,
3072 ScriptControl_get_SitehWnd,
3073 ScriptControl_get_Timeout,
3074 ScriptControl_put_Timeout,
3075 ScriptControl_get_AllowUI,
3076 ScriptControl_put_AllowUI,
3077 ScriptControl_get_UseSafeSubset,
3078 ScriptControl_put_UseSafeSubset,
3079 ScriptControl_get_Modules,
3080 ScriptControl_get_Error,
3081 ScriptControl_get_CodeObject,
3082 ScriptControl_get_Procedures,
3083 ScriptControl__AboutBox,
3084 ScriptControl_AddObject,
3085 ScriptControl_Reset,
3086 ScriptControl_AddCode,
3087 ScriptControl_Eval,
3088 ScriptControl_ExecuteStatement,
3089 ScriptControl_Run
3092 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **obj)
3094 ScriptControl *This = impl_from_IOleObject(iface);
3095 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3098 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
3100 ScriptControl *This = impl_from_IOleObject(iface);
3101 return IScriptControl_AddRef(&This->IScriptControl_iface);
3104 static ULONG WINAPI OleObject_Release(IOleObject *iface)
3106 ScriptControl *This = impl_from_IOleObject(iface);
3107 return IScriptControl_Release(&This->IScriptControl_iface);
3110 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, IOleClientSite *site)
3112 ScriptControl *This = impl_from_IOleObject(iface);
3114 TRACE("(%p)->(%p)\n", This, site);
3116 if (This->site)
3117 IOleClientSite_Release(This->site);
3119 if ((This->site = site))
3120 IOleClientSite_AddRef(site);
3122 return S_OK;
3125 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, IOleClientSite **site)
3127 ScriptControl *This = impl_from_IOleObject(iface);
3129 TRACE("(%p)->(%p)\n", This, site);
3131 if (!site)
3132 return E_POINTER;
3134 if ((*site = This->site))
3135 IOleClientSite_AddRef(*site);
3137 return S_OK;
3140 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR containerapp, LPCOLESTR containerobj)
3142 ScriptControl *This = impl_from_IOleObject(iface);
3144 FIXME("(%p)->(%s %s)\n", This, debugstr_w(containerapp), debugstr_w(containerobj));
3146 return E_NOTIMPL;
3149 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD save)
3151 ScriptControl *This = impl_from_IOleObject(iface);
3153 FIXME("(%p)->(%d)\n", This, save);
3155 return E_NOTIMPL;
3158 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD which, IMoniker *moniker)
3160 ScriptControl *This = impl_from_IOleObject(iface);
3162 FIXME("(%p)->(%d %p)\n", This, which, moniker);
3164 return E_NOTIMPL;
3167 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD assign, DWORD which, IMoniker **moniker)
3169 ScriptControl *This = impl_from_IOleObject(iface);
3171 FIXME("(%p)->(%d %d %p)\n", This, assign, which, moniker);
3173 return E_NOTIMPL;
3176 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, IDataObject *dataobj, BOOL creation,
3177 DWORD reserved)
3179 ScriptControl *This = impl_from_IOleObject(iface);
3181 FIXME("(%p)->(%p %d %d)\n", This, dataobj, creation, reserved);
3183 return E_NOTIMPL;
3186 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD reserved, IDataObject **dataobj)
3188 ScriptControl *This = impl_from_IOleObject(iface);
3190 FIXME("(%p)->(%d %p)\n", This, reserved, dataobj);
3192 return E_NOTIMPL;
3195 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG verb, LPMSG msg, IOleClientSite *active_site,
3196 LONG index, HWND hwndParent, LPCRECT rect)
3198 ScriptControl *This = impl_from_IOleObject(iface);
3200 FIXME("(%p)->(%d %p %p %d %p %p)\n", This, verb, msg, active_site, index, hwndParent, rect);
3202 return E_NOTIMPL;
3205 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **enumoleverb)
3207 ScriptControl *This = impl_from_IOleObject(iface);
3209 FIXME("(%p)->(%p)\n", This, enumoleverb);
3211 return E_NOTIMPL;
3214 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
3216 ScriptControl *This = impl_from_IOleObject(iface);
3218 FIXME("(%p)\n", This);
3220 return E_NOTIMPL;
3223 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
3225 ScriptControl *This = impl_from_IOleObject(iface);
3227 FIXME("(%p)\n", This);
3229 return E_NOTIMPL;
3232 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *clsid)
3234 ScriptControl *This = impl_from_IOleObject(iface);
3236 FIXME("(%p)->(%p)\n", This, clsid);
3238 return E_NOTIMPL;
3241 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD form_of_type, LPOLESTR *usertype)
3243 ScriptControl *This = impl_from_IOleObject(iface);
3245 FIXME("(%p)->(%d %p)\n", This, form_of_type, usertype);
3247 return E_NOTIMPL;
3250 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
3252 ScriptControl *This = impl_from_IOleObject(iface);
3254 FIXME("(%p)->(%d %p)\n", This, aspect, size);
3256 return E_NOTIMPL;
3259 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD aspect, SIZEL *size)
3261 ScriptControl *This = impl_from_IOleObject(iface);
3263 TRACE("(%p)->(%d %p)\n", This, aspect, size);
3265 if (aspect != DVASPECT_CONTENT)
3266 return DV_E_DVASPECT;
3268 *size = This->extent;
3269 return S_OK;
3272 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *sink, DWORD *connection)
3274 ScriptControl *This = impl_from_IOleObject(iface);
3276 FIXME("(%p)->(%p %p)\n", This, sink, connection);
3278 return E_NOTIMPL;
3281 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD connection)
3283 ScriptControl *This = impl_from_IOleObject(iface);
3285 FIXME("(%p)->(%d)\n", This, connection);
3287 return E_NOTIMPL;
3290 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **enumadvise)
3292 ScriptControl *This = impl_from_IOleObject(iface);
3294 FIXME("(%p)->(%p)\n", This, enumadvise);
3296 return E_NOTIMPL;
3299 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD aspect, DWORD *status)
3301 ScriptControl *This = impl_from_IOleObject(iface);
3303 TRACE("(%p)->(%d %p)\n", This, aspect, status);
3305 return OleRegGetMiscStatus(&CLSID_ScriptControl, aspect, status);
3308 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *logpal)
3310 ScriptControl *This = impl_from_IOleObject(iface);
3312 FIXME("(%p)->(%p)\n", This, logpal);
3314 return E_NOTIMPL;
3317 static const IOleObjectVtbl OleObjectVtbl = {
3318 OleObject_QueryInterface,
3319 OleObject_AddRef,
3320 OleObject_Release,
3321 OleObject_SetClientSite,
3322 OleObject_GetClientSite,
3323 OleObject_SetHostNames,
3324 OleObject_Close,
3325 OleObject_SetMoniker,
3326 OleObject_GetMoniker,
3327 OleObject_InitFromData,
3328 OleObject_GetClipboardData,
3329 OleObject_DoVerb,
3330 OleObject_EnumVerbs,
3331 OleObject_Update,
3332 OleObject_IsUpToDate,
3333 OleObject_GetUserClassID,
3334 OleObject_GetUserType,
3335 OleObject_SetExtent,
3336 OleObject_GetExtent,
3337 OleObject_Advise,
3338 OleObject_Unadvise,
3339 OleObject_EnumAdvise,
3340 OleObject_GetMiscStatus,
3341 OleObject_SetColorScheme
3344 static HRESULT WINAPI PersistStreamInit_QueryInterface(IPersistStreamInit *iface, REFIID riid, void **obj)
3346 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3347 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3350 static ULONG WINAPI PersistStreamInit_AddRef(IPersistStreamInit *iface)
3352 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3353 return IScriptControl_AddRef(&This->IScriptControl_iface);
3356 static ULONG WINAPI PersistStreamInit_Release(IPersistStreamInit *iface)
3358 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3359 return IScriptControl_Release(&This->IScriptControl_iface);
3362 static HRESULT WINAPI PersistStreamInit_GetClassID(IPersistStreamInit *iface, CLSID *clsid)
3364 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3366 FIXME("(%p)->(%p)\n", This, clsid);
3368 return E_NOTIMPL;
3371 static HRESULT WINAPI PersistStreamInit_IsDirty(IPersistStreamInit *iface)
3373 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3375 FIXME("(%p)\n", This);
3377 return E_NOTIMPL;
3380 static HRESULT WINAPI PersistStreamInit_Load(IPersistStreamInit *iface, IStream *stream)
3382 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3384 FIXME("(%p)->(%p)\n", This, stream);
3386 return E_NOTIMPL;
3389 static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, IStream *stream, BOOL clear_dirty)
3391 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3393 FIXME("(%p)->(%p %d)\n", This, stream, clear_dirty);
3395 return E_NOTIMPL;
3398 static HRESULT WINAPI PersistStreamInit_GetSizeMax(IPersistStreamInit *iface, ULARGE_INTEGER *size)
3400 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3402 FIXME("(%p)->(%p)\n", This, size);
3404 return E_NOTIMPL;
3407 static HRESULT WINAPI PersistStreamInit_InitNew(IPersistStreamInit *iface)
3409 ScriptControl *This = impl_from_IPersistStreamInit(iface);
3411 FIXME("(%p)\n", This);
3413 return S_OK;
3416 static const IPersistStreamInitVtbl PersistStreamInitVtbl = {
3417 PersistStreamInit_QueryInterface,
3418 PersistStreamInit_AddRef,
3419 PersistStreamInit_Release,
3420 PersistStreamInit_GetClassID,
3421 PersistStreamInit_IsDirty,
3422 PersistStreamInit_Load,
3423 PersistStreamInit_Save,
3424 PersistStreamInit_GetSizeMax,
3425 PersistStreamInit_InitNew
3428 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface, REFIID riid, void **obj)
3430 ScriptControl *This = impl_from_IOleControl(iface);
3431 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3434 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
3436 ScriptControl *This = impl_from_IOleControl(iface);
3437 return IScriptControl_AddRef(&This->IScriptControl_iface);
3440 static ULONG WINAPI OleControl_Release(IOleControl *iface)
3442 ScriptControl *This = impl_from_IOleControl(iface);
3443 return IScriptControl_Release(&This->IScriptControl_iface);
3446 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, CONTROLINFO *info)
3448 ScriptControl *This = impl_from_IOleControl(iface);
3450 TRACE("(%p)->(%p)\n", This, info);
3452 if (!info)
3453 return E_POINTER;
3455 info->hAccel = NULL;
3456 info->cAccel = 0;
3458 return S_OK;
3461 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, MSG *msg)
3463 ScriptControl *This = impl_from_IOleControl(iface);
3465 FIXME("(%p)->(%p)\n", This, msg);
3467 return E_NOTIMPL;
3470 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispid)
3472 ScriptControl *This = impl_from_IOleControl(iface);
3474 FIXME("(%p)->(%#x)\n", This, dispid);
3476 return E_NOTIMPL;
3479 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL freeze)
3481 ScriptControl *This = impl_from_IOleControl(iface);
3483 FIXME("(%p)->(%d)\n", This, freeze);
3485 return E_NOTIMPL;
3488 static const IOleControlVtbl OleControlVtbl = {
3489 OleControl_QueryInterface,
3490 OleControl_AddRef,
3491 OleControl_Release,
3492 OleControl_GetControlInfo,
3493 OleControl_OnMnemonic,
3494 OleControl_OnAmbientPropertyChange,
3495 OleControl_FreezeEvents
3498 static HRESULT WINAPI QuickActivate_QueryInterface(IQuickActivate *iface, REFIID riid, void **obj)
3500 ScriptControl *This = impl_from_IQuickActivate(iface);
3501 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3504 static ULONG WINAPI QuickActivate_AddRef(IQuickActivate *iface)
3506 ScriptControl *This = impl_from_IQuickActivate(iface);
3507 return IScriptControl_AddRef(&This->IScriptControl_iface);
3510 static ULONG WINAPI QuickActivate_Release(IQuickActivate *iface)
3512 ScriptControl *This = impl_from_IQuickActivate(iface);
3513 return IScriptControl_Release(&This->IScriptControl_iface);
3516 static HRESULT WINAPI QuickActivate_QuickActivate(IQuickActivate *iface, QACONTAINER *container, QACONTROL *control)
3518 ScriptControl *This = impl_from_IQuickActivate(iface);
3520 FIXME("(%p)->(%p %p)\n", This, container, control);
3522 return E_NOTIMPL;
3525 static HRESULT WINAPI QuickActivate_SetContentExtent(IQuickActivate *iface, SIZEL *size)
3527 ScriptControl *This = impl_from_IQuickActivate(iface);
3529 FIXME("(%p)->(%p)\n", This, size);
3531 return E_NOTIMPL;
3534 static HRESULT WINAPI QuickActivate_GetContentExtent(IQuickActivate *iface, SIZEL *size)
3536 ScriptControl *This = impl_from_IQuickActivate(iface);
3538 FIXME("(%p)->(%p)\n", This, size);
3540 return E_NOTIMPL;
3543 static const IQuickActivateVtbl QuickActivateVtbl = {
3544 QuickActivate_QueryInterface,
3545 QuickActivate_AddRef,
3546 QuickActivate_Release,
3547 QuickActivate_QuickActivate,
3548 QuickActivate_SetContentExtent,
3549 QuickActivate_GetContentExtent
3552 static HRESULT WINAPI ViewObject_QueryInterface(IViewObjectEx *iface, REFIID riid, void **obj)
3554 ScriptControl *This = impl_from_IViewObjectEx(iface);
3555 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3558 static ULONG WINAPI ViewObject_AddRef(IViewObjectEx *iface)
3560 ScriptControl *This = impl_from_IViewObjectEx(iface);
3561 return IScriptControl_AddRef(&This->IScriptControl_iface);
3564 static ULONG WINAPI ViewObject_Release(IViewObjectEx *iface)
3566 ScriptControl *This = impl_from_IViewObjectEx(iface);
3567 return IScriptControl_Release(&This->IScriptControl_iface);
3570 static HRESULT WINAPI ViewObject_Draw(IViewObjectEx *iface, DWORD drawaspect, LONG index, void *aspect,
3571 DVTARGETDEVICE *device, HDC target_dev, HDC hdc_draw, const RECTL *bounds, const RECTL *win_bounds,
3572 BOOL (STDMETHODCALLTYPE *fn_continue)(ULONG_PTR cont), ULONG_PTR cont)
3574 ScriptControl *This = impl_from_IViewObjectEx(iface);
3576 FIXME("(%p)->(%d %d %p %p %p %p %p %p %p %lu)\n", This, drawaspect, index, aspect, device, target_dev,
3577 hdc_draw, bounds, win_bounds, fn_continue, cont);
3579 return E_NOTIMPL;
3582 static HRESULT WINAPI ViewObject_GetColorSet(IViewObjectEx *iface, DWORD drawaspect, LONG index, void *aspect,
3583 DVTARGETDEVICE *device, HDC hic_target, LOGPALETTE **colorset)
3585 ScriptControl *This = impl_from_IViewObjectEx(iface);
3587 FIXME("(%p)->(%d %d %p %p %p %p)\n", This, drawaspect, index, aspect, device, hic_target,
3588 colorset);
3590 return E_NOTIMPL;
3593 static HRESULT WINAPI ViewObject_Freeze(IViewObjectEx *iface, DWORD drawaspect, LONG index, void *aspect,
3594 DWORD *freeze)
3596 ScriptControl *This = impl_from_IViewObjectEx(iface);
3598 FIXME("(%p)->(%d %d %p %p)\n", This, drawaspect, index, aspect, freeze);
3600 return E_NOTIMPL;
3603 static HRESULT WINAPI ViewObject_Unfreeze(IViewObjectEx *iface, DWORD freeze)
3605 ScriptControl *This = impl_from_IViewObjectEx(iface);
3607 FIXME("(%p)->(%d)\n", This, freeze);
3609 return E_NOTIMPL;
3612 static HRESULT WINAPI ViewObject_SetAdvise(IViewObjectEx *iface, DWORD aspects, DWORD flags, IAdviseSink *sink)
3614 ScriptControl *This = impl_from_IViewObjectEx(iface);
3616 TRACE("(%p)->(%d %#x %p)\n", This, aspects, flags, sink);
3618 if (aspects != DVASPECT_CONTENT)
3619 return DV_E_DVASPECT;
3621 This->view_sink_flags = flags;
3622 if (This->view_sink)
3623 IAdviseSink_Release(This->view_sink);
3624 This->view_sink = sink;
3625 if (This->view_sink)
3626 IAdviseSink_AddRef(This->view_sink);
3628 return S_OK;
3631 static HRESULT WINAPI ViewObject_GetAdvise(IViewObjectEx *iface, DWORD *aspects, DWORD *flags, IAdviseSink **sink)
3633 ScriptControl *This = impl_from_IViewObjectEx(iface);
3635 TRACE("(%p)->(%p %p %p)\n", This, aspects, flags, sink);
3637 if (aspects)
3638 *aspects = DVASPECT_CONTENT;
3639 if (flags)
3640 *flags = This->view_sink_flags;
3641 if (sink) {
3642 *sink = This->view_sink;
3643 if (*sink)
3644 IAdviseSink_AddRef(*sink);
3647 return S_OK;
3650 static HRESULT WINAPI ViewObject_GetExtent(IViewObjectEx *iface, DWORD draw_aspect, LONG index,
3651 DVTARGETDEVICE *device, SIZEL *size)
3653 ScriptControl *This = impl_from_IViewObjectEx(iface);
3655 FIXME("(%p)->(%d %d %p %p)\n", This, draw_aspect, index, device, size);
3657 return E_NOTIMPL;
3660 static HRESULT WINAPI ViewObject_GetRect(IViewObjectEx *iface, DWORD aspect, RECTL *rect)
3662 ScriptControl *This = impl_from_IViewObjectEx(iface);
3664 FIXME("(%p)->(%d %p)\n", This, aspect, rect);
3666 return E_NOTIMPL;
3669 static HRESULT WINAPI ViewObject_GetViewStatus(IViewObjectEx *iface, DWORD *status)
3671 ScriptControl *This = impl_from_IViewObjectEx(iface);
3673 TRACE("(%p)->(%p)\n", This, status);
3675 *status = VIEWSTATUS_OPAQUE;
3676 return S_OK;
3679 static HRESULT WINAPI ViewObject_QueryHitPoint(IViewObjectEx *iface, DWORD aspect, const RECT *bounds,
3680 POINT pt, LONG close_hint, DWORD *hit_result)
3682 ScriptControl *This = impl_from_IViewObjectEx(iface);
3684 FIXME("(%p)->(%d %s %s %d %p)\n", This, aspect, wine_dbgstr_rect(bounds), wine_dbgstr_point(&pt), close_hint, hit_result);
3686 return E_NOTIMPL;
3689 static HRESULT WINAPI ViewObject_QueryHitRect(IViewObjectEx *iface, DWORD aspect, const RECT *bounds,
3690 const RECT *loc, LONG close_hint, DWORD *hit_result)
3692 ScriptControl *This = impl_from_IViewObjectEx(iface);
3694 FIXME("(%p)->(%d %s %s %d %p)\n", This, aspect, wine_dbgstr_rect(bounds), wine_dbgstr_rect(loc), close_hint, hit_result);
3696 return E_NOTIMPL;
3699 static HRESULT WINAPI ViewObject_GetNaturalExtent(IViewObjectEx *iface, DWORD aspect, LONG index,
3700 DVTARGETDEVICE *device, HDC target_hdc, DVEXTENTINFO *extent_info, SIZEL *size)
3702 ScriptControl *This = impl_from_IViewObjectEx(iface);
3704 FIXME("(%p)->(%d %d %p %p %p %p)\n", This, aspect, index, device, target_hdc, extent_info, size);
3706 return E_NOTIMPL;
3709 static const IViewObjectExVtbl ViewObjectExVtbl = {
3710 ViewObject_QueryInterface,
3711 ViewObject_AddRef,
3712 ViewObject_Release,
3713 ViewObject_Draw,
3714 ViewObject_GetColorSet,
3715 ViewObject_Freeze,
3716 ViewObject_Unfreeze,
3717 ViewObject_SetAdvise,
3718 ViewObject_GetAdvise,
3719 ViewObject_GetExtent,
3720 ViewObject_GetRect,
3721 ViewObject_GetViewStatus,
3722 ViewObject_QueryHitPoint,
3723 ViewObject_QueryHitRect,
3724 ViewObject_GetNaturalExtent
3727 static HRESULT WINAPI PointerInactive_QueryInterface(IPointerInactive *iface, REFIID riid, void **obj)
3729 ScriptControl *This = impl_from_IPointerInactive(iface);
3730 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3733 static ULONG WINAPI PointerInactive_AddRef(IPointerInactive *iface)
3735 ScriptControl *This = impl_from_IPointerInactive(iface);
3736 return IScriptControl_AddRef(&This->IScriptControl_iface);
3739 static ULONG WINAPI PointerInactive_Release(IPointerInactive *iface)
3741 ScriptControl *This = impl_from_IPointerInactive(iface);
3742 return IScriptControl_Release(&This->IScriptControl_iface);
3745 static HRESULT WINAPI PointerInactive_GetActivationPolicy(IPointerInactive *iface, DWORD *policy)
3747 ScriptControl *This = impl_from_IPointerInactive(iface);
3749 TRACE("(%p)->(%p)\n", This, policy);
3751 if (!policy)
3752 return E_POINTER;
3754 *policy = 0;
3755 return S_OK;
3758 static HRESULT WINAPI PointerInactive_OnInactiveMouseMove(IPointerInactive *iface, const RECT *bounds,
3759 LONG x, LONG y, DWORD key_state)
3761 ScriptControl *This = impl_from_IPointerInactive(iface);
3763 FIXME("(%p)->(%s %d %d %#x)\n", This, wine_dbgstr_rect(bounds), x, y, key_state);
3765 return E_NOTIMPL;
3768 static HRESULT WINAPI PointerInactive_OnInactiveSetCursor(IPointerInactive *iface, const RECT *bounds,
3769 LONG x, LONG y, DWORD msg, BOOL set_always)
3771 ScriptControl *This = impl_from_IPointerInactive(iface);
3773 FIXME("(%p)->(%s %d %d %#x %d)\n", This, wine_dbgstr_rect(bounds), x, y, msg, set_always);
3775 return E_NOTIMPL;
3778 static const IPointerInactiveVtbl PointerInactiveVtbl = {
3779 PointerInactive_QueryInterface,
3780 PointerInactive_AddRef,
3781 PointerInactive_Release,
3782 PointerInactive_GetActivationPolicy,
3783 PointerInactive_OnInactiveMouseMove,
3784 PointerInactive_OnInactiveSetCursor
3787 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface, REFIID riid, void **obj)
3789 ScriptControl *This = impl_from_IConnectionPointContainer(iface);
3790 return IScriptControl_QueryInterface(&This->IScriptControl_iface, riid, obj);
3793 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
3795 ScriptControl *This = impl_from_IConnectionPointContainer(iface);
3796 return IScriptControl_AddRef(&This->IScriptControl_iface);
3799 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
3801 ScriptControl *This = impl_from_IConnectionPointContainer(iface);
3802 return IScriptControl_Release(&This->IScriptControl_iface);
3805 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface, IEnumConnectionPoints **enum_points)
3807 ScriptControl *This = impl_from_IConnectionPointContainer(iface);
3809 FIXME("(%p)->(%p)\n", This, enum_points);
3811 return E_NOTIMPL;
3814 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface, REFIID riid, IConnectionPoint **cp)
3816 ScriptControl *This = impl_from_IConnectionPointContainer(iface);
3817 ConnectionPoint *iter;
3819 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), cp);
3821 *cp = NULL;
3823 for (iter = This->cp_list; iter; iter = iter->next) {
3824 if (IsEqualIID(iter->riid, riid))
3825 *cp = &iter->IConnectionPoint_iface;
3828 if (*cp) {
3829 IConnectionPoint_AddRef(*cp);
3830 return S_OK;
3833 FIXME("unsupported connection point %s\n", debugstr_guid(riid));
3834 return CONNECT_E_NOCONNECTION;
3837 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl = {
3838 ConnectionPointContainer_QueryInterface,
3839 ConnectionPointContainer_AddRef,
3840 ConnectionPointContainer_Release,
3841 ConnectionPointContainer_EnumConnectionPoints,
3842 ConnectionPointContainer_FindConnectionPoint
3845 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface,
3846 REFIID riid, void **ppv)
3848 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3850 if(IsEqualGUID(&IID_IUnknown, riid)) {
3851 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
3852 *ppv = &This->IConnectionPoint_iface;
3853 }else if(IsEqualGUID(&IID_IConnectionPoint, riid)) {
3854 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
3855 *ppv = &This->IConnectionPoint_iface;
3856 }else {
3857 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
3858 *ppv = NULL;
3859 return E_NOINTERFACE;
3862 IUnknown_AddRef((IUnknown*)*ppv);
3863 return S_OK;
3866 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
3868 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3869 return IConnectionPointContainer_AddRef(&This->control->IConnectionPointContainer_iface);
3872 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
3874 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3875 return IConnectionPointContainer_Release(&This->control->IConnectionPointContainer_iface);
3878 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *iid)
3880 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3882 TRACE("(%p)->(%p)\n", This, iid);
3884 *iid = *This->riid;
3885 return S_OK;
3888 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
3889 IConnectionPointContainer **container)
3891 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3893 TRACE("(%p)->(%p)\n", This, container);
3895 if (!container)
3896 return E_POINTER;
3898 *container = &This->control->IConnectionPointContainer_iface;
3899 IConnectionPointContainer_AddRef(*container);
3901 return S_OK;
3904 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *unk_sink,
3905 DWORD *cookie)
3907 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3909 FIXME("(%p)->(%p %p)\n", This, unk_sink, cookie);
3911 return E_NOTIMPL;
3914 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD cookie)
3916 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3918 FIXME("(%p)->(%d)\n", This, cookie);
3920 return E_NOTIMPL;
3923 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface,
3924 IEnumConnections **ppEnum)
3926 ConnectionPoint *This = impl_from_IConnectionPoint(iface);
3928 FIXME("(%p)->(%p): stub\n", This, ppEnum);
3930 return E_NOTIMPL;
3933 static const IConnectionPointVtbl ConnectionPointVtbl =
3935 ConnectionPoint_QueryInterface,
3936 ConnectionPoint_AddRef,
3937 ConnectionPoint_Release,
3938 ConnectionPoint_GetConnectionInterface,
3939 ConnectionPoint_GetConnectionPointContainer,
3940 ConnectionPoint_Advise,
3941 ConnectionPoint_Unadvise,
3942 ConnectionPoint_EnumConnections
3945 static void ConnectionPoint_Init(ConnectionPoint *cp, ScriptControl *sc, REFIID riid)
3947 cp->IConnectionPoint_iface.lpVtbl = &ConnectionPointVtbl;
3948 cp->control = sc;
3949 cp->riid = riid;
3951 cp->next = sc->cp_list;
3952 sc->cp_list = cp;
3955 static HRESULT WINAPI ScriptControl_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
3957 ScriptControl *script_control;
3958 DWORD dpi_x, dpi_y;
3959 HRESULT hres;
3960 HDC hdc;
3962 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
3964 script_control = heap_alloc_zero(sizeof(*script_control));
3965 if(!script_control)
3966 return E_OUTOFMEMORY;
3968 script_control->error = heap_alloc_zero(sizeof(*script_control->error));
3969 if(!script_control->error)
3971 heap_free(script_control);
3972 return E_OUTOFMEMORY;
3975 script_control->IScriptControl_iface.lpVtbl = &ScriptControlVtbl;
3976 script_control->IPersistStreamInit_iface.lpVtbl = &PersistStreamInitVtbl;
3977 script_control->IOleObject_iface.lpVtbl = &OleObjectVtbl;
3978 script_control->IOleControl_iface.lpVtbl = &OleControlVtbl;
3979 script_control->IQuickActivate_iface.lpVtbl = &QuickActivateVtbl;
3980 script_control->IViewObjectEx_iface.lpVtbl = &ViewObjectExVtbl;
3981 script_control->IPointerInactive_iface.lpVtbl = &PointerInactiveVtbl;
3982 script_control->IConnectionPointContainer_iface.lpVtbl = &ConnectionPointContainerVtbl;
3983 script_control->IScriptModuleCollection_iface.lpVtbl = &ScriptModuleCollectionVtbl;
3984 script_control->ref = 1;
3985 script_control->timeout = 10000;
3986 script_control->allow_ui = VARIANT_TRUE;
3987 script_control->use_safe_subset = VARIANT_FALSE;
3989 script_control->error->IScriptError_iface.lpVtbl = &ScriptErrorVtbl;
3990 script_control->error->ref = 1;
3992 ConnectionPoint_Init(&script_control->cp_scsource, script_control, &DIID_DScriptControlSource);
3993 ConnectionPoint_Init(&script_control->cp_propnotif, script_control, &IID_IPropertyNotifySink);
3995 hdc = GetDC(0);
3996 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
3997 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
3998 ReleaseDC(0, hdc);
4000 script_control->extent.cx = MulDiv(38, 2540, dpi_x);
4001 script_control->extent.cy = MulDiv(38, 2540, dpi_y);
4003 hres = IScriptControl_QueryInterface(&script_control->IScriptControl_iface, riid, ppv);
4004 IScriptControl_Release(&script_control->IScriptControl_iface);
4005 return hres;
4008 /******************************************************************
4009 * DllMain (msscript.ocx.@)
4011 BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
4013 TRACE("(%p %d %p)\n", instance, reason, reserved);
4015 switch(reason) {
4016 case DLL_PROCESS_ATTACH:
4017 msscript_instance = instance;
4018 DisableThreadLibraryCalls(instance);
4019 break;
4020 case DLL_PROCESS_DETACH:
4021 if(!reserved)
4022 release_typelib();
4023 break;
4026 return TRUE;
4029 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
4031 *ppv = NULL;
4033 if(IsEqualGUID(&IID_IUnknown, riid)) {
4034 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
4035 *ppv = iface;
4036 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
4037 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
4038 *ppv = iface;
4041 if(*ppv) {
4042 IUnknown_AddRef((IUnknown*)*ppv);
4043 return S_OK;
4046 WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
4047 return E_NOINTERFACE;
4050 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
4052 TRACE("(%p)\n", iface);
4053 return 2;
4056 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
4058 TRACE("(%p)\n", iface);
4059 return 1;
4062 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
4064 TRACE("(%p)->(%x)\n", iface, fLock);
4065 return S_OK;
4068 static const IClassFactoryVtbl ScriptControlFactoryVtbl = {
4069 ClassFactory_QueryInterface,
4070 ClassFactory_AddRef,
4071 ClassFactory_Release,
4072 ScriptControl_CreateInstance,
4073 ClassFactory_LockServer
4076 static IClassFactory ScriptControlFactory = { &ScriptControlFactoryVtbl };
4078 /***********************************************************************
4079 * DllGetClassObject (msscript.ocx.@)
4081 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
4083 if(IsEqualGUID(&CLSID_ScriptControl, rclsid)) {
4084 TRACE("(CLSID_ScriptControl %s %p)\n", debugstr_guid(riid), ppv);
4085 return IClassFactory_QueryInterface(&ScriptControlFactory, riid, ppv);
4088 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
4089 return CLASS_E_CLASSNOTAVAILABLE;
4092 /***********************************************************************
4093 * DllCanUnloadNow (msscript.ocx.@)
4095 HRESULT WINAPI DllCanUnloadNow(void)
4097 TRACE("\n");
4098 return S_FALSE;
4101 /***********************************************************************
4102 * DllRegisterServer (msscript.ocx.@)
4104 HRESULT WINAPI DllRegisterServer(void)
4106 TRACE("()\n");
4107 return __wine_register_resources(msscript_instance);
4110 /***********************************************************************
4111 * DllUnregisterServer (msscript.ocx.@)
4113 HRESULT WINAPI DllUnregisterServer(void)
4115 TRACE("()\n");
4116 return __wine_unregister_resources(msscript_instance);