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
], &ti
);
113 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
117 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
118 ITypeInfo_Release(ti
);
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 static inline BOOL
is_custom_dispid(DISPID id
)
329 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
332 static inline BOOL
is_dynamic_dispid(DISPID id
)
334 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
337 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
339 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
340 V_VT(dest
) = VT_BSTR
;
345 return VariantCopy(dest
, src
);
348 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
, BOOL alloc
)
350 return !alloc
|| This
->dynamic_data
352 : (This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
)));
355 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
357 const BOOL alloc
= flags
& fdexNameEnsure
;
358 dispex_dynamic_data_t
*data
;
359 dynamic_prop_t
*prop
;
361 data
= get_dynamic_data(This
, alloc
);
364 return E_OUTOFMEMORY
;
366 TRACE("not found %s\n", debugstr_w(name
));
367 return DISP_E_UNKNOWNNAME
;
370 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
371 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
372 if(prop
->flags
& DYNPROP_DELETED
) {
374 return DISP_E_UNKNOWNNAME
;
375 prop
->flags
&= ~DYNPROP_DELETED
;
383 return DISP_E_UNKNOWNNAME
;
385 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
387 if(!data
->buf_size
) {
388 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
390 return E_OUTOFMEMORY
;
392 }else if(data
->buf_size
== data
->prop_cnt
) {
393 dynamic_prop_t
*new_props
;
395 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
397 return E_OUTOFMEMORY
;
399 data
->props
= new_props
;
400 data
->buf_size
<<= 1;
403 prop
= data
->props
+ data
->prop_cnt
;
405 prop
->name
= heap_strdupW(name
);
407 return E_OUTOFMEMORY
;
409 VariantInit(&prop
->var
);
416 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
418 dynamic_prop_t
*prop
;
421 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
429 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
430 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
432 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
433 return This
->data
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
436 case DISPATCH_PROPERTYGET
:
438 V_BSTR(res
) = SysAllocString(objectW
);
440 return E_OUTOFMEMORY
;
443 FIXME("Unimplemented flags %x\n", flags
);
450 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
458 hres
= get_typeinfo(func
->tid
, &ti
);
460 ERR("Could not get type info: %08x\n", hres
);
464 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
466 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids
[func
->tid
]), hres
);
470 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, dp
, res
, ei
, &argerr
);
472 IUnknown_Release(unk
);
476 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
478 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
481 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
483 func_disp_t
*This
= impl_from_IUnknown(iface
);
485 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
486 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
487 *ppv
= &This
->IUnknown_iface
;
488 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
489 return *ppv
? S_OK
: E_NOINTERFACE
;
492 return E_NOINTERFACE
;
495 IUnknown_AddRef((IUnknown
*)*ppv
);
499 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
501 func_disp_t
*This
= impl_from_IUnknown(iface
);
503 TRACE("(%p)\n", This
);
505 return IDispatchEx_AddRef(&This
->obj
->IDispatchEx_iface
);
508 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
510 func_disp_t
*This
= impl_from_IUnknown(iface
);
512 TRACE("(%p)\n", This
);
514 return IDispatchEx_Release(&This
->obj
->IDispatchEx_iface
);
517 static const IUnknownVtbl FunctionUnkVtbl
= {
518 Function_QueryInterface
,
523 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
525 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
528 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
529 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
531 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
535 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
538 case DISPATCH_METHOD
:
539 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
542 FIXME("Unimplemented flags %x\n", flags
);
549 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
555 static const tid_t function_iface_tids
[] = {0};
557 static dispex_static_data_t function_dispex
= {
558 &function_dispex_vtbl
,
564 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
568 ret
= heap_alloc_zero(sizeof(func_disp_t
));
572 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
573 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
580 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
586 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
589 case DISPATCH_METHOD
:
590 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
592 case DISPATCH_PROPERTYGET
: {
593 dispex_dynamic_data_t
*dynamic_data
;
595 if(func
->id
== DISPID_VALUE
) {
598 ret
= SysAllocString(objectW
);
600 return E_OUTOFMEMORY
;
607 dynamic_data
= get_dynamic_data(This
, TRUE
);
609 return E_OUTOFMEMORY
;
611 if(!dynamic_data
->func_disps
) {
612 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(func_disp_t
*));
613 if(!dynamic_data
->func_disps
)
614 return E_OUTOFMEMORY
;
617 if(!dynamic_data
->func_disps
[func
->func_disp_idx
]) {
618 dynamic_data
->func_disps
[func
->func_disp_idx
] = create_func_disp(This
, func
);
619 if(!dynamic_data
->func_disps
[func
->func_disp_idx
])
620 return E_OUTOFMEMORY
;
623 V_VT(res
) = VT_DISPATCH
;
624 V_DISPATCH(res
) = (IDispatch
*)&dynamic_data
->func_disps
[func
->func_disp_idx
]->dispex
.IDispatchEx_iface
;
625 IDispatch_AddRef(V_DISPATCH(res
));
630 FIXME("Unimplemented flags %x\n", flags
);
631 case DISPATCH_PROPERTYPUT
:
638 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
643 max
= data
->func_cnt
-1;
648 if(data
->funcs
[n
].id
== id
) {
649 *ret
= data
->funcs
+n
;
653 if(data
->funcs
[n
].id
< id
)
659 WARN("invalid id %x\n", id
);
660 return DISP_E_UNKNOWNNAME
;
663 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
668 data
= get_dispex_data(This
);
673 max
= data
->func_cnt
-1;
678 c
= strcmpiW(data
->name_table
[n
]->name
, name
);
680 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, name
))
683 *ret
= data
->name_table
[n
]->id
;
693 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
696 hres
= This
->data
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
697 if(hres
!= DISP_E_UNKNOWNNAME
)
701 return DISP_E_UNKNOWNNAME
;
704 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
705 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
711 data
= get_dispex_data(This
);
715 hres
= get_builtin_func(data
, id
, &func
);
716 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
717 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
721 if(func
->func_disp_idx
== -1)
722 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
724 hres
= function_invoke(This
, func
, flags
, dp
, res
, ei
);
729 HRESULT
remove_prop(DispatchEx
*This
, BSTR name
, VARIANT_BOOL
*success
)
731 dynamic_prop_t
*prop
;
735 hres
= get_builtin_id(This
, name
, 0, &id
);
737 DISPID named_id
= DISPID_PROPERTYPUT
;
739 DISPPARAMS dp
= {&var
,&named_id
,1,1};
742 V_VT(&var
) = VT_EMPTY
;
743 memset(&ei
, 0, sizeof(ei
));
744 hres
= invoke_builtin_prop(This
, id
, 0, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
748 *success
= VARIANT_TRUE
;
752 hres
= get_dynamic_prop(This
, name
, 0, &prop
);
754 if(hres
!= DISP_E_UNKNOWNNAME
)
756 *success
= VARIANT_FALSE
;
760 VariantClear(&prop
->var
);
761 prop
->flags
|= DYNPROP_DELETED
;
762 *success
= VARIANT_TRUE
;
766 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
768 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
771 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
773 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
775 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
778 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
780 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
782 return IUnknown_AddRef(This
->outer
);
785 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
787 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
789 return IUnknown_Release(This
->outer
);
792 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
794 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
796 TRACE("(%p)->(%p)\n", This
, pctinfo
);
802 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
803 LCID lcid
, ITypeInfo
**ppTInfo
)
805 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
808 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
810 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
814 ITypeInfo_AddRef(*ppTInfo
);
818 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
819 LPOLESTR
*rgszNames
, UINT cNames
,
820 LCID lcid
, DISPID
*rgDispId
)
822 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
826 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
829 for(i
=0; i
< cNames
; i
++) {
830 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
838 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
839 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
840 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
842 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
844 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
845 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
847 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
848 pVarResult
, pExcepInfo
, NULL
);
851 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
853 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
854 dynamic_prop_t
*dprop
;
857 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
859 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
860 FIXME("Unsupported grfdex %x\n", grfdex
);
862 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
863 if(hres
!= DISP_E_UNKNOWNNAME
)
866 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
870 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
874 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
875 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
877 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
880 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
882 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
883 return This
->data
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
885 if(wFlags
== DISPATCH_CONSTRUCT
) {
886 if(id
== DISPID_VALUE
) {
887 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
888 return This
->data
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
890 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
893 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
897 if(is_dynamic_dispid(id
)) {
898 DWORD idx
= id
- DISPID_DYNPROP_0
;
899 dynamic_prop_t
*prop
;
901 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
902 return DISP_E_UNKNOWNNAME
;
904 prop
= This
->dynamic_data
->props
+idx
;
907 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
910 case DISPATCH_METHOD
: {
911 DISPID named_arg
= DISPID_THIS
;
912 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
915 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
916 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
920 if(pdp
->cNamedArgs
) {
921 FIXME("named args not supported\n");
925 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
927 return E_OUTOFMEMORY
;
929 dp
.cArgs
= pdp
->cArgs
+1;
930 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
932 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
933 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
935 hres
= IDispatch_QueryInterface(V_DISPATCH(&prop
->var
), &IID_IDispatchEx
, (void**)&dispex
);
936 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
937 if(SUCCEEDED(hres
)) {
938 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
939 IDispatchEx_Release(dispex
);
942 hres
= IDispatch_Invoke(V_DISPATCH(&prop
->var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
944 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
946 heap_free(dp
.rgvarg
);
949 case DISPATCH_PROPERTYGET
:
950 if(prop
->flags
& DYNPROP_DELETED
)
951 return DISP_E_UNKNOWNNAME
;
952 return variant_copy(pvarRes
, &prop
->var
);
953 case DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
:
954 case DISPATCH_PROPERTYPUT
:
955 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
956 || pdp
->cNamedArgs
> 1) {
957 FIXME("invalid args\n");
961 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
962 VariantClear(&prop
->var
);
963 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
967 prop
->flags
&= ~DYNPROP_DELETED
;
970 FIXME("unhandled wFlags %x\n", wFlags
);
975 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
978 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
980 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
982 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
984 /* Not implemented by IE */
988 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
990 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
991 FIXME("(%p)->(%x)\n", This
, id
);
995 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
997 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
998 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1002 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1004 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1005 dispex_data_t
*data
;
1009 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1011 if(is_dynamic_dispid(id
)) {
1012 DWORD idx
= id
- DISPID_DYNPROP_0
;
1014 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1015 return DISP_E_UNKNOWNNAME
;
1017 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1019 return E_OUTOFMEMORY
;
1024 data
= get_dispex_data(This
);
1028 hres
= get_builtin_func(data
, id
, &func
);
1032 *pbstrName
= SysAllocString(func
->name
);
1034 return E_OUTOFMEMORY
;
1038 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1040 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1041 dispex_data_t
*data
;
1045 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1047 if(is_dynamic_dispid(id
)) {
1048 DWORD idx
= id
- DISPID_DYNPROP_0
;
1050 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
1051 return DISP_E_UNKNOWNNAME
;
1053 while(++idx
< This
->dynamic_data
->prop_cnt
&& This
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
);
1055 if(idx
== This
->dynamic_data
->prop_cnt
) {
1056 *pid
= DISPID_STARTENUM
;
1060 *pid
= DISPID_DYNPROP_0
+idx
;
1064 data
= get_dispex_data(This
);
1068 if(id
== DISPID_STARTENUM
) {
1071 hres
= get_builtin_func(data
, id
, &func
);
1077 while(func
< data
->funcs
+data
->func_cnt
) {
1078 /* FIXME: Skip hidden properties */
1079 if(func
->func_disp_idx
== -1) {
1086 if(This
->dynamic_data
&& This
->dynamic_data
->prop_cnt
) {
1087 *pid
= DISPID_DYNPROP_0
;
1091 *pid
= DISPID_STARTENUM
;
1095 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1097 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1098 FIXME("(%p)->(%p)\n", This
, ppunk
);
1102 static IDispatchExVtbl DispatchExVtbl
= {
1103 DispatchEx_QueryInterface
,
1106 DispatchEx_GetTypeInfoCount
,
1107 DispatchEx_GetTypeInfo
,
1108 DispatchEx_GetIDsOfNames
,
1110 DispatchEx_GetDispID
,
1111 DispatchEx_InvokeEx
,
1112 DispatchEx_DeleteMemberByName
,
1113 DispatchEx_DeleteMemberByDispID
,
1114 DispatchEx_GetMemberProperties
,
1115 DispatchEx_GetMemberName
,
1116 DispatchEx_GetNextDispID
,
1117 DispatchEx_GetNameSpaceParent
1120 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1122 static const IID IID_UndocumentedScriptIface
=
1123 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1124 static const IID IID_IDispatchJS
=
1125 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1127 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1128 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1129 *ppv
= &This
->IDispatchEx_iface
;
1130 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1131 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1132 *ppv
= &This
->IDispatchEx_iface
;
1133 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
1134 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
1136 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
1137 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
1144 IUnknown_AddRef((IUnknown
*)*ppv
);
1148 void release_dispex(DispatchEx
*This
)
1150 dynamic_prop_t
*prop
;
1152 if(!This
->dynamic_data
)
1155 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1156 VariantClear(&prop
->var
);
1157 heap_free(prop
->name
);
1160 heap_free(This
->dynamic_data
->props
);
1162 if(This
->dynamic_data
->func_disps
) {
1165 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
1166 if(This
->dynamic_data
->func_disps
[i
]) {
1167 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
1168 heap_free(This
->dynamic_data
->func_disps
[i
]);
1172 heap_free(This
->dynamic_data
->func_disps
);
1175 heap_free(This
->dynamic_data
);
1178 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1180 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1181 dispex
->outer
= outer
;
1182 dispex
->data
= data
;
1183 dispex
->dynamic_data
= NULL
;