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
23 #define NONAMELESSUNION
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
39 static CRITICAL_SECTION cs_dispex_static_data
;
40 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
42 0, 0, &cs_dispex_static_data
,
43 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
44 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
46 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
49 static const WCHAR objectW
[] = {'[','o','b','j','e','c','t',']',0};
55 dispex_hook_invoke_t hook
;
65 struct dispex_data_t
{
66 dispex_static_data_t
*desc
;
71 func_info_t
**name_table
;
83 #define DYNPROP_DELETED 0x01
87 IUnknown IUnknown_iface
;
94 func_disp_t
*func_obj
;
98 struct dispex_dynamic_data_t
{
101 dynamic_prop_t
*props
;
102 func_obj_entry_t
*func_disps
;
105 #define DISPID_DYNPROP_0 0x50000000
106 #define DISPID_DYNPROP_MAX 0x5fffffff
108 #define FDEX_VERSION_MASK 0xf0000000
110 static ITypeLib
*typelib
;
111 static ITypeInfo
*typeinfos
[LAST_tid
];
112 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
114 static REFIID tid_ids
[] = {
115 #define XIID(iface) &IID_ ## iface,
116 #define XDIID(iface) &DIID_ ## iface,
122 static HRESULT
load_typelib(void)
127 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
129 ERR("LoadRegTypeLib failed: %08x\n", hres
);
133 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
134 ITypeLib_Release(tl
);
138 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
143 hres
= load_typelib();
147 if(!typeinfos
[tid
]) {
150 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
152 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_mshtml_guid(tid_ids
[tid
]), hres
);
156 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
157 ITypeInfo_Release(ti
);
160 *typeinfo
= typeinfos
[tid
];
164 void release_typelib(void)
169 while(!list_empty(&dispex_data_list
)) {
170 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
171 list_remove(&iter
->entry
);
173 for(i
=0; i
< iter
->func_cnt
; i
++)
174 SysFreeString(iter
->funcs
[i
].name
);
176 heap_free(iter
->funcs
);
177 heap_free(iter
->name_table
);
184 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
186 ITypeInfo_Release(typeinfos
[i
]);
188 ITypeLib_Release(typelib
);
189 DeleteCriticalSection(&cs_dispex_static_data
);
192 HRESULT
get_class_typeinfo(const CLSID
*clsid
, ITypeInfo
**typeinfo
)
197 hres
= load_typelib();
201 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, clsid
, typeinfo
);
203 ERR("GetTypeInfoOfGuid failed: %08x\n", hres
);
207 /* Not all argument types are supported yet */
208 #define BUILTIN_ARG_TYPES_SWITCH \
209 CASE_VT(VT_I2, INT16, V_I2); \
210 CASE_VT(VT_UI2, UINT16, V_UI2); \
211 CASE_VT(VT_I4, INT32, V_I4); \
212 CASE_VT(VT_R4, float, V_R4); \
213 CASE_VT(VT_BSTR, BSTR, V_BSTR); \
214 CASE_VT(VT_BOOL, VARIANT_BOOL, V_BOOL)
216 /* List all types used by IDispatchEx-based properties */
217 #define BUILTIN_TYPES_SWITCH \
218 BUILTIN_ARG_TYPES_SWITCH; \
219 CASE_VT(VT_VARIANT, VARIANT, *); \
220 CASE_VT(VT_PTR, void*, V_BYREF); \
221 CASE_VT(VT_UNKNOWN, IUnknown*, V_UNKNOWN); \
222 CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH); \
223 CASE_VT(VT_UI8, ULONGLONG, V_UI8)
225 static BOOL
is_arg_type_supported(VARTYPE vt
)
228 #define CASE_VT(x,a,b) case x: return TRUE
229 BUILTIN_ARG_TYPES_SWITCH
;
235 static void add_func_info(dispex_data_t
*data
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
,
236 dispex_hook_invoke_t hook
)
242 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &name
, NULL
, NULL
, NULL
);
246 for(info
= data
->funcs
; info
< data
->funcs
+data
->func_cnt
; info
++) {
247 if(info
->id
== desc
->memid
|| !strcmpW(info
->name
, name
)) {
248 if(info
->tid
!= tid
) {
250 return; /* Duplicated in other interface */
256 if(info
== data
->funcs
+data
->func_cnt
) {
257 if(data
->func_cnt
== data
->func_size
)
258 data
->funcs
= heap_realloc_zero(data
->funcs
, (data
->func_size
<<= 1)*sizeof(func_info_t
));
259 info
= data
->funcs
+data
->func_cnt
;
263 info
->id
= desc
->memid
;
266 info
->func_disp_idx
= -1;
267 info
->prop_vt
= VT_EMPTY
;
273 if(desc
->invkind
& DISPATCH_METHOD
) {
276 info
->func_disp_idx
= data
->func_disp_cnt
++;
277 info
->argc
= desc
->cParams
;
279 assert(info
->argc
< MAX_ARGS
);
280 assert(desc
->funckind
== FUNC_DISPATCH
);
282 info
->arg_types
= heap_alloc(sizeof(*info
->arg_types
) * info
->argc
);
284 return; /* FIXME: real error instead of fallback */
286 for(i
=0; i
< info
->argc
; i
++)
287 info
->arg_types
[i
] = desc
->lprgelemdescParam
[i
].tdesc
.vt
;
289 info
->prop_vt
= desc
->elemdescFunc
.tdesc
.vt
;
290 if(info
->prop_vt
!= VT_VOID
&& !is_arg_type_supported(info
->prop_vt
)) {
291 TRACE("%s: return type %d\n", debugstr_w(info
->name
), info
->prop_vt
);
292 return; /* Fallback to ITypeInfo::Invoke */
295 if(desc
->cParamsOpt
) {
296 TRACE("%s: optional params\n", debugstr_w(info
->name
));
297 return; /* Fallback to ITypeInfo::Invoke */
300 for(i
=0; i
< info
->argc
; i
++) {
301 if(!is_arg_type_supported(info
->arg_types
[i
])) {
302 return; /* Fallback to ITypeInfo for unsupported arg types */
305 if(desc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
306 TRACE("%s param %d: default value\n", debugstr_w(info
->name
), i
);
307 return; /* Fallback to ITypeInfo::Invoke */
311 assert(info
->argc
<= MAX_ARGS
);
312 assert(desc
->callconv
== CC_STDCALL
);
314 info
->call_vtbl_off
= desc
->oVft
/sizeof(void*);
315 }else if(desc
->invkind
& (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYGET
)) {
316 VARTYPE vt
= VT_EMPTY
;
318 if(desc
->invkind
& DISPATCH_PROPERTYGET
) {
319 vt
= desc
->elemdescFunc
.tdesc
.vt
;
320 info
->get_vtbl_off
= desc
->oVft
/sizeof(void*);
322 if(desc
->invkind
& DISPATCH_PROPERTYPUT
) {
323 assert(desc
->cParams
== 1);
324 vt
= desc
->lprgelemdescParam
->tdesc
.vt
;
325 info
->put_vtbl_off
= desc
->oVft
/sizeof(void*);
328 assert(info
->prop_vt
== VT_EMPTY
|| vt
== info
->prop_vt
);
333 static HRESULT
process_interface(dispex_data_t
*data
, tid_t tid
, ITypeInfo
*disp_typeinfo
, const dispex_hook_t
*hooks
)
335 unsigned i
= 7; /* skip IDispatch functions */
340 hres
= get_typeinfo(tid
, &typeinfo
);
345 const dispex_hook_t
*hook
= NULL
;
347 hres
= ITypeInfo_GetFuncDesc(typeinfo
, i
++, &funcdesc
);
352 for(hook
= hooks
; hook
->dispid
!= DISPID_UNKNOWN
; hook
++) {
353 if(hook
->dispid
== funcdesc
->memid
)
356 if(hook
->dispid
== DISPID_UNKNOWN
)
360 if(!hook
|| hook
->invoke
) {
361 TRACE("adding...\n");
362 add_func_info(data
, tid
, funcdesc
, disp_typeinfo
? disp_typeinfo
: typeinfo
,
363 hook
? hook
->invoke
: NULL
);
366 ITypeInfo_ReleaseFuncDesc(typeinfo
, funcdesc
);
372 void dispex_info_add_interface(dispex_data_t
*info
, tid_t tid
, const dispex_hook_t
*hooks
)
376 hres
= process_interface(info
, tid
, NULL
, hooks
);
378 ERR("process_interface failed: %08x\n", hres
);
381 static int dispid_cmp(const void *p1
, const void *p2
)
383 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
386 static int func_name_cmp(const void *p1
, const void *p2
)
388 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
391 static dispex_data_t
*preprocess_dispex_data(dispex_static_data_t
*desc
, compat_mode_t compat_mode
)
400 hres
= get_typeinfo(desc
->disp_tid
, &dti
);
402 ERR("Could not get disp type info: %08x\n", hres
);
407 data
= heap_alloc(sizeof(dispex_data_t
));
409 ERR("Out of memory\n");
414 data
->func_disp_cnt
= 0;
415 data
->func_size
= 16;
416 data
->funcs
= heap_alloc_zero(data
->func_size
*sizeof(func_info_t
));
419 ERR("Out of memory\n");
422 list_add_tail(&dispex_data_list
, &data
->entry
);
425 desc
->init_info(data
, compat_mode
);
427 for(tid
= desc
->iface_tids
; *tid
; tid
++) {
428 hres
= process_interface(data
, *tid
, dti
, NULL
);
433 if(!data
->func_cnt
) {
434 heap_free(data
->funcs
);
435 data
->name_table
= NULL
;
442 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
443 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
445 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
446 for(i
=0; i
< data
->func_cnt
; i
++)
447 data
->name_table
[i
] = data
->funcs
+i
;
448 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
452 static int id_cmp(const void *p1
, const void *p2
)
454 return *(const DISPID
*)p1
- *(const DISPID
*)p2
;
457 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
459 unsigned i
, func_cnt
;
466 hres
= get_typeinfo(tid
, &ti
);
470 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
472 ITypeInfo_Release(ti
);
476 func_cnt
= attr
->cFuncs
;
477 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
479 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
481 ITypeInfo_Release(ti
);
482 return E_OUTOFMEMORY
;
485 for(i
=0; i
< func_cnt
; i
++) {
486 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
490 ids
[i
] = funcdesc
->memid
;
491 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
494 ITypeInfo_Release(ti
);
500 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
502 *ret_size
= func_cnt
;
507 static inline BOOL
is_custom_dispid(DISPID id
)
509 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
512 static inline BOOL
is_dynamic_dispid(DISPID id
)
514 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
517 dispex_prop_type_t
get_dispid_type(DISPID id
)
519 if(is_dynamic_dispid(id
))
520 return DISPEXPROP_DYNAMIC
;
521 if(is_custom_dispid(id
))
522 return DISPEXPROP_CUSTOM
;
523 return DISPEXPROP_BUILTIN
;
526 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
528 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
529 V_VT(dest
) = VT_BSTR
;
534 return VariantCopy(dest
, src
);
537 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
)
539 if(This
->dynamic_data
)
540 return This
->dynamic_data
;
542 This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
));
543 if(!This
->dynamic_data
)
546 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->populate_props
)
547 This
->info
->desc
->vtbl
->populate_props(This
);
549 return This
->dynamic_data
;
552 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
554 const BOOL alloc
= flags
& fdexNameEnsure
;
555 dispex_dynamic_data_t
*data
;
556 dynamic_prop_t
*prop
;
558 data
= get_dynamic_data(This
);
560 return E_OUTOFMEMORY
;
562 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
563 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
564 if(prop
->flags
& DYNPROP_DELETED
) {
566 return DISP_E_UNKNOWNNAME
;
567 prop
->flags
&= ~DYNPROP_DELETED
;
575 return DISP_E_UNKNOWNNAME
;
577 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
579 if(!data
->buf_size
) {
580 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
582 return E_OUTOFMEMORY
;
584 }else if(data
->buf_size
== data
->prop_cnt
) {
585 dynamic_prop_t
*new_props
;
587 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
589 return E_OUTOFMEMORY
;
591 data
->props
= new_props
;
592 data
->buf_size
<<= 1;
595 prop
= data
->props
+ data
->prop_cnt
;
597 prop
->name
= heap_strdupW(name
);
599 return E_OUTOFMEMORY
;
601 VariantInit(&prop
->var
);
608 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
610 dynamic_prop_t
*prop
;
613 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
621 HRESULT
dispex_get_dynid(DispatchEx
*This
, const WCHAR
*name
, DISPID
*id
)
623 dynamic_prop_t
*prop
;
626 hres
= get_dynamic_prop(This
, name
, fdexNameEnsure
, &prop
);
630 *id
= DISPID_DYNPROP_0
+ (prop
- This
->dynamic_data
->props
);
634 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
635 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
637 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->value
)
638 return This
->info
->desc
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
641 case DISPATCH_PROPERTYGET
:
643 V_BSTR(res
) = SysAllocString(objectW
);
645 return E_OUTOFMEMORY
;
648 FIXME("Unimplemented flags %x\n", flags
);
655 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
658 DISPPARAMS params
= {dp
->rgvarg
+dp
->cNamedArgs
, NULL
, dp
->cArgs
-dp
->cNamedArgs
, 0};
664 hres
= get_typeinfo(func
->tid
, &ti
);
666 ERR("Could not get type info: %08x\n", hres
);
670 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
672 ERR("Could not get iface %s: %08x\n", debugstr_mshtml_guid(tid_ids
[func
->tid
]), hres
);
676 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, ¶ms
, res
, ei
, &argerr
);
678 IUnknown_Release(unk
);
682 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
684 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
687 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
689 func_disp_t
*This
= impl_from_IUnknown(iface
);
691 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
693 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
694 *ppv
= &This
->IUnknown_iface
;
695 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
696 return *ppv
? S_OK
: E_NOINTERFACE
;
699 return E_NOINTERFACE
;
702 IUnknown_AddRef((IUnknown
*)*ppv
);
706 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
708 func_disp_t
*This
= impl_from_IUnknown(iface
);
709 LONG ref
= InterlockedIncrement(&This
->ref
);
711 TRACE("(%p) ref=%d\n", This
, ref
);
716 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
718 func_disp_t
*This
= impl_from_IUnknown(iface
);
719 LONG ref
= InterlockedDecrement(&This
->ref
);
721 TRACE("(%p) ref=%d\n", This
, ref
);
725 release_dispex(&This
->dispex
);
732 static const IUnknownVtbl FunctionUnkVtbl
= {
733 Function_QueryInterface
,
738 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
740 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
743 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
744 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
746 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
750 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
754 case DISPATCH_METHOD
:
757 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
759 case DISPATCH_PROPERTYGET
: {
764 static const WCHAR func_prefixW
[] =
765 {'\n','f','u','n','c','t','i','o','n',' '};
766 static const WCHAR func_suffixW
[] =
767 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
769 /* FIXME: This probably should be more generic. Also we should try to get IID_IActiveScriptSite and SID_GetCaller. */
771 return E_ACCESSDENIED
;
773 name_len
= SysStringLen(This
->info
->name
);
774 ptr
= str
= SysAllocStringLen(NULL
, name_len
+ (sizeof(func_prefixW
)+sizeof(func_suffixW
))/sizeof(WCHAR
));
776 return E_OUTOFMEMORY
;
778 memcpy(ptr
, func_prefixW
, sizeof(func_prefixW
));
779 ptr
+= sizeof(func_prefixW
)/sizeof(WCHAR
);
781 memcpy(ptr
, This
->info
->name
, name_len
*sizeof(WCHAR
));
784 memcpy(ptr
, func_suffixW
, sizeof(func_suffixW
));
791 FIXME("Unimplemented flags %x\n", flags
);
798 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
805 static const tid_t function_iface_tids
[] = {0};
807 static dispex_static_data_t function_dispex
= {
808 &function_dispex_vtbl
,
813 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
817 ret
= heap_alloc_zero(sizeof(func_disp_t
));
821 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
822 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
830 static HRESULT
invoke_disp_value(DispatchEx
*This
, IDispatch
*func_disp
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
831 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
833 DISPID named_arg
= DISPID_THIS
;
834 DISPPARAMS new_dp
= {NULL
, &named_arg
, 0, 1};
839 FIXME("named args not supported\n");
843 new_dp
.rgvarg
= heap_alloc((dp
->cArgs
+1)*sizeof(VARIANTARG
));
845 return E_OUTOFMEMORY
;
847 new_dp
.cArgs
= dp
->cArgs
+1;
848 memcpy(new_dp
.rgvarg
+1, dp
->rgvarg
, dp
->cArgs
*sizeof(VARIANTARG
));
850 V_VT(new_dp
.rgvarg
) = VT_DISPATCH
;
851 V_DISPATCH(new_dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
853 hres
= IDispatch_QueryInterface(func_disp
, &IID_IDispatchEx
, (void**)&dispex
);
855 if(SUCCEEDED(hres
)) {
856 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, flags
, &new_dp
, res
, ei
, caller
);
857 IDispatchEx_Release(dispex
);
860 hres
= IDispatch_Invoke(func_disp
, DISPID_VALUE
, &IID_NULL
, lcid
, flags
, &new_dp
, res
, ei
, &err
);
863 TRACE("<<< %s\n", debugstr_variant(res
));
865 WARN("<<< %08x\n", hres
);
867 heap_free(new_dp
.rgvarg
);
871 static HRESULT
get_func_obj_entry(DispatchEx
*This
, func_info_t
*func
, func_obj_entry_t
**ret
)
873 dispex_dynamic_data_t
*dynamic_data
;
874 func_obj_entry_t
*entry
;
876 dynamic_data
= get_dynamic_data(This
);
878 return E_OUTOFMEMORY
;
880 if(!dynamic_data
->func_disps
) {
881 dynamic_data
->func_disps
= heap_alloc_zero(This
->info
->func_disp_cnt
* sizeof(*dynamic_data
->func_disps
));
882 if(!dynamic_data
->func_disps
)
883 return E_OUTOFMEMORY
;
886 entry
= dynamic_data
->func_disps
+ func
->func_disp_idx
;
887 if(!entry
->func_obj
) {
888 entry
->func_obj
= create_func_disp(This
, func
);
890 return E_OUTOFMEMORY
;
892 IDispatchEx_AddRef(&entry
->func_obj
->dispex
.IDispatchEx_iface
);
893 V_VT(&entry
->val
) = VT_DISPATCH
;
894 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
901 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
906 max
= data
->func_cnt
-1;
911 if(data
->funcs
[n
].id
== id
) {
912 *ret
= data
->funcs
+n
;
916 if(data
->funcs
[n
].id
< id
)
922 WARN("invalid id %x\n", id
);
923 return DISP_E_UNKNOWNNAME
;
926 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
931 max
= This
->info
->func_cnt
-1;
936 c
= strcmpiW(This
->info
->name_table
[n
]->name
, name
);
938 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(This
->info
->name_table
[n
]->name
, name
))
941 *ret
= This
->info
->name_table
[n
]->id
;
951 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->get_dispid
) {
954 hres
= This
->info
->desc
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
955 if(hres
!= DISP_E_UNKNOWNNAME
)
959 return DISP_E_UNKNOWNNAME
;
962 static HRESULT
change_type(VARIANT
*dst
, VARIANT
*src
, VARTYPE vt
, IServiceProvider
*caller
)
964 V_VT(dst
) = VT_EMPTY
;
967 IVariantChangeType
*change_type
= NULL
;
970 hres
= IServiceProvider_QueryService(caller
, &SID_VariantConversion
, &IID_IVariantChangeType
, (void**)&change_type
);
971 if(SUCCEEDED(hres
)) {
972 hres
= IVariantChangeType_ChangeType(change_type
, dst
, src
, LOCALE_NEUTRAL
, vt
);
973 IVariantChangeType_Release(change_type
);
980 if(V_VT(src
) == VT_BSTR
) {
982 V_BOOL(dst
) = variant_bool(V_BSTR(src
) && *V_BSTR(src
));
988 return VariantChangeType(dst
, src
, 0, vt
);
991 static HRESULT
builtin_propget(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
)
996 if(dp
&& dp
->cArgs
) {
997 FIXME("cArgs %d\n", dp
->cArgs
);
1001 assert(func
->get_vtbl_off
);
1003 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1004 if(SUCCEEDED(hres
)) {
1005 switch(func
->prop_vt
) {
1006 #define CASE_VT(vt,type,access) \
1009 hres = ((HRESULT (WINAPI*)(IUnknown*,type*))((void**)iface->lpVtbl)[func->get_vtbl_off])(iface,&val); \
1010 if(SUCCEEDED(hres)) \
1011 access(res) = val; \
1014 BUILTIN_TYPES_SWITCH
;
1017 FIXME("Unhandled vt %d\n", func
->prop_vt
);
1020 IUnknown_Release(iface
);
1026 if(func
->prop_vt
!= VT_VARIANT
)
1027 V_VT(res
) = func
->prop_vt
== VT_PTR
? VT_DISPATCH
: func
->prop_vt
;
1031 static HRESULT
builtin_propput(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, IServiceProvider
*caller
)
1037 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1038 || dp
->cNamedArgs
> 1) {
1039 FIXME("invalid args\n");
1040 return E_INVALIDARG
;
1043 if(!func
->put_vtbl_off
) {
1044 FIXME("No setter\n");
1049 if(func
->prop_vt
!= VT_VARIANT
&& V_VT(v
) != func
->prop_vt
) {
1050 hres
= change_type(&tmpv
, v
, func
->prop_vt
, caller
);
1056 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1057 if(SUCCEEDED(hres
)) {
1058 switch(func
->prop_vt
) {
1059 #define CASE_VT(vt,type,access) \
1061 hres = ((HRESULT (WINAPI*)(IUnknown*,type))((void**)iface->lpVtbl)[func->put_vtbl_off])(iface,access(v)); \
1063 BUILTIN_TYPES_SWITCH
;
1066 FIXME("Unimplemented vt %d\n", func
->prop_vt
);
1070 IUnknown_Release(iface
);
1078 static HRESULT
invoke_builtin_function(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
, IServiceProvider
*caller
)
1080 VARIANT arg_buf
[MAX_ARGS
], *arg_ptrs
[MAX_ARGS
], *arg
, retv
, ret_ref
, vhres
;
1081 unsigned i
, nconv
= 0;
1085 if(dp
->cNamedArgs
) {
1086 FIXME("Named arguments not supported\n");
1090 if(dp
->cArgs
!= func
->argc
) {
1091 FIXME("Invalid argument count (expected %u, got %u)\n", func
->argc
, dp
->cArgs
);
1092 return E_INVALIDARG
;
1095 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1099 for(i
=0; i
< func
->argc
; i
++) {
1100 arg
= dp
->rgvarg
+dp
->cArgs
-i
-1;
1101 if(func
->arg_types
[i
] == V_VT(arg
)) {
1104 hres
= change_type(arg_buf
+nconv
, arg
, func
->arg_types
[i
], caller
);
1107 arg_ptrs
[i
] = arg_buf
+ nconv
++;
1111 if(SUCCEEDED(hres
)) {
1112 if(func
->prop_vt
== VT_VOID
) {
1113 V_VT(&retv
) = VT_EMPTY
;
1115 V_VT(&retv
) = func
->prop_vt
;
1116 arg_ptrs
[func
->argc
] = &ret_ref
;
1117 V_VT(&ret_ref
) = VT_BYREF
|func
->prop_vt
;
1119 switch(func
->prop_vt
) {
1120 #define CASE_VT(vt,type,access) \
1122 V_BYREF(&ret_ref) = &access(&retv); \
1124 BUILTIN_TYPES_SWITCH
;
1131 V_VT(&vhres
) = VT_ERROR
;
1132 hres
= DispCallFunc(iface
, func
->call_vtbl_off
*sizeof(void*), CC_STDCALL
, VT_ERROR
,
1133 func
->argc
+ (func
->prop_vt
== VT_VOID
? 0 : 1), func
->arg_types
, arg_ptrs
, &vhres
);
1137 VariantClear(arg_buf
+nconv
);
1138 IUnknown_Release(iface
);
1141 if(FAILED(V_ERROR(&vhres
)))
1142 return V_ERROR(&vhres
);
1147 VariantClear(&retv
);
1148 return V_ERROR(&vhres
);
1151 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
1152 EXCEPINFO
*ei
, IServiceProvider
*caller
)
1157 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1159 return E_INVALIDARG
;
1161 case DISPATCH_METHOD
:
1162 if(This
->dynamic_data
&& This
->dynamic_data
->func_disps
1163 && This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1164 func_obj_entry_t
*entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1166 if(V_VT(&entry
->val
) != VT_DISPATCH
) {
1167 FIXME("calling %s not supported\n", debugstr_variant(&entry
->val
));
1171 if((IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
!= V_DISPATCH(&entry
->val
)) {
1172 if(!V_DISPATCH(&entry
->val
)) {
1173 FIXME("Calling null\n");
1177 hres
= invoke_disp_value(This
, V_DISPATCH(&entry
->val
), 0, flags
, dp
, res
, ei
, NULL
);
1182 if(func
->call_vtbl_off
)
1183 hres
= invoke_builtin_function(This
, func
, dp
, res
, caller
);
1185 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1187 case DISPATCH_PROPERTYGET
: {
1188 func_obj_entry_t
*entry
;
1190 if(func
->id
== DISPID_VALUE
) {
1193 ret
= SysAllocString(objectW
);
1195 return E_OUTOFMEMORY
;
1197 V_VT(res
) = VT_BSTR
;
1202 hres
= get_func_obj_entry(This
, func
, &entry
);
1206 V_VT(res
) = VT_EMPTY
;
1207 return VariantCopy(res
, &entry
->val
);
1209 case DISPATCH_PROPERTYPUT
: {
1210 func_obj_entry_t
*entry
;
1212 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1213 || dp
->cNamedArgs
> 1) {
1214 FIXME("invalid args\n");
1215 return E_INVALIDARG
;
1219 * NOTE: Although we have IDispatchEx tests showing, that it's not allowed to set
1220 * function property using InvokeEx, it's possible to do that from jscript.
1221 * Native probably uses some undocumented interface in this case, but it should
1222 * be fine for us to allow IDispatchEx handle that.
1224 hres
= get_func_obj_entry(This
, func
, &entry
);
1228 return VariantCopy(&entry
->val
, dp
->rgvarg
);
1231 FIXME("Unimplemented flags %x\n", flags
);
1238 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
1239 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1244 hres
= get_builtin_func(This
->info
, id
, &func
);
1245 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
1246 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1251 hres
= func
->hook(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1256 if(func
->func_disp_idx
!= -1)
1257 return function_invoke(This
, func
, flags
, dp
, res
, ei
, caller
);
1260 case DISPATCH_PROPERTYPUT
:
1262 V_VT(res
) = VT_EMPTY
;
1263 hres
= builtin_propput(This
, func
, dp
, caller
);
1265 case DISPATCH_PROPERTYGET
:
1266 hres
= builtin_propget(This
, func
, dp
, res
);
1269 if(!func
->get_vtbl_off
) {
1270 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1274 hres
= builtin_propget(This
, func
, NULL
, &v
);
1278 if(flags
!= (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
) || dp
->cArgs
) {
1279 if(V_VT(&v
) != VT_DISPATCH
) {
1280 FIXME("Not a function %s flags %08x\n", debugstr_variant(&v
), flags
);
1285 hres
= invoke_disp_value(This
, V_DISPATCH(&v
), lcid
, flags
, dp
, res
, ei
, caller
);
1286 IDispatch_Release(V_DISPATCH(&v
));
1298 HRESULT
remove_attribute(DispatchEx
*This
, DISPID id
, VARIANT_BOOL
*success
)
1300 switch(get_dispid_type(id
)) {
1301 case DISPEXPROP_CUSTOM
:
1302 FIXME("DISPEXPROP_CUSTOM not supported\n");
1305 case DISPEXPROP_DYNAMIC
: {
1306 DWORD idx
= id
- DISPID_DYNPROP_0
;
1307 dynamic_prop_t
*prop
;
1309 prop
= This
->dynamic_data
->props
+idx
;
1310 VariantClear(&prop
->var
);
1311 prop
->flags
|= DYNPROP_DELETED
;
1312 *success
= VARIANT_TRUE
;
1315 case DISPEXPROP_BUILTIN
: {
1317 DISPPARAMS dp
= {&var
,NULL
,1,0};
1321 hres
= get_builtin_func(This
->info
, id
, &func
);
1325 /* For builtin functions, we set their value to the original function. */
1326 if(func
->func_disp_idx
!= -1) {
1327 func_obj_entry_t
*entry
;
1329 if(!This
->dynamic_data
|| !This
->dynamic_data
->func_disps
1330 || !This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1331 *success
= VARIANT_FALSE
;
1335 entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1336 if(V_VT(&entry
->val
) == VT_DISPATCH
1337 && V_DISPATCH(&entry
->val
) == (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
) {
1338 *success
= VARIANT_FALSE
;
1342 VariantClear(&entry
->val
);
1343 V_VT(&entry
->val
) = VT_DISPATCH
;
1344 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
1345 IDispatch_AddRef(V_DISPATCH(&entry
->val
));
1346 *success
= VARIANT_TRUE
;
1350 V_VT(&var
) = VT_EMPTY
;
1351 hres
= builtin_propput(This
, func
, &dp
, NULL
);
1355 *success
= VARIANT_TRUE
;
1364 compat_mode_t
dispex_compat_mode(DispatchEx
*dispex
)
1366 return dispex
->info
->desc
->vtbl
->get_compat_mode(dispex
);
1369 static dispex_data_t
*ensure_dispex_info(dispex_static_data_t
*desc
, compat_mode_t compat_mode
)
1371 if(!desc
->info_cache
[compat_mode
]) {
1372 EnterCriticalSection(&cs_dispex_static_data
);
1373 if(!desc
->info_cache
[compat_mode
])
1374 desc
->info_cache
[compat_mode
] = preprocess_dispex_data(desc
, compat_mode
);
1375 LeaveCriticalSection(&cs_dispex_static_data
);
1377 return desc
->info_cache
[compat_mode
];
1380 static BOOL
ensure_real_info(DispatchEx
*dispex
)
1382 if(dispex
->info
!= dispex
->info
->desc
->delayed_init_info
)
1385 dispex
->info
= ensure_dispex_info(dispex
->info
->desc
, dispex_compat_mode(dispex
));
1386 return dispex
->info
!= NULL
;
1389 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
1391 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
1394 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1396 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1398 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1401 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
1403 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1405 return IUnknown_AddRef(This
->outer
);
1408 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
1410 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1412 return IUnknown_Release(This
->outer
);
1415 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
1417 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1419 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1425 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
1426 LCID lcid
, ITypeInfo
**ppTInfo
)
1428 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1431 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1433 hres
= get_typeinfo(This
->info
->desc
->disp_tid
, ppTInfo
);
1437 ITypeInfo_AddRef(*ppTInfo
);
1441 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
1442 LPOLESTR
*rgszNames
, UINT cNames
,
1443 LCID lcid
, DISPID
*rgDispId
)
1445 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1449 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1452 for(i
=0; i
< cNames
; i
++) {
1453 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
1461 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
1462 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1463 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1465 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1467 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1468 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1470 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
1471 pVarResult
, pExcepInfo
, NULL
);
1474 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
1476 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1477 dynamic_prop_t
*dprop
;
1480 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
1482 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
1483 FIXME("Unsupported grfdex %x\n", grfdex
);
1485 if(!ensure_real_info(This
))
1486 return E_OUTOFMEMORY
;
1488 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
1489 if(hres
!= DISP_E_UNKNOWNNAME
)
1492 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
1496 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
1500 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1501 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
1503 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1506 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1508 if(!ensure_real_info(This
))
1509 return E_OUTOFMEMORY
;
1511 if(wFlags
== (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
))
1512 wFlags
= DISPATCH_PROPERTYPUT
;
1514 switch(get_dispid_type(id
)) {
1515 case DISPEXPROP_CUSTOM
:
1516 if(!This
->info
->desc
->vtbl
|| !This
->info
->desc
->vtbl
->invoke
)
1517 return DISP_E_UNKNOWNNAME
;
1518 return This
->info
->desc
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1520 case DISPEXPROP_DYNAMIC
: {
1521 DWORD idx
= id
- DISPID_DYNPROP_0
;
1522 dynamic_prop_t
*prop
;
1524 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1525 return DISP_E_UNKNOWNNAME
;
1527 prop
= This
->dynamic_data
->props
+idx
;
1530 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1532 return E_INVALIDARG
;
1534 case DISPATCH_METHOD
:
1535 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
1536 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
1540 return invoke_disp_value(This
, V_DISPATCH(&prop
->var
), lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1541 case DISPATCH_PROPERTYGET
:
1542 if(prop
->flags
& DYNPROP_DELETED
)
1543 return DISP_E_UNKNOWNNAME
;
1544 V_VT(pvarRes
) = VT_EMPTY
;
1545 return variant_copy(pvarRes
, &prop
->var
);
1546 case DISPATCH_PROPERTYPUT
:
1547 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1548 || pdp
->cNamedArgs
> 1) {
1549 FIXME("invalid args\n");
1550 return E_INVALIDARG
;
1553 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
1554 VariantClear(&prop
->var
);
1555 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
1559 prop
->flags
&= ~DYNPROP_DELETED
;
1562 FIXME("unhandled wFlags %x\n", wFlags
);
1566 case DISPEXPROP_BUILTIN
:
1567 if(wFlags
== DISPATCH_CONSTRUCT
) {
1568 if(id
== DISPID_VALUE
) {
1569 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->value
) {
1570 return This
->info
->desc
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1572 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
1575 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
1579 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1586 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1588 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1590 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1592 /* Not implemented by IE */
1596 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1598 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1600 TRACE("(%p)->(%x)\n", This
, id
);
1602 /* Not implemented by IE */
1606 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1608 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1609 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1613 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1615 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1619 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1621 if(!ensure_real_info(This
))
1622 return E_OUTOFMEMORY
;
1624 if(is_dynamic_dispid(id
)) {
1625 DWORD idx
= id
- DISPID_DYNPROP_0
;
1627 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1628 return DISP_E_UNKNOWNNAME
;
1630 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1632 return E_OUTOFMEMORY
;
1637 hres
= get_builtin_func(This
->info
, id
, &func
);
1641 *pbstrName
= SysAllocString(func
->name
);
1643 return E_OUTOFMEMORY
;
1647 static HRESULT
next_dynamic_id(DispatchEx
*dispex
, DWORD idx
, DISPID
*ret_id
)
1649 while(idx
< dispex
->dynamic_data
->prop_cnt
&& dispex
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
)
1652 if(idx
== dispex
->dynamic_data
->prop_cnt
) {
1653 *ret_id
= DISPID_STARTENUM
;
1657 *ret_id
= DISPID_DYNPROP_0
+idx
;
1661 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1663 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1667 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1669 if(!ensure_real_info(This
))
1670 return E_OUTOFMEMORY
;
1672 if(is_dynamic_dispid(id
)) {
1673 DWORD idx
= id
- DISPID_DYNPROP_0
;
1675 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1676 return DISP_E_UNKNOWNNAME
;
1678 return next_dynamic_id(This
, idx
+1, pid
);
1681 if(id
== DISPID_STARTENUM
) {
1682 func
= This
->info
->funcs
;
1684 hres
= get_builtin_func(This
->info
, id
, &func
);
1690 while(func
< This
->info
->funcs
+ This
->info
->func_cnt
) {
1691 /* FIXME: Skip hidden properties */
1692 if(func
->func_disp_idx
== -1) {
1699 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
)
1700 return next_dynamic_id(This
, 0, pid
);
1702 *pid
= DISPID_STARTENUM
;
1706 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1708 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1709 FIXME("(%p)->(%p)\n", This
, ppunk
);
1713 static IDispatchExVtbl DispatchExVtbl
= {
1714 DispatchEx_QueryInterface
,
1717 DispatchEx_GetTypeInfoCount
,
1718 DispatchEx_GetTypeInfo
,
1719 DispatchEx_GetIDsOfNames
,
1721 DispatchEx_GetDispID
,
1722 DispatchEx_InvokeEx
,
1723 DispatchEx_DeleteMemberByName
,
1724 DispatchEx_DeleteMemberByDispID
,
1725 DispatchEx_GetMemberProperties
,
1726 DispatchEx_GetMemberName
,
1727 DispatchEx_GetNextDispID
,
1728 DispatchEx_GetNameSpaceParent
1731 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1733 if(IsEqualGUID(&IID_IDispatch
, riid
))
1734 *ppv
= &This
->IDispatchEx_iface
;
1735 else if(IsEqualGUID(&IID_IDispatchEx
, riid
))
1736 *ppv
= &This
->IDispatchEx_iface
;
1737 else if(IsEqualGUID(&IID_IDispatchJS
, riid
))
1739 else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
))
1741 else if(IsEqualGUID(&IID_IMarshal
, riid
))
1743 else if(IsEqualGUID(&IID_IManagedObject
, riid
))
1749 IUnknown_AddRef((IUnknown
*)*ppv
);
1753 void dispex_traverse(DispatchEx
*This
, nsCycleCollectionTraversalCallback
*cb
)
1755 dynamic_prop_t
*prop
;
1757 if(!This
->dynamic_data
)
1760 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1761 if(V_VT(&prop
->var
) == VT_DISPATCH
)
1762 note_cc_edge((nsISupports
*)V_DISPATCH(&prop
->var
), "dispex_data", cb
);
1765 /* FIXME: Traverse func_disps */
1768 void dispex_unlink(DispatchEx
*This
)
1770 dynamic_prop_t
*prop
;
1772 if(!This
->dynamic_data
)
1775 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1776 if(V_VT(&prop
->var
) == VT_DISPATCH
) {
1777 V_VT(&prop
->var
) = VT_EMPTY
;
1778 IDispatch_Release(V_DISPATCH(&prop
->var
));
1780 VariantClear(&prop
->var
);
1785 const void *dispex_get_vtbl(DispatchEx
*dispex
)
1787 return dispex
->info
->desc
->vtbl
;
1790 void release_dispex(DispatchEx
*This
)
1792 dynamic_prop_t
*prop
;
1794 if(!This
->dynamic_data
)
1797 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1798 VariantClear(&prop
->var
);
1799 heap_free(prop
->name
);
1802 heap_free(This
->dynamic_data
->props
);
1804 if(This
->dynamic_data
->func_disps
) {
1805 func_obj_entry_t
*iter
;
1807 for(iter
= This
->dynamic_data
->func_disps
; iter
< This
->dynamic_data
->func_disps
+ This
->info
->func_disp_cnt
; iter
++) {
1808 if(iter
->func_obj
) {
1809 iter
->func_obj
->obj
= NULL
;
1810 IDispatchEx_Release(&iter
->func_obj
->dispex
.IDispatchEx_iface
);
1812 VariantClear(&iter
->val
);
1815 heap_free(This
->dynamic_data
->func_disps
);
1818 heap_free(This
->dynamic_data
);
1821 void init_dispex_with_compat_mode(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
, compat_mode_t compat_mode
)
1823 assert(compat_mode
< COMPAT_MODE_CNT
);
1825 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1826 dispex
->outer
= outer
;
1827 dispex
->dynamic_data
= NULL
;
1829 if(data
->vtbl
&& data
->vtbl
->get_compat_mode
) {
1831 if(!data
->delayed_init_info
) {
1832 EnterCriticalSection(&cs_dispex_static_data
);
1833 if(!data
->delayed_init_info
) {
1834 dispex_data_t
*info
= heap_alloc_zero(sizeof(*data
->delayed_init_info
));
1837 data
->delayed_init_info
= info
;
1840 LeaveCriticalSection(&cs_dispex_static_data
);
1842 dispex
->info
= data
->delayed_init_info
;
1844 dispex
->info
= ensure_dispex_info(data
, compat_mode
);