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);
41 struct dispex_data_t {
44 func_info_t **name_table;
57 const IUnknownVtbl *lpIUnknownVtbl;
62 #define FUNCUNKNOWN(x) ((IUnknown*) &(x)->lpIUnknownVtbl)
64 struct dispex_dynamic_data_t {
67 dynamic_prop_t *props;
68 func_disp_t **func_disps;
71 #define DISPID_DYNPROP_0 0x50000000
72 #define DISPID_DYNPROP_MAX 0x5fffffff
74 static ITypeLib *typelib;
75 static ITypeInfo *typeinfos[LAST_tid];
76 static struct list dispex_data_list = LIST_INIT(dispex_data_list);
78 static REFIID tid_ids[] = {
81 &DIID_DispDOMChildrenCollection,
83 &DIID_DispHTMLCommentElement,
84 &DIID_DispHTMLCurrentStyle,
85 &DIID_DispHTMLDocument,
86 &DIID_DispHTMLDOMTextNode,
87 &DIID_DispHTMLElementCollection,
88 &DIID_DispHTMLGenericElement,
91 &DIID_DispHTMLInputElement,
92 &DIID_DispHTMLLocation,
93 &DIID_DispHTMLNavigator,
94 &DIID_DispHTMLOptionElement,
95 &DIID_DispHTMLSelectElement,
98 &DIID_DispHTMLTableRow,
99 &DIID_DispHTMLUnknownElement,
100 &DIID_DispHTMLWindow2,
101 &IID_IHTMLBodyElement,
102 &IID_IHTMLBodyElement2,
103 &IID_IHTMLCommentElement,
104 &IID_IHTMLCurrentStyle,
105 &IID_IHTMLCurrentStyle2,
106 &IID_IHTMLCurrentStyle3,
107 &IID_IHTMLCurrentStyle4,
112 &IID_IHTMLDOMChildrenCollection,
115 &IID_IHTMLDOMTextNode,
120 &IID_IHTMLElementCollection,
122 &IID_IHTMLFrameBase2,
123 &IID_IHTMLGenericElement,
124 &IID_IHTMLImgElement,
125 &IID_IHTMLInputElement,
127 &IID_IHTMLOptionElement,
128 &IID_IHTMLSelectElement,
135 &IID_IHTMLTextContainer,
136 &IID_IHTMLUniqueName,
142 static HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
149 hres = LoadRegTypeLib(&LIBID_MSHTML, 4, 0, LOCALE_SYSTEM_DEFAULT, &tl);
151 ERR("LoadRegTypeLib failed: %08x\n", hres);
155 if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
156 ITypeLib_Release(tl);
159 if(!typeinfos[tid]) {
162 hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &typeinfo);
164 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
168 if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), typeinfo, NULL))
169 ITypeInfo_Release(typeinfo);
172 *typeinfo = typeinfos[tid];
176 void release_typelib(void)
181 while(!list_empty(&dispex_data_list)) {
182 iter = LIST_ENTRY(list_head(&dispex_data_list), dispex_data_t, entry);
183 list_remove(&iter->entry);
185 for(i=0; i < iter->func_cnt; i++)
186 SysFreeString(iter->funcs[i].name);
188 heap_free(iter->funcs);
189 heap_free(iter->name_table);
196 for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
198 ITypeInfo_Release(typeinfos[i]);
200 ITypeLib_Release(typelib);
203 static void add_func_info(dispex_data_t *data, DWORD *size, tid_t tid, const FUNCDESC *desc, ITypeInfo *dti)
207 if(data->func_cnt && data->funcs[data->func_cnt-1].id == desc->memid)
210 if(data->func_cnt == *size)
211 data->funcs = heap_realloc(data->funcs, (*size <<= 1)*sizeof(func_info_t));
213 hres = ITypeInfo_GetDocumentation(dti, desc->memid, &data->funcs[data->func_cnt].name, NULL, NULL, NULL);
217 data->funcs[data->func_cnt].id = desc->memid;
218 data->funcs[data->func_cnt].tid = tid;
219 data->funcs[data->func_cnt].func_disp_idx = desc->invkind == INVOKE_FUNC ? data->func_disp_cnt++ : -1;
224 static int dispid_cmp(const void *p1, const void *p2)
226 return ((func_info_t*)p1)->id - ((func_info_t*)p2)->id;
229 static int func_name_cmp(const void *p1, const void *p2)
231 return strcmpiW((*(func_info_t**)p1)->name, (*(func_info_t**)p2)->name);
234 static dispex_data_t *preprocess_dispex_data(DispatchEx *This)
236 const tid_t *tid = This->data->iface_tids;
243 TRACE("(%p)\n", This);
245 hres = get_typeinfo(This->data->disp_tid, &dti);
247 ERR("Could not get disp type info: %08x\n", hres);
251 data = heap_alloc(sizeof(dispex_data_t));
253 data->func_disp_cnt = 0;
254 data->funcs = heap_alloc(size*sizeof(func_info_t));
255 list_add_tail(&dispex_data_list, &data->entry);
258 hres = get_typeinfo(*tid, &ti);
264 hres = ITypeInfo_GetFuncDesc(ti, i++, &funcdesc);
268 add_func_info(data, &size, *tid, funcdesc, dti);
269 ITypeInfo_ReleaseFuncDesc(ti, funcdesc);
275 if(!data->func_cnt) {
276 heap_free(data->funcs);
278 }else if(data->func_cnt != size) {
279 data->funcs = heap_realloc(data->funcs, data->func_cnt * sizeof(func_info_t));
282 qsort(data->funcs, data->func_cnt, sizeof(func_info_t), dispid_cmp);
285 data->name_table = heap_alloc(data->func_cnt * sizeof(func_info_t*));
286 for(i=0; i < data->func_cnt; i++)
287 data->name_table[i] = data->funcs+i;
288 qsort(data->name_table, data->func_cnt, sizeof(func_info_t*), func_name_cmp);
290 data->name_table = NULL;
296 static CRITICAL_SECTION cs_dispex_static_data;
297 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg =
299 0, 0, &cs_dispex_static_data,
300 { &cs_dispex_static_data_dbg.ProcessLocksList, &cs_dispex_static_data_dbg.ProcessLocksList },
301 0, 0, { (DWORD_PTR)(__FILE__ ": dispex_static_data") }
303 static CRITICAL_SECTION cs_dispex_static_data = { &cs_dispex_static_data_dbg, -1, 0, 0, 0, 0 };
306 static dispex_data_t *get_dispex_data(DispatchEx *This)
309 return This->data->data;
311 EnterCriticalSection(&cs_dispex_static_data);
313 if(!This->data->data)
314 This->data->data = preprocess_dispex_data(This);
316 LeaveCriticalSection(&cs_dispex_static_data);
318 return This->data->data;
321 HRESULT call_disp_func(IDispatch *disp, DISPPARAMS *dp)
328 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
330 FIXME("Could not get IDispatchEx interface: %08x\n", hres);
335 memset(&ei, 0, sizeof(ei));
337 hres = IDispatchEx_InvokeEx(dispex, 0, GetUserDefaultLCID(), DISPATCH_METHOD, dp, &res, &ei, NULL);
339 IDispatchEx_Release(dispex);
344 static inline BOOL is_custom_dispid(DISPID id)
346 return MSHTML_DISPID_CUSTOM_MIN <= id && id <= MSHTML_DISPID_CUSTOM_MAX;
349 static inline BOOL is_dynamic_dispid(DISPID id)
351 return DISPID_DYNPROP_0 <= id && id <= DISPID_DYNPROP_MAX;
354 static inline dispex_dynamic_data_t *get_dynamic_data(DispatchEx *This, BOOL alloc)
356 return !alloc || This->dynamic_data
358 : (This->dynamic_data = heap_alloc_zero(sizeof(dispex_dynamic_data_t)));
361 static HRESULT get_dynamic_prop(DispatchEx *This, const WCHAR *name, BOOL alloc, dynamic_prop_t **ret)
363 dispex_dynamic_data_t *data = get_dynamic_data(This, alloc);
368 return E_OUTOFMEMORY;
370 TRACE("not found %s\n", debugstr_w(name));
371 return DISP_E_UNKNOWNNAME;
374 for(i=0; i < data->prop_cnt; i++) {
375 if(!strcmpW(data->props[i].name, name)) {
376 *ret = data->props+i;
381 TRACE("creating dynamic prop %s\n", debugstr_w(name));
383 if(!data->buf_size) {
384 data->props = heap_alloc(sizeof(dynamic_prop_t)*4);
386 return E_OUTOFMEMORY;
388 }else if(data->buf_size == data->prop_cnt) {
389 dynamic_prop_t *new_props;
391 new_props = heap_realloc(data->props, sizeof(dynamic_prop_t)*(data->buf_size<<1));
393 return E_OUTOFMEMORY;
395 data->props = new_props;
396 data->buf_size <<= 1;
399 data->props[data->prop_cnt].name = heap_strdupW(name);
400 VariantInit(&data->props[data->prop_cnt].var);
401 *ret = data->props + data->prop_cnt++;
406 HRESULT dispex_get_dprop_ref(DispatchEx *This, const WCHAR *name, BOOL alloc, VARIANT **ret)
408 dynamic_prop_t *prop;
411 hres = get_dynamic_prop(This, name, alloc, &prop);
419 static HRESULT dispex_value(DispatchEx *This, LCID lcid, WORD flags, DISPPARAMS *params,
420 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
422 static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
424 if(This->data->vtbl && This->data->vtbl->value)
425 return This->data->vtbl->value(This->outer, lcid, flags, params, res, ei, caller);
428 case DISPATCH_PROPERTYGET:
430 V_BSTR(res) = SysAllocString(objectW);
432 return E_OUTOFMEMORY;
435 FIXME("Unimplemented flags %x\n", flags);
442 static HRESULT typeinfo_invoke(DispatchEx *This, func_info_t *func, WORD flags, DISPPARAMS *dp, VARIANT *res,
450 hres = get_typeinfo(func->tid, &ti);
452 ERR("Could not get type info: %08x\n", hres);
456 hres = IUnknown_QueryInterface(This->outer, tid_ids[func->tid], (void**)&unk);
458 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids[func->tid]), hres);
462 hres = ITypeInfo_Invoke(ti, unk, func->id, flags, dp, res, ei, &argerr);
464 IUnknown_Release(unk);
468 #define FUNCTION_THIS(iface) DEFINE_THIS(func_disp_t, IUnknown, iface)
470 static HRESULT WINAPI Function_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
472 func_disp_t *This = FUNCTION_THIS(iface);
474 if(IsEqualGUID(&IID_IUnknown, riid)) {
475 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
476 *ppv = FUNCUNKNOWN(This);
477 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
478 return *ppv ? S_OK : E_NOINTERFACE;
481 return E_NOINTERFACE;
484 IUnknown_AddRef((IUnknown*)*ppv);
488 static ULONG WINAPI Function_AddRef(IUnknown *iface)
490 func_disp_t *This = FUNCTION_THIS(iface);
492 TRACE("(%p)\n", This);
494 return IDispatchEx_AddRef(DISPATCHEX(This->obj));
497 static ULONG WINAPI Function_Release(IUnknown *iface)
499 func_disp_t *This = FUNCTION_THIS(iface);
501 TRACE("(%p)\n", This);
503 return IDispatchEx_Release(DISPATCHEX(This->obj));
506 static HRESULT function_value(IUnknown *iface, LCID lcid, WORD flags, DISPPARAMS *params,
507 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
509 func_disp_t *This = FUNCTION_THIS(iface);
513 case DISPATCH_METHOD:
514 hres = typeinfo_invoke(This->obj, This->info, flags, params, res, ei);
517 FIXME("Unimplemented flags %x\n", flags);
526 static const IUnknownVtbl FunctionUnkVtbl = {
527 Function_QueryInterface,
532 static const dispex_static_data_vtbl_t function_dispex_vtbl = {
538 static dispex_static_data_t function_dispex = {
539 &function_dispex_vtbl,
545 static func_disp_t *create_func_disp(DispatchEx *obj, func_info_t *info)
549 ret = heap_alloc_zero(sizeof(func_disp_t));
553 ret->lpIUnknownVtbl = &FunctionUnkVtbl;
554 init_dispex(&ret->dispex, FUNCUNKNOWN(ret), &function_dispex);
561 static HRESULT function_invoke(DispatchEx *This, func_info_t *func, WORD flags, DISPPARAMS *dp, VARIANT *res,
567 case DISPATCH_METHOD:
568 hres = typeinfo_invoke(This, func, flags, dp, res, ei);
570 case DISPATCH_PROPERTYGET: {
571 dispex_dynamic_data_t *dynamic_data;
573 dynamic_data = get_dynamic_data(This, TRUE);
575 return E_OUTOFMEMORY;
577 if(!dynamic_data->func_disps) {
578 dynamic_data->func_disps = heap_alloc_zero(This->data->data->func_disp_cnt * sizeof(func_disp_t*));
579 if(!dynamic_data->func_disps)
580 return E_OUTOFMEMORY;
583 if(!dynamic_data->func_disps[func->func_disp_idx]) {
584 dynamic_data->func_disps[func->func_disp_idx] = create_func_disp(This, func);
585 if(!dynamic_data->func_disps[func->func_disp_idx])
586 return E_OUTOFMEMORY;
589 V_VT(res) = VT_DISPATCH;
590 V_DISPATCH(res) = (IDispatch*)DISPATCHEX(&dynamic_data->func_disps[func->func_disp_idx]->dispex);
591 IDispatch_AddRef(V_DISPATCH(res));
596 FIXME("Unimplemented flags %x\n", flags);
597 case DISPATCH_PROPERTYPUT:
604 static HRESULT get_builtin_func(dispex_data_t *data, DISPID id, func_info_t **ret)
609 max = data->func_cnt-1;
614 if(data->funcs[n].id == id)
617 if(data->funcs[n].id < id)
624 WARN("invalid id %x\n", id);
625 return DISP_E_UNKNOWNNAME;
628 *ret = data->funcs+n;
632 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
634 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
636 DispatchEx *This = DISPATCHEX_THIS(iface);
638 return IUnknown_QueryInterface(This->outer, riid, ppv);
641 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
643 DispatchEx *This = DISPATCHEX_THIS(iface);
645 return IUnknown_AddRef(This->outer);
648 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
650 DispatchEx *This = DISPATCHEX_THIS(iface);
652 return IUnknown_Release(This->outer);
655 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
657 DispatchEx *This = DISPATCHEX_THIS(iface);
659 TRACE("(%p)->(%p)\n", This, pctinfo);
665 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
666 LCID lcid, ITypeInfo **ppTInfo)
668 DispatchEx *This = DISPATCHEX_THIS(iface);
671 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
673 hres = get_typeinfo(This->data->disp_tid, ppTInfo);
677 ITypeInfo_AddRef(*ppTInfo);
681 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
682 LPOLESTR *rgszNames, UINT cNames,
683 LCID lcid, DISPID *rgDispId)
685 DispatchEx *This = DISPATCHEX_THIS(iface);
689 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
692 for(i=0; i < cNames; i++) {
693 hres = IDispatchEx_GetDispID(DISPATCHEX(This), rgszNames[i], 0, rgDispId+i);
701 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
702 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
703 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
705 DispatchEx *This = DISPATCHEX_THIS(iface);
707 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
708 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
710 return IDispatchEx_InvokeEx(DISPATCHEX(This), dispIdMember, lcid, wFlags,
711 pDispParams, pVarResult, pExcepInfo, NULL);
714 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
716 DispatchEx *This = DISPATCHEX_THIS(iface);
717 dynamic_prop_t *dprop;
722 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
724 if(grfdex & ~(fdexNameCaseSensitive|fdexNameEnsure|fdexNameImplicit))
725 FIXME("Unsupported grfdex %x\n", grfdex);
727 data = get_dispex_data(This);
732 max = data->func_cnt-1;
737 c = strcmpiW(data->name_table[n]->name, bstrName);
739 if((grfdex & fdexNameCaseSensitive) && strcmpW(data->name_table[n]->name, bstrName))
742 *pid = data->name_table[n]->id;
752 if(This->data->vtbl && This->data->vtbl->get_dispid) {
755 hres = This->data->vtbl->get_dispid(This->outer, bstrName, grfdex, pid);
756 if(hres != DISP_E_UNKNOWNNAME)
760 hres = get_dynamic_prop(This, bstrName, grfdex&fdexNameEnsure, &dprop);
764 *pid = DISPID_DYNPROP_0 + (dprop - This->dynamic_data->props);
768 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
769 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
771 DispatchEx *This = DISPATCHEX_THIS(iface);
776 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
778 if(id == DISPID_VALUE)
779 return dispex_value(This, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
781 if(is_custom_dispid(id) && This->data->vtbl && This->data->vtbl->invoke)
782 return This->data->vtbl->invoke(This->outer, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
784 if(wFlags == DISPATCH_CONSTRUCT) {
785 FIXME("DISPATCH_CONSTRUCT not implemented\n");
789 if(is_dynamic_dispid(id)) {
790 DWORD idx = id - DISPID_DYNPROP_0;
793 if(!This->dynamic_data || This->dynamic_data->prop_cnt <= idx)
794 return DISP_E_UNKNOWNNAME;
796 var = &This->dynamic_data->props[idx].var;
800 DISPID named_arg = DISPID_THIS;
801 DISPPARAMS dp = {NULL, &named_arg, 0, 1};
804 if(V_VT(var) != VT_DISPATCH) {
805 FIXME("invoke vt %d\n", V_VT(var));
809 if(pdp->cNamedArgs) {
810 FIXME("named args not supported\n");
814 dp.rgvarg = heap_alloc((pdp->cArgs+1)*sizeof(VARIANTARG));
816 return E_OUTOFMEMORY;
818 dp.cArgs = pdp->cArgs+1;
819 memcpy(dp.rgvarg+1, pdp->rgvarg, pdp->cArgs*sizeof(VARIANTARG));
821 V_VT(dp.rgvarg) = VT_DISPATCH;
822 V_DISPATCH(dp.rgvarg) = (IDispatch*)DISPATCHEX(This);
824 hres = IDispatch_QueryInterface(V_DISPATCH(var), &IID_IDispatchEx, (void**)&dispex);
825 TRACE("%s call\n", debugstr_w(This->dynamic_data->props[idx].name));
826 if(SUCCEEDED(hres)) {
827 hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, lcid, wFlags, &dp, pvarRes, pei, pspCaller);
828 IDispatchEx_Release(dispex);
831 hres = IDispatch_Invoke(V_DISPATCH(var), DISPID_VALUE, &IID_NULL, lcid, wFlags, pdp, pvarRes, pei, &err);
833 TRACE("%s ret %08x\n", debugstr_w(This->dynamic_data->props[idx].name), hres);
835 heap_free(dp.rgvarg);
838 case INVOKE_PROPERTYGET:
839 return VariantCopy(pvarRes, var);
840 case INVOKE_PROPERTYPUT:
842 return VariantCopy(var, pdp->rgvarg);
844 FIXME("unhandled wFlags %x\n", wFlags);
849 data = get_dispex_data(This);
853 hres = get_builtin_func(data, id, &func);
857 if(func->func_disp_idx == -1)
858 hres = typeinfo_invoke(This, func, wFlags, pdp, pvarRes, pei);
860 hres = function_invoke(This, func, wFlags, pdp, pvarRes, pei);
865 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
867 DispatchEx *This = DISPATCHEX_THIS(iface);
868 FIXME("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
872 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
874 DispatchEx *This = DISPATCHEX_THIS(iface);
875 FIXME("(%p)->(%x)\n", This, id);
879 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
881 DispatchEx *This = DISPATCHEX_THIS(iface);
882 FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
886 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
888 DispatchEx *This = DISPATCHEX_THIS(iface);
893 TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
895 if(is_dynamic_dispid(id)) {
896 DWORD idx = id - DISPID_DYNPROP_0;
898 if(!This->dynamic_data || This->dynamic_data->prop_cnt <= idx)
899 return DISP_E_UNKNOWNNAME;
901 *pbstrName = SysAllocString(This->dynamic_data->props[idx].name);
903 return E_OUTOFMEMORY;
908 data = get_dispex_data(This);
912 hres = get_builtin_func(data, id, &func);
916 *pbstrName = SysAllocString(func->name);
918 return E_OUTOFMEMORY;
922 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
924 DispatchEx *This = DISPATCHEX_THIS(iface);
929 TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
931 if(is_dynamic_dispid(id)) {
932 DWORD idx = id - DISPID_DYNPROP_0;
934 if(!This->dynamic_data || This->dynamic_data->prop_cnt <= idx)
935 return DISP_E_UNKNOWNNAME;
937 if(idx+1 == This->dynamic_data->prop_cnt) {
938 *pid = DISPID_STARTENUM;
946 data = get_dispex_data(This);
950 if(id == DISPID_STARTENUM) {
953 hres = get_builtin_func(data, id, &func);
959 while(func < data->funcs+data->func_cnt) {
960 /* FIXME: Skip hidden properties */
961 if(func->func_disp_idx == -1) {
968 if(This->dynamic_data && This->dynamic_data->prop_cnt) {
969 *pid = DISPID_DYNPROP_0;
973 *pid = DISPID_STARTENUM;
977 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
979 DispatchEx *This = DISPATCHEX_THIS(iface);
980 FIXME("(%p)->(%p)\n", This, ppunk);
984 #undef DISPATCHEX_THIS
986 static IDispatchExVtbl DispatchExVtbl = {
987 DispatchEx_QueryInterface,
990 DispatchEx_GetTypeInfoCount,
991 DispatchEx_GetTypeInfo,
992 DispatchEx_GetIDsOfNames,
994 DispatchEx_GetDispID,
996 DispatchEx_DeleteMemberByName,
997 DispatchEx_DeleteMemberByDispID,
998 DispatchEx_GetMemberProperties,
999 DispatchEx_GetMemberName,
1000 DispatchEx_GetNextDispID,
1001 DispatchEx_GetNameSpaceParent
1004 BOOL dispex_query_interface(DispatchEx *This, REFIID riid, void **ppv)
1006 static const IID IID_UndocumentedScriptIface =
1007 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1008 static const IID IID_IDispatchJS =
1009 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1011 if(IsEqualGUID(&IID_IDispatch, riid)) {
1012 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1013 *ppv = DISPATCHEX(This);
1014 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1015 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1016 *ppv = DISPATCHEX(This);
1017 }else if(IsEqualGUID(&IID_IDispatchJS, riid)) {
1018 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This, ppv);
1020 }else if(IsEqualGUID(&IID_UndocumentedScriptIface, riid)) {
1021 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This, ppv);
1028 IUnknown_AddRef((IUnknown*)*ppv);
1032 void release_dispex(DispatchEx *This)
1034 dynamic_prop_t *prop;
1036 if(!This->dynamic_data)
1039 for(prop = This->dynamic_data->props; prop < This->dynamic_data->props + This->dynamic_data->prop_cnt; prop++) {
1040 VariantClear(&prop->var);
1041 heap_free(prop->name);
1044 heap_free(This->dynamic_data->props);
1046 if(This->dynamic_data->func_disps) {
1049 for(i=0; i < This->data->data->func_disp_cnt; i++) {
1050 if(This->dynamic_data->func_disps[i]) {
1051 release_dispex(&This->dynamic_data->func_disps[i]->dispex);
1052 heap_free(This->dynamic_data->func_disps[i]);
1056 heap_free(This->dynamic_data->func_disps);
1059 heap_free(This->dynamic_data);
1062 void init_dispex(DispatchEx *dispex, IUnknown *outer, dispex_static_data_t *data)
1064 dispex->lpIDispatchExVtbl = &DispatchExVtbl;
1065 dispex->outer = outer;
1066 dispex->data = data;
1067 dispex->dynamic_data = NULL;