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
;
59 const IUnknownVtbl
*lpIUnknownVtbl
;
64 #define FUNCUNKNOWN(x) ((IUnknown*) &(x)->lpIUnknownVtbl)
66 struct dispex_dynamic_data_t
{
69 dynamic_prop_t
*props
;
70 func_disp_t
**func_disps
;
73 #define DISPID_DYNPROP_0 0x50000000
74 #define DISPID_DYNPROP_MAX 0x5fffffff
76 #define FDEX_VERSION_MASK 0xf0000000
78 static ITypeLib
*typelib
;
79 static ITypeInfo
*typeinfos
[LAST_tid
];
80 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
82 static REFIID tid_ids
[] = {
85 &DIID_DispDOMChildrenCollection
,
86 &DIID_DispHTMLAnchorElement
,
88 &DIID_DispHTMLCommentElement
,
89 &DIID_DispHTMLCurrentStyle
,
90 &DIID_DispHTMLDocument
,
91 &DIID_DispHTMLDOMTextNode
,
92 &DIID_DispHTMLElementCollection
,
93 &DIID_DispHTMLGenericElement
,
96 &DIID_DispHTMLInputElement
,
97 &DIID_DispHTMLLocation
,
98 &DIID_DispHTMLNavigator
,
99 &DIID_DispHTMLOptionElement
,
100 &DIID_DispHTMLScreen
,
101 &DIID_DispHTMLSelectElement
,
104 &DIID_DispHTMLTableRow
,
105 &DIID_DispHTMLUnknownElement
,
106 &DIID_DispHTMLWindow2
,
107 &DIID_HTMLDocumentEvents
,
108 &IID_IHTMLAnchorElement
,
109 &IID_IHTMLBodyElement
,
110 &IID_IHTMLBodyElement2
,
111 &IID_IHTMLCommentElement
,
112 &IID_IHTMLCurrentStyle
,
113 &IID_IHTMLCurrentStyle2
,
114 &IID_IHTMLCurrentStyle3
,
115 &IID_IHTMLCurrentStyle4
,
120 &IID_IHTMLDOMChildrenCollection
,
123 &IID_IHTMLDOMTextNode
,
128 &IID_IHTMLElementCollection
,
131 &IID_IHTMLFrameBase2
,
132 &IID_IHTMLGenericElement
,
133 &IID_IHTMLImageElementFactory
,
134 &IID_IHTMLImgElement
,
135 &IID_IHTMLInputElement
,
137 &IID_IHTMLOptionElement
,
139 &IID_IHTMLSelectElement
,
146 &IID_IHTMLTextContainer
,
147 &IID_IHTMLUniqueName
,
154 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
161 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
163 ERR("LoadRegTypeLib failed: %08x\n", hres
);
167 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
168 ITypeLib_Release(tl
);
171 if(!typeinfos
[tid
]) {
174 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &typeinfo
);
176 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
180 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), typeinfo
, NULL
))
181 ITypeInfo_Release(typeinfo
);
184 *typeinfo
= typeinfos
[tid
];
188 void release_typelib(void)
193 while(!list_empty(&dispex_data_list
)) {
194 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
195 list_remove(&iter
->entry
);
197 for(i
=0; i
< iter
->func_cnt
; i
++)
198 SysFreeString(iter
->funcs
[i
].name
);
200 heap_free(iter
->funcs
);
201 heap_free(iter
->name_table
);
208 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
210 ITypeInfo_Release(typeinfos
[i
]);
212 ITypeLib_Release(typelib
);
215 static void add_func_info(dispex_data_t
*data
, DWORD
*size
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
)
219 if(data
->func_cnt
&& data
->funcs
[data
->func_cnt
-1].id
== desc
->memid
)
222 if(data
->func_cnt
== *size
)
223 data
->funcs
= heap_realloc(data
->funcs
, (*size
<<= 1)*sizeof(func_info_t
));
225 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &data
->funcs
[data
->func_cnt
].name
, NULL
, NULL
, NULL
);
229 data
->funcs
[data
->func_cnt
].id
= desc
->memid
;
230 data
->funcs
[data
->func_cnt
].tid
= tid
;
231 data
->funcs
[data
->func_cnt
].func_disp_idx
= (desc
->invkind
& DISPATCH_METHOD
) ? data
->func_disp_cnt
++ : -1;
236 static int dispid_cmp(const void *p1
, const void *p2
)
238 return ((func_info_t
*)p1
)->id
- ((func_info_t
*)p2
)->id
;
241 static int func_name_cmp(const void *p1
, const void *p2
)
243 return strcmpiW((*(func_info_t
**)p1
)->name
, (*(func_info_t
**)p2
)->name
);
246 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
248 const tid_t
*tid
= This
->data
->iface_tids
;
255 TRACE("(%p)\n", This
);
257 if(This
->data
->disp_tid
) {
258 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
260 ERR("Could not get disp type info: %08x\n", hres
);
265 data
= heap_alloc(sizeof(dispex_data_t
));
267 data
->func_disp_cnt
= 0;
268 data
->funcs
= heap_alloc(size
*sizeof(func_info_t
));
269 list_add_tail(&dispex_data_list
, &data
->entry
);
272 hres
= get_typeinfo(*tid
, &ti
);
278 hres
= ITypeInfo_GetFuncDesc(ti
, i
++, &funcdesc
);
282 add_func_info(data
, &size
, *tid
, funcdesc
, dti
);
283 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
289 if(!data
->func_cnt
) {
290 heap_free(data
->funcs
);
292 }else if(data
->func_cnt
!= size
) {
293 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
296 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
299 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
300 for(i
=0; i
< data
->func_cnt
; i
++)
301 data
->name_table
[i
] = data
->funcs
+i
;
302 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
304 data
->name_table
= NULL
;
310 static int id_cmp(const void *p1
, const void *p2
)
312 return *(DISPID
*)p1
- *(DISPID
*)p2
;
315 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
317 unsigned i
, func_cnt
;
324 hres
= get_typeinfo(tid
, &ti
);
328 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
330 ITypeInfo_Release(ti
);
334 func_cnt
= attr
->cFuncs
;
335 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
337 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
339 ITypeInfo_Release(ti
);
340 return E_OUTOFMEMORY
;
343 for(i
=0; i
< func_cnt
; i
++) {
344 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
348 ids
[i
] = funcdesc
->memid
;
349 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
352 ITypeInfo_Release(ti
);
358 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
360 *ret_size
= func_cnt
;
365 static CRITICAL_SECTION cs_dispex_static_data
;
366 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
368 0, 0, &cs_dispex_static_data
,
369 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
370 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
372 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
375 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
378 return This
->data
->data
;
380 EnterCriticalSection(&cs_dispex_static_data
);
382 if(!This
->data
->data
)
383 This
->data
->data
= preprocess_dispex_data(This
);
385 LeaveCriticalSection(&cs_dispex_static_data
);
387 return This
->data
->data
;
390 HRESULT
call_disp_func(IDispatch
*disp
, DISPPARAMS
*dp
)
397 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
399 FIXME("Could not get IDispatchEx interface: %08x\n", hres
);
404 memset(&ei
, 0, sizeof(ei
));
406 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, dp
, &res
, &ei
, NULL
);
408 IDispatchEx_Release(dispex
);
413 static inline BOOL
is_custom_dispid(DISPID id
)
415 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
418 static inline BOOL
is_dynamic_dispid(DISPID id
)
420 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
423 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
, BOOL alloc
)
425 return !alloc
|| This
->dynamic_data
427 : (This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
)));
430 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
432 const BOOL alloc
= flags
& fdexNameEnsure
;
433 dispex_dynamic_data_t
*data
;
436 data
= get_dynamic_data(This
, alloc
);
439 return E_OUTOFMEMORY
;
441 TRACE("not found %s\n", debugstr_w(name
));
442 return DISP_E_UNKNOWNNAME
;
445 for(i
=0; i
< data
->prop_cnt
; i
++) {
446 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(data
->props
[i
].name
, name
) : !strcmpW(data
->props
[i
].name
, name
)) {
447 *ret
= data
->props
+i
;
453 return DISP_E_UNKNOWNNAME
;
455 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
457 if(!data
->buf_size
) {
458 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
460 return E_OUTOFMEMORY
;
462 }else if(data
->buf_size
== data
->prop_cnt
) {
463 dynamic_prop_t
*new_props
;
465 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
467 return E_OUTOFMEMORY
;
469 data
->props
= new_props
;
470 data
->buf_size
<<= 1;
473 data
->props
[data
->prop_cnt
].name
= heap_strdupW(name
);
474 VariantInit(&data
->props
[data
->prop_cnt
].var
);
475 *ret
= data
->props
+ data
->prop_cnt
++;
480 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
482 dynamic_prop_t
*prop
;
485 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
493 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
494 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
496 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
497 return This
->data
->vtbl
->value(This
->outer
, lcid
, flags
, params
, res
, ei
, caller
);
500 case DISPATCH_PROPERTYGET
:
502 V_BSTR(res
) = SysAllocString(objectW
);
504 return E_OUTOFMEMORY
;
507 FIXME("Unimplemented flags %x\n", flags
);
514 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
522 hres
= get_typeinfo(func
->tid
, &ti
);
524 ERR("Could not get type info: %08x\n", hres
);
528 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
530 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids
[func
->tid
]), hres
);
534 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, dp
, res
, ei
, &argerr
);
536 IUnknown_Release(unk
);
540 #define FUNCTION_THIS(iface) DEFINE_THIS(func_disp_t, IUnknown, iface)
542 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
544 func_disp_t
*This
= FUNCTION_THIS(iface
);
546 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
547 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
548 *ppv
= FUNCUNKNOWN(This
);
549 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
550 return *ppv
? S_OK
: E_NOINTERFACE
;
553 return E_NOINTERFACE
;
556 IUnknown_AddRef((IUnknown
*)*ppv
);
560 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
562 func_disp_t
*This
= FUNCTION_THIS(iface
);
564 TRACE("(%p)\n", This
);
566 return IDispatchEx_AddRef(DISPATCHEX(This
->obj
));
569 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
571 func_disp_t
*This
= FUNCTION_THIS(iface
);
573 TRACE("(%p)\n", This
);
575 return IDispatchEx_Release(DISPATCHEX(This
->obj
));
578 static HRESULT
function_value(IUnknown
*iface
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
579 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
581 func_disp_t
*This
= FUNCTION_THIS(iface
);
585 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
588 case DISPATCH_METHOD
:
589 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
592 FIXME("Unimplemented flags %x\n", flags
);
601 static const IUnknownVtbl FunctionUnkVtbl
= {
602 Function_QueryInterface
,
607 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
613 static const tid_t function_iface_tids
[] = {0};
615 static dispex_static_data_t function_dispex
= {
616 &function_dispex_vtbl
,
622 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
626 ret
= heap_alloc_zero(sizeof(func_disp_t
));
630 ret
->lpIUnknownVtbl
= &FunctionUnkVtbl
;
631 init_dispex(&ret
->dispex
, FUNCUNKNOWN(ret
), &function_dispex
);
638 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
644 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
647 case DISPATCH_METHOD
:
648 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
650 case DISPATCH_PROPERTYGET
: {
651 dispex_dynamic_data_t
*dynamic_data
;
653 if(func
->id
== DISPID_VALUE
) {
656 ret
= SysAllocString(objectW
);
658 return E_OUTOFMEMORY
;
665 dynamic_data
= get_dynamic_data(This
, TRUE
);
667 return E_OUTOFMEMORY
;
669 if(!dynamic_data
->func_disps
) {
670 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(func_disp_t
*));
671 if(!dynamic_data
->func_disps
)
672 return E_OUTOFMEMORY
;
675 if(!dynamic_data
->func_disps
[func
->func_disp_idx
]) {
676 dynamic_data
->func_disps
[func
->func_disp_idx
] = create_func_disp(This
, func
);
677 if(!dynamic_data
->func_disps
[func
->func_disp_idx
])
678 return E_OUTOFMEMORY
;
681 V_VT(res
) = VT_DISPATCH
;
682 V_DISPATCH(res
) = (IDispatch
*)DISPATCHEX(&dynamic_data
->func_disps
[func
->func_disp_idx
]->dispex
);
683 IDispatch_AddRef(V_DISPATCH(res
));
688 FIXME("Unimplemented flags %x\n", flags
);
689 case DISPATCH_PROPERTYPUT
:
696 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
701 max
= data
->func_cnt
-1;
706 if(data
->funcs
[n
].id
== id
) {
707 *ret
= data
->funcs
+n
;
711 if(data
->funcs
[n
].id
< id
)
717 WARN("invalid id %x\n", id
);
718 return DISP_E_UNKNOWNNAME
;
721 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
723 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
725 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
727 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
730 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
732 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
734 return IUnknown_AddRef(This
->outer
);
737 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
739 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
741 return IUnknown_Release(This
->outer
);
744 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
746 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
748 TRACE("(%p)->(%p)\n", This
, pctinfo
);
754 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
755 LCID lcid
, ITypeInfo
**ppTInfo
)
757 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
760 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
762 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
766 ITypeInfo_AddRef(*ppTInfo
);
770 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
771 LPOLESTR
*rgszNames
, UINT cNames
,
772 LCID lcid
, DISPID
*rgDispId
)
774 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
778 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
781 for(i
=0; i
< cNames
; i
++) {
782 hres
= IDispatchEx_GetDispID(DISPATCHEX(This
), rgszNames
[i
], 0, rgDispId
+i
);
790 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
791 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
792 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
794 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
796 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
797 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
799 return IDispatchEx_InvokeEx(DISPATCHEX(This
), dispIdMember
, lcid
, wFlags
,
800 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
803 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
805 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
806 dynamic_prop_t
*dprop
;
811 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
813 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
814 FIXME("Unsupported grfdex %x\n", grfdex
);
816 data
= get_dispex_data(This
);
821 max
= data
->func_cnt
-1;
826 c
= strcmpiW(data
->name_table
[n
]->name
, bstrName
);
828 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, bstrName
))
831 *pid
= data
->name_table
[n
]->id
;
841 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
844 hres
= This
->data
->vtbl
->get_dispid(This
->outer
, bstrName
, grfdex
, pid
);
845 if(hres
!= DISP_E_UNKNOWNNAME
)
849 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
853 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
857 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
858 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
860 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
865 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
867 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
868 return This
->data
->vtbl
->invoke(This
->outer
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
870 if(wFlags
== DISPATCH_CONSTRUCT
) {
871 if(id
== DISPID_VALUE
) {
872 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
873 return This
->data
->vtbl
->value(This
->outer
, lcid
, wFlags
, pdp
,
874 pvarRes
, pei
, pspCaller
);
876 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
879 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
883 if(is_dynamic_dispid(id
)) {
884 DWORD idx
= id
- DISPID_DYNPROP_0
;
887 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
888 return DISP_E_UNKNOWNNAME
;
890 var
= &This
->dynamic_data
->props
[idx
].var
;
893 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
896 case DISPATCH_METHOD
: {
897 DISPID named_arg
= DISPID_THIS
;
898 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
901 if(V_VT(var
) != VT_DISPATCH
) {
902 FIXME("invoke vt %d\n", V_VT(var
));
906 if(pdp
->cNamedArgs
) {
907 FIXME("named args not supported\n");
911 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
913 return E_OUTOFMEMORY
;
915 dp
.cArgs
= pdp
->cArgs
+1;
916 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
918 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
919 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)DISPATCHEX(This
);
921 hres
= IDispatch_QueryInterface(V_DISPATCH(var
), &IID_IDispatchEx
, (void**)&dispex
);
922 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
923 if(SUCCEEDED(hres
)) {
924 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
925 IDispatchEx_Release(dispex
);
928 hres
= IDispatch_Invoke(V_DISPATCH(var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
930 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
932 heap_free(dp
.rgvarg
);
935 case DISPATCH_PROPERTYGET
:
936 return VariantCopy(pvarRes
, var
);
937 case DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
:
938 case DISPATCH_PROPERTYPUT
:
939 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
940 || pdp
->cNamedArgs
> 1) {
941 FIXME("invalid args\n");
945 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
947 return VariantCopy(var
, pdp
->rgvarg
);
949 FIXME("unhandled wFlags %x\n", wFlags
);
954 data
= get_dispex_data(This
);
958 hres
= get_builtin_func(data
, id
, &func
);
959 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
960 return dispex_value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
964 if(func
->func_disp_idx
== -1)
965 hres
= typeinfo_invoke(This
, func
, wFlags
, pdp
, pvarRes
, pei
);
967 hres
= function_invoke(This
, func
, wFlags
, pdp
, pvarRes
, pei
);
972 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
974 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
975 FIXME("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
979 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
981 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
982 FIXME("(%p)->(%x)\n", This
, id
);
986 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
988 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
989 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
993 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
995 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1000 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1002 if(is_dynamic_dispid(id
)) {
1003 DWORD idx
= id
- DISPID_DYNPROP_0
;
1005 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1006 return DISP_E_UNKNOWNNAME
;
1008 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1010 return E_OUTOFMEMORY
;
1015 data
= get_dispex_data(This
);
1019 hres
= get_builtin_func(data
, id
, &func
);
1023 *pbstrName
= SysAllocString(func
->name
);
1025 return E_OUTOFMEMORY
;
1029 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1031 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1032 dispex_data_t
*data
;
1036 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1038 if(is_dynamic_dispid(id
)) {
1039 DWORD idx
= id
- DISPID_DYNPROP_0
;
1041 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1042 return DISP_E_UNKNOWNNAME
;
1044 if(idx
+1 == This
->dynamic_data
->prop_cnt
) {
1045 *pid
= DISPID_STARTENUM
;
1053 data
= get_dispex_data(This
);
1057 if(id
== DISPID_STARTENUM
) {
1060 hres
= get_builtin_func(data
, id
, &func
);
1066 while(func
< data
->funcs
+data
->func_cnt
) {
1067 /* FIXME: Skip hidden properties */
1068 if(func
->func_disp_idx
== -1) {
1075 if(This
->dynamic_data
&& This
->dynamic_data
->prop_cnt
) {
1076 *pid
= DISPID_DYNPROP_0
;
1080 *pid
= DISPID_STARTENUM
;
1084 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1086 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
1087 FIXME("(%p)->(%p)\n", This
, ppunk
);
1091 #undef DISPATCHEX_THIS
1093 static IDispatchExVtbl DispatchExVtbl
= {
1094 DispatchEx_QueryInterface
,
1097 DispatchEx_GetTypeInfoCount
,
1098 DispatchEx_GetTypeInfo
,
1099 DispatchEx_GetIDsOfNames
,
1101 DispatchEx_GetDispID
,
1102 DispatchEx_InvokeEx
,
1103 DispatchEx_DeleteMemberByName
,
1104 DispatchEx_DeleteMemberByDispID
,
1105 DispatchEx_GetMemberProperties
,
1106 DispatchEx_GetMemberName
,
1107 DispatchEx_GetNextDispID
,
1108 DispatchEx_GetNameSpaceParent
1111 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1113 static const IID IID_UndocumentedScriptIface
=
1114 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1115 static const IID IID_IDispatchJS
=
1116 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1118 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1119 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1120 *ppv
= DISPATCHEX(This
);
1121 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1122 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1123 *ppv
= DISPATCHEX(This
);
1124 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
1125 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
1127 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
1128 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
1135 IUnknown_AddRef((IUnknown
*)*ppv
);
1139 void release_dispex(DispatchEx
*This
)
1141 dynamic_prop_t
*prop
;
1143 if(!This
->dynamic_data
)
1146 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1147 VariantClear(&prop
->var
);
1148 heap_free(prop
->name
);
1151 heap_free(This
->dynamic_data
->props
);
1153 if(This
->dynamic_data
->func_disps
) {
1156 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
1157 if(This
->dynamic_data
->func_disps
[i
]) {
1158 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
1159 heap_free(This
->dynamic_data
->func_disps
[i
]);
1163 heap_free(This
->dynamic_data
->func_disps
);
1166 heap_free(This
->dynamic_data
);
1169 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1171 dispex
->lpIDispatchExVtbl
= &DispatchExVtbl
;
1172 dispex
->outer
= outer
;
1173 dispex
->data
= data
;
1174 dispex
->dynamic_data
= NULL
;