2 * Copyright 2008-2009 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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
43 struct dispex_data_t {
46 func_info_t **name_table;
58 #define DYNPROP_DELETED 0x01
62 IUnknown IUnknown_iface;
67 struct dispex_dynamic_data_t {
70 dynamic_prop_t *props;
71 func_disp_t **func_disps;
74 #define DISPID_DYNPROP_0 0x50000000
75 #define DISPID_DYNPROP_MAX 0x5fffffff
77 #define FDEX_VERSION_MASK 0xf0000000
79 static ITypeLib *typelib;
80 static ITypeInfo *typeinfos[LAST_tid];
81 static struct list dispex_data_list = LIST_INIT(dispex_data_list);
83 static REFIID tid_ids[] = {
84 #define XIID(iface) &IID_ ## iface,
85 #define XDIID(iface) &DIID_ ## iface,
91 static HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
98 hres = LoadRegTypeLib(&LIBID_MSHTML, 4, 0, LOCALE_SYSTEM_DEFAULT, &tl);
100 ERR("LoadRegTypeLib failed: %08x\n", hres);
104 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
105 ITypeLib_Release(tl);
108 if(!typeinfos[tid]) {
111 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &typeinfo);
113 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
117 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), typeinfo, NULL))
118 ITypeInfo_Release(typeinfo);
121 *typeinfo = typeinfos[tid];
125 void release_typelib(void)
130 while(!list_empty(&dispex_data_list)) {
131 iter = LIST_ENTRY(list_head(&dispex_data_list), dispex_data_t, entry);
132 list_remove(&iter->entry);
134 for(i=0; i < iter->func_cnt; i++)
135 SysFreeString(iter->funcs[i].name);
137 heap_free(iter->funcs);
138 heap_free(iter->name_table);
145 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
147 ITypeInfo_Release(typeinfos[i]);
149 ITypeLib_Release(typelib);
152 static void add_func_info(dispex_data_t *data, DWORD *size, tid_t tid, const FUNCDESC *desc, ITypeInfo *dti)
156 if(data->func_cnt && data->funcs[data->func_cnt-1].id == desc->memid)
159 if(data->func_cnt == *size)
160 data->funcs = heap_realloc(data->funcs, (*size <<= 1)*sizeof(func_info_t));
162 hres = ITypeInfo_GetDocumentation(dti, desc->memid, &data->funcs[data->func_cnt].name, NULL, NULL, NULL);
166 data->funcs[data->func_cnt].id = desc->memid;
167 data->funcs[data->func_cnt].tid = tid;
168 data->funcs[data->func_cnt].func_disp_idx = (desc->invkind & DISPATCH_METHOD) ? data->func_disp_cnt++ : -1;
173 static int dispid_cmp(const void *p1, const void *p2)
175 return ((const func_info_t*)p1)->id - ((const func_info_t*)p2)->id;
178 static int func_name_cmp(const void *p1, const void *p2)
180 return strcmpiW((*(func_info_t* const*)p1)->name, (*(func_info_t* const*)p2)->name);
183 static dispex_data_t *preprocess_dispex_data(DispatchEx *This)
185 const tid_t *tid = This->data->iface_tids;
192 TRACE("(%p)\n", This);
194 if(This->data->disp_tid) {
195 hres = get_typeinfo(This->data->disp_tid, &dti);
197 ERR("Could not get disp type info: %08x\n", hres);
202 data = heap_alloc(sizeof(dispex_data_t));
204 data->func_disp_cnt = 0;
205 data->funcs = heap_alloc(size*sizeof(func_info_t));
206 list_add_tail(&dispex_data_list, &data->entry);
209 hres = get_typeinfo(*tid, &ti);
215 hres = ITypeInfo_GetFuncDesc(ti, i++, &funcdesc);
219 add_func_info(data, &size, *tid, funcdesc, dti);
220 ITypeInfo_ReleaseFuncDesc(ti, funcdesc);
226 if(!data->func_cnt) {
227 heap_free(data->funcs);
229 }else if(data->func_cnt != size) {
230 data->funcs = heap_realloc(data->funcs, data->func_cnt * sizeof(func_info_t));
233 qsort(data->funcs, data->func_cnt, sizeof(func_info_t), dispid_cmp);
236 data->name_table = heap_alloc(data->func_cnt * sizeof(func_info_t*));
237 for(i=0; i < data->func_cnt; i++)
238 data->name_table[i] = data->funcs+i;
239 qsort(data->name_table, data->func_cnt, sizeof(func_info_t*), func_name_cmp);
241 data->name_table = NULL;
247 static int id_cmp(const void *p1, const void *p2)
249 return *(const DISPID*)p1 - *(const DISPID*)p2;
252 HRESULT get_dispids(tid_t tid, DWORD *ret_size, DISPID **ret)
254 unsigned i, func_cnt;
261 hres = get_typeinfo(tid, &ti);
265 hres = ITypeInfo_GetTypeAttr(ti, &attr);
267 ITypeInfo_Release(ti);
271 func_cnt = attr->cFuncs;
272 ITypeInfo_ReleaseTypeAttr(ti, attr);
274 ids = heap_alloc(func_cnt*sizeof(DISPID));
276 ITypeInfo_Release(ti);
277 return E_OUTOFMEMORY;
280 for(i=0; i < func_cnt; i++) {
281 hres = ITypeInfo_GetFuncDesc(ti, i, &funcdesc);
285 ids[i] = funcdesc->memid;
286 ITypeInfo_ReleaseFuncDesc(ti, funcdesc);
289 ITypeInfo_Release(ti);
295 qsort(ids, func_cnt, sizeof(DISPID), id_cmp);
297 *ret_size = func_cnt;
302 static CRITICAL_SECTION cs_dispex_static_data;
303 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg =
305 0, 0, &cs_dispex_static_data,
306 { &cs_dispex_static_data_dbg.ProcessLocksList, &cs_dispex_static_data_dbg.ProcessLocksList },
307 0, 0, { (DWORD_PTR)(__FILE__ ": dispex_static_data") }
309 static CRITICAL_SECTION cs_dispex_static_data = { &cs_dispex_static_data_dbg, -1, 0, 0, 0, 0 };
312 static dispex_data_t *get_dispex_data(DispatchEx *This)
315 return This->data->data;
317 EnterCriticalSection(&cs_dispex_static_data);
319 if(!This->data->data)
320 This->data->data = preprocess_dispex_data(This);
322 LeaveCriticalSection(&cs_dispex_static_data);
324 return This->data->data;
327 HRESULT call_disp_func(IDispatch *disp, DISPPARAMS *dp)
335 memset(&ei, 0, sizeof(ei));
337 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
338 if(SUCCEEDED(hres)) {
339 hres = IDispatchEx_InvokeEx(dispex, 0, GetUserDefaultLCID(), DISPATCH_METHOD, dp, &res, &ei, NULL);
340 IDispatchEx_Release(dispex);
342 TRACE("Could not get IDispatchEx interface: %08x\n", hres);
343 hres = IDispatch_Invoke(disp, 0, &IID_NULL, GetUserDefaultLCID(), DISPATCH_METHOD,
344 dp, &res, &ei, NULL);
351 static inline BOOL is_custom_dispid(DISPID id)
353 return MSHTML_DISPID_CUSTOM_MIN <= id && id <= MSHTML_DISPID_CUSTOM_MAX;
356 static inline BOOL is_dynamic_dispid(DISPID id)
358 return DISPID_DYNPROP_0 <= id && id <= DISPID_DYNPROP_MAX;
361 static inline dispex_dynamic_data_t *get_dynamic_data(DispatchEx *This, BOOL alloc)
363 return !alloc || This->dynamic_data
365 : (This->dynamic_data = heap_alloc_zero(sizeof(dispex_dynamic_data_t)));
368 static HRESULT get_dynamic_prop(DispatchEx *This, const WCHAR *name, DWORD flags, dynamic_prop_t **ret)
370 const BOOL alloc = flags & fdexNameEnsure;
371 dispex_dynamic_data_t *data;
372 dynamic_prop_t *prop;
374 data = get_dynamic_data(This, alloc);
377 return E_OUTOFMEMORY;
379 TRACE("not found %s\n", debugstr_w(name));
380 return DISP_E_UNKNOWNNAME;
383 for(prop = data->props; prop < data->props+data->prop_cnt; prop++) {
384 if(flags & fdexNameCaseInsensitive ? !strcmpiW(prop->name, name) : !strcmpW(prop->name, name)) {
385 if(prop->flags & DYNPROP_DELETED) {
387 return DISP_E_UNKNOWNNAME;
388 prop->flags &= ~DYNPROP_DELETED;
396 return DISP_E_UNKNOWNNAME;
398 TRACE("creating dynamic prop %s\n", debugstr_w(name));
400 if(!data->buf_size) {
401 data->props = heap_alloc(sizeof(dynamic_prop_t)*4);
403 return E_OUTOFMEMORY;
405 }else if(data->buf_size == data->prop_cnt) {
406 dynamic_prop_t *new_props;
408 new_props = heap_realloc(data->props, sizeof(dynamic_prop_t)*(data->buf_size<<1));
410 return E_OUTOFMEMORY;
412 data->props = new_props;
413 data->buf_size <<= 1;
416 prop = data->props + data->prop_cnt;
418 prop->name = heap_strdupW(name);
420 return E_OUTOFMEMORY;
422 VariantInit(&prop->var);
429 HRESULT dispex_get_dprop_ref(DispatchEx *This, const WCHAR *name, BOOL alloc, VARIANT **ret)
431 dynamic_prop_t *prop;
434 hres = get_dynamic_prop(This, name, alloc ? fdexNameEnsure : 0, &prop);
442 static HRESULT dispex_value(DispatchEx *This, LCID lcid, WORD flags, DISPPARAMS *params,
443 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
445 if(This->data->vtbl && This->data->vtbl->value)
446 return This->data->vtbl->value(This, lcid, flags, params, res, ei, caller);
449 case DISPATCH_PROPERTYGET:
451 V_BSTR(res) = SysAllocString(objectW);
453 return E_OUTOFMEMORY;
456 FIXME("Unimplemented flags %x\n", flags);
463 static HRESULT typeinfo_invoke(DispatchEx *This, func_info_t *func, WORD flags, DISPPARAMS *dp, VARIANT *res,
471 hres = get_typeinfo(func->tid, &ti);
473 ERR("Could not get type info: %08x\n", hres);
477 hres = IUnknown_QueryInterface(This->outer, tid_ids[func->tid], (void**)&unk);
479 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids[func->tid]), hres);
483 hres = ITypeInfo_Invoke(ti, unk, func->id, flags, dp, res, ei, &argerr);
485 IUnknown_Release(unk);
489 static inline func_disp_t *impl_from_IUnknown(IUnknown *iface)
491 return CONTAINING_RECORD(iface, func_disp_t, IUnknown_iface);
494 static HRESULT WINAPI Function_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
496 func_disp_t *This = impl_from_IUnknown(iface);
498 if(IsEqualGUID(&IID_IUnknown, riid)) {
499 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
500 *ppv = &This->IUnknown_iface;
501 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
502 return *ppv ? S_OK : E_NOINTERFACE;
505 return E_NOINTERFACE;
508 IUnknown_AddRef((IUnknown*)*ppv);
512 static ULONG WINAPI Function_AddRef(IUnknown *iface)
514 func_disp_t *This = impl_from_IUnknown(iface);
516 TRACE("(%p)\n", This);
518 return IDispatchEx_AddRef(&This->obj->IDispatchEx_iface);
521 static ULONG WINAPI Function_Release(IUnknown *iface)
523 func_disp_t *This = impl_from_IUnknown(iface);
525 TRACE("(%p)\n", This);
527 return IDispatchEx_Release(&This->obj->IDispatchEx_iface);
530 static const IUnknownVtbl FunctionUnkVtbl = {
531 Function_QueryInterface,
536 static inline func_disp_t *impl_from_DispatchEx(DispatchEx *iface)
538 return CONTAINING_RECORD(iface, func_disp_t, dispex);
541 static HRESULT function_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *params,
542 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
544 func_disp_t *This = impl_from_DispatchEx(dispex);
548 case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
551 case DISPATCH_METHOD:
552 hres = typeinfo_invoke(This->obj, This->info, flags, params, res, ei);
555 FIXME("Unimplemented flags %x\n", flags);
562 static const dispex_static_data_vtbl_t function_dispex_vtbl = {
568 static const tid_t function_iface_tids[] = {0};
570 static dispex_static_data_t function_dispex = {
571 &function_dispex_vtbl,
577 static func_disp_t *create_func_disp(DispatchEx *obj, func_info_t *info)
581 ret = heap_alloc_zero(sizeof(func_disp_t));
585 ret->IUnknown_iface.lpVtbl = &FunctionUnkVtbl;
586 init_dispex(&ret->dispex, &ret->IUnknown_iface, &function_dispex);
593 static HRESULT function_invoke(DispatchEx *This, func_info_t *func, WORD flags, DISPPARAMS *dp, VARIANT *res,
599 case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
602 case DISPATCH_METHOD:
603 hres = typeinfo_invoke(This, func, flags, dp, res, ei);
605 case DISPATCH_PROPERTYGET: {
606 dispex_dynamic_data_t *dynamic_data;
608 if(func->id == DISPID_VALUE) {
611 ret = SysAllocString(objectW);
613 return E_OUTOFMEMORY;
620 dynamic_data = get_dynamic_data(This, TRUE);
622 return E_OUTOFMEMORY;
624 if(!dynamic_data->func_disps) {
625 dynamic_data->func_disps = heap_alloc_zero(This->data->data->func_disp_cnt * sizeof(func_disp_t*));
626 if(!dynamic_data->func_disps)
627 return E_OUTOFMEMORY;
630 if(!dynamic_data->func_disps[func->func_disp_idx]) {
631 dynamic_data->func_disps[func->func_disp_idx] = create_func_disp(This, func);
632 if(!dynamic_data->func_disps[func->func_disp_idx])
633 return E_OUTOFMEMORY;
636 V_VT(res) = VT_DISPATCH;
637 V_DISPATCH(res) = (IDispatch*)&dynamic_data->func_disps[func->func_disp_idx]->dispex.IDispatchEx_iface;
638 IDispatch_AddRef(V_DISPATCH(res));
643 FIXME("Unimplemented flags %x\n", flags);
644 case DISPATCH_PROPERTYPUT:
651 static HRESULT get_builtin_func(dispex_data_t *data, DISPID id, func_info_t **ret)
656 max = data->func_cnt-1;
661 if(data->funcs[n].id == id) {
662 *ret = data->funcs+n;
666 if(data->funcs[n].id < id)
672 WARN("invalid id %x\n", id);
673 return DISP_E_UNKNOWNNAME;
676 static HRESULT get_builtin_id(DispatchEx *This, BSTR name, DWORD grfdex, DISPID *ret)
681 data = get_dispex_data(This);
686 max = data->func_cnt-1;
691 c = strcmpiW(data->name_table[n]->name, name);
693 if((grfdex & fdexNameCaseSensitive) && strcmpW(data->name_table[n]->name, name))
696 *ret = data->name_table[n]->id;
706 if(This->data->vtbl && This->data->vtbl->get_dispid) {
709 hres = This->data->vtbl->get_dispid(This, name, grfdex, ret);
710 if(hres != DISP_E_UNKNOWNNAME)
714 return DISP_E_UNKNOWNNAME;
717 static HRESULT invoke_builtin_prop(DispatchEx *This, DISPID id, LCID lcid, WORD flags, DISPPARAMS *dp,
718 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
724 data = get_dispex_data(This);
728 hres = get_builtin_func(data, id, &func);
729 if(id == DISPID_VALUE && hres == DISP_E_UNKNOWNNAME)
730 return dispex_value(This, lcid, flags, dp, res, ei, caller);
734 if(func->func_disp_idx == -1)
735 hres = typeinfo_invoke(This, func, flags, dp, res, ei);
737 hres = function_invoke(This, func, flags, dp, res, ei);
742 HRESULT remove_prop(DispatchEx *This, BSTR name, VARIANT_BOOL *success)
744 dynamic_prop_t *prop;
748 hres = get_builtin_id(This, name, 0, &id);
750 DISPID named_id = DISPID_PROPERTYPUT;
752 DISPPARAMS dp = {&var,&named_id,1,1};
755 V_VT(&var) = VT_EMPTY;
756 memset(&ei, 0, sizeof(ei));
757 hres = invoke_builtin_prop(This, id, 0, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
761 *success = VARIANT_TRUE;
765 hres = get_dynamic_prop(This, name, 0, &prop);
767 if(hres != DISP_E_UNKNOWNNAME)
769 *success = VARIANT_FALSE;
773 VariantClear(&prop->var);
774 prop->flags |= DYNPROP_DELETED;
775 *success = VARIANT_TRUE;
779 static inline DispatchEx *impl_from_IDispatchEx(IDispatchEx *iface)
781 return CONTAINING_RECORD(iface, DispatchEx, IDispatchEx_iface);
784 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
786 DispatchEx *This = impl_from_IDispatchEx(iface);
788 return IUnknown_QueryInterface(This->outer, riid, ppv);
791 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
793 DispatchEx *This = impl_from_IDispatchEx(iface);
795 return IUnknown_AddRef(This->outer);
798 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
800 DispatchEx *This = impl_from_IDispatchEx(iface);
802 return IUnknown_Release(This->outer);
805 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
807 DispatchEx *This = impl_from_IDispatchEx(iface);
809 TRACE("(%p)->(%p)\n", This, pctinfo);
815 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
816 LCID lcid, ITypeInfo **ppTInfo)
818 DispatchEx *This = impl_from_IDispatchEx(iface);
821 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
823 hres = get_typeinfo(This->data->disp_tid, ppTInfo);
827 ITypeInfo_AddRef(*ppTInfo);
831 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
832 LPOLESTR *rgszNames, UINT cNames,
833 LCID lcid, DISPID *rgDispId)
835 DispatchEx *This = impl_from_IDispatchEx(iface);
839 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
842 for(i=0; i < cNames; i++) {
843 hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
851 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
852 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
853 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
855 DispatchEx *This = impl_from_IDispatchEx(iface);
857 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
858 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
860 return IDispatchEx_InvokeEx(&This->IDispatchEx_iface, dispIdMember, lcid, wFlags, pDispParams,
861 pVarResult, pExcepInfo, NULL);
864 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
866 DispatchEx *This = impl_from_IDispatchEx(iface);
867 dynamic_prop_t *dprop;
870 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
872 if(grfdex & ~(fdexNameCaseSensitive|fdexNameCaseInsensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK))
873 FIXME("Unsupported grfdex %x\n", grfdex);
875 hres = get_builtin_id(This, bstrName, grfdex, pid);
876 if(hres != DISP_E_UNKNOWNNAME)
879 hres = get_dynamic_prop(This, bstrName, grfdex, &dprop);
883 *pid = DISPID_DYNPROP_0 + (dprop - This->dynamic_data->props);
887 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
888 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
890 DispatchEx *This = impl_from_IDispatchEx(iface);
893 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
895 if(is_custom_dispid(id) && This->data->vtbl && This->data->vtbl->invoke)
896 return This->data->vtbl->invoke(This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
898 if(wFlags == DISPATCH_CONSTRUCT) {
899 if(id == DISPID_VALUE) {
900 if(This->data->vtbl && This->data->vtbl->value) {
901 return This->data->vtbl->value(This, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
903 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
906 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
910 if(is_dynamic_dispid(id)) {
911 DWORD idx = id - DISPID_DYNPROP_0;
912 dynamic_prop_t *prop;
914 if(!This->dynamic_data || This->dynamic_data->prop_cnt <= idx)
915 return DISP_E_UNKNOWNNAME;
917 prop = This->dynamic_data->props+idx;
920 case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
923 case DISPATCH_METHOD: {
924 DISPID named_arg = DISPID_THIS;
925 DISPPARAMS dp = {NULL, &named_arg, 0, 1};
928 if(V_VT(&prop->var) != VT_DISPATCH) {
929 FIXME("invoke %s\n", debugstr_variant(&prop->var));
933 if(pdp->cNamedArgs) {
934 FIXME("named args not supported\n");
938 dp.rgvarg = heap_alloc((pdp->cArgs+1)*sizeof(VARIANTARG));
940 return E_OUTOFMEMORY;
942 dp.cArgs = pdp->cArgs+1;
943 memcpy(dp.rgvarg+1, pdp->rgvarg, pdp->cArgs*sizeof(VARIANTARG));
945 V_VT(dp.rgvarg) = VT_DISPATCH;
946 V_DISPATCH(dp.rgvarg) = (IDispatch*)&This->IDispatchEx_iface;
948 hres = IDispatch_QueryInterface(V_DISPATCH(&prop->var), &IID_IDispatchEx, (void**)&dispex);
949 TRACE("%s call\n", debugstr_w(This->dynamic_data->props[idx].name));
950 if(SUCCEEDED(hres)) {
951 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, lcid, wFlags, &dp, pvarRes, pei, pspCaller);
952 IDispatchEx_Release(dispex);
955 hres = IDispatch_Invoke(V_DISPATCH(&prop->var), DISPID_VALUE, &IID_NULL, lcid, wFlags, pdp, pvarRes, pei, &err);
957 TRACE("%s ret %08x\n", debugstr_w(This->dynamic_data->props[idx].name), hres);
959 heap_free(dp.rgvarg);
962 case DISPATCH_PROPERTYGET:
963 if(prop->flags & DYNPROP_DELETED)
964 return DISP_E_UNKNOWNNAME;
965 return VariantCopy(pvarRes, &prop->var);
966 case DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF:
967 case DISPATCH_PROPERTYPUT:
968 if(pdp->cArgs != 1 || (pdp->cNamedArgs == 1 && *pdp->rgdispidNamedArgs != DISPID_PROPERTYPUT)
969 || pdp->cNamedArgs > 1) {
970 FIXME("invalid args\n");
974 TRACE("put %s\n", debugstr_variant(pdp->rgvarg));
975 VariantClear(&prop->var);
976 hres = VariantCopy(&prop->var, pdp->rgvarg);
980 prop->flags &= ~DYNPROP_DELETED;
983 FIXME("unhandled wFlags %x\n", wFlags);
988 return invoke_builtin_prop(This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
991 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
993 DispatchEx *This = impl_from_IDispatchEx(iface);
995 TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
997 /* Not implemented by IE */
1001 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1003 DispatchEx *This = impl_from_IDispatchEx(iface);
1004 FIXME("(%p)->(%x)\n", This, id);
1008 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1010 DispatchEx *This = impl_from_IDispatchEx(iface);
1011 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
1015 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1017 DispatchEx *This = impl_from_IDispatchEx(iface);
1018 dispex_data_t *data;
1022 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
1024 if(is_dynamic_dispid(id)) {
1025 DWORD idx = id - DISPID_DYNPROP_0;
1027 if(!This->dynamic_data || This->dynamic_data->prop_cnt <= idx)
1028 return DISP_E_UNKNOWNNAME;
1030 *pbstrName = SysAllocString(This->dynamic_data->props[idx].name);
1032 return E_OUTOFMEMORY;
1037 data = get_dispex_data(This);
1041 hres = get_builtin_func(data, id, &func);
1045 *pbstrName = SysAllocString(func->name);
1047 return E_OUTOFMEMORY;
1051 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1053 DispatchEx *This = impl_from_IDispatchEx(iface);
1054 dispex_data_t *data;
1058 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
1060 if(is_dynamic_dispid(id)) {
1061 DWORD idx = id - DISPID_DYNPROP_0;
1063 if(!This->dynamic_data || This->dynamic_data->prop_cnt <= idx)
1064 return DISP_E_UNKNOWNNAME;
1066 while(++idx < This->dynamic_data->prop_cnt && This->dynamic_data->props[idx].flags & DYNPROP_DELETED);
1068 if(idx == This->dynamic_data->prop_cnt) {
1069 *pid = DISPID_STARTENUM;
1073 *pid = DISPID_DYNPROP_0+idx;
1077 data = get_dispex_data(This);
1081 if(id == DISPID_STARTENUM) {
1084 hres = get_builtin_func(data, id, &func);
1090 while(func < data->funcs+data->func_cnt) {
1091 /* FIXME: Skip hidden properties */
1092 if(func->func_disp_idx == -1) {
1099 if(This->dynamic_data && This->dynamic_data->prop_cnt) {
1100 *pid = DISPID_DYNPROP_0;
1104 *pid = DISPID_STARTENUM;
1108 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1110 DispatchEx *This = impl_from_IDispatchEx(iface);
1111 FIXME("(%p)->(%p)\n", This, ppunk);
1115 static IDispatchExVtbl DispatchExVtbl = {
1116 DispatchEx_QueryInterface,
1119 DispatchEx_GetTypeInfoCount,
1120 DispatchEx_GetTypeInfo,
1121 DispatchEx_GetIDsOfNames,
1123 DispatchEx_GetDispID,
1124 DispatchEx_InvokeEx,
1125 DispatchEx_DeleteMemberByName,
1126 DispatchEx_DeleteMemberByDispID,
1127 DispatchEx_GetMemberProperties,
1128 DispatchEx_GetMemberName,
1129 DispatchEx_GetNextDispID,
1130 DispatchEx_GetNameSpaceParent
1133 BOOL dispex_query_interface(DispatchEx *This, REFIID riid, void **ppv)
1135 static const IID IID_UndocumentedScriptIface =
1136 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1137 static const IID IID_IDispatchJS =
1138 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1140 if(IsEqualGUID(&IID_IDispatch, riid)) {
1141 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1142 *ppv = &This->IDispatchEx_iface;
1143 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1144 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1145 *ppv = &This->IDispatchEx_iface;
1146 }else if(IsEqualGUID(&IID_IDispatchJS, riid)) {
1147 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This, ppv);
1149 }else if(IsEqualGUID(&IID_UndocumentedScriptIface, riid)) {
1150 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This, ppv);
1157 IUnknown_AddRef((IUnknown*)*ppv);
1161 void release_dispex(DispatchEx *This)
1163 dynamic_prop_t *prop;
1165 if(!This->dynamic_data)
1168 for(prop = This->dynamic_data->props; prop < This->dynamic_data->props + This->dynamic_data->prop_cnt; prop++) {
1169 VariantClear(&prop->var);
1170 heap_free(prop->name);
1173 heap_free(This->dynamic_data->props);
1175 if(This->dynamic_data->func_disps) {
1178 for(i=0; i < This->data->data->func_disp_cnt; i++) {
1179 if(This->dynamic_data->func_disps[i]) {
1180 release_dispex(&This->dynamic_data->func_disps[i]->dispex);
1181 heap_free(This->dynamic_data->func_disps[i]);
1185 heap_free(This->dynamic_data->func_disps);
1188 heap_free(This->dynamic_data);
1191 void init_dispex(DispatchEx *dispex, IUnknown *outer, dispex_static_data_t *data)
1193 dispex->IDispatchEx_iface.lpVtbl = &DispatchExVtbl;
1194 dispex->outer = outer;
1195 dispex->data = data;
1196 dispex->dynamic_data = NULL;