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
;
67 compat_mode_t compat_mode
;
72 func_info_t
**name_table
;
84 #define DYNPROP_DELETED 0x01
88 IUnknown IUnknown_iface
;
95 func_disp_t
*func_obj
;
99 struct dispex_dynamic_data_t
{
102 dynamic_prop_t
*props
;
103 func_obj_entry_t
*func_disps
;
106 #define DISPID_DYNPROP_0 0x50000000
107 #define DISPID_DYNPROP_MAX 0x5fffffff
109 #define FDEX_VERSION_MASK 0xf0000000
111 static ITypeLib
*typelib
;
112 static ITypeInfo
*typeinfos
[LAST_tid
];
113 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
115 static REFIID tid_ids
[] = {
116 #define XIID(iface) &IID_ ## iface,
117 #define XDIID(iface) &DIID_ ## iface,
123 static HRESULT
load_typelib(void)
128 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
130 ERR("LoadRegTypeLib failed: %08x\n", hres
);
134 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
135 ITypeLib_Release(tl
);
139 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
144 hres
= load_typelib();
148 if(!typeinfos
[tid
]) {
151 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
153 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_mshtml_guid(tid_ids
[tid
]), hres
);
157 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
158 ITypeInfo_Release(ti
);
161 *typeinfo
= typeinfos
[tid
];
165 void release_typelib(void)
170 while(!list_empty(&dispex_data_list
)) {
171 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
172 list_remove(&iter
->entry
);
174 for(i
=0; i
< iter
->func_cnt
; i
++)
175 SysFreeString(iter
->funcs
[i
].name
);
177 heap_free(iter
->funcs
);
178 heap_free(iter
->name_table
);
185 for(i
=0; i
< ARRAY_SIZE(typeinfos
); i
++)
187 ITypeInfo_Release(typeinfos
[i
]);
189 ITypeLib_Release(typelib
);
190 DeleteCriticalSection(&cs_dispex_static_data
);
193 HRESULT
get_class_typeinfo(const CLSID
*clsid
, ITypeInfo
**typeinfo
)
198 hres
= load_typelib();
202 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, clsid
, typeinfo
);
204 ERR("GetTypeInfoOfGuid failed: %08x\n", hres
);
208 /* Not all argument types are supported yet */
209 #define BUILTIN_ARG_TYPES_SWITCH \
210 CASE_VT(VT_I2, INT16, V_I2); \
211 CASE_VT(VT_UI2, UINT16, V_UI2); \
212 CASE_VT(VT_I4, INT32, V_I4); \
213 CASE_VT(VT_UI4, UINT32, V_UI4); \
214 CASE_VT(VT_R4, float, V_R4); \
215 CASE_VT(VT_BSTR, BSTR, V_BSTR); \
216 CASE_VT(VT_BOOL, VARIANT_BOOL, V_BOOL)
218 /* List all types used by IDispatchEx-based properties */
219 #define BUILTIN_TYPES_SWITCH \
220 BUILTIN_ARG_TYPES_SWITCH; \
221 CASE_VT(VT_VARIANT, VARIANT, *); \
222 CASE_VT(VT_PTR, void*, V_BYREF); \
223 CASE_VT(VT_UNKNOWN, IUnknown*, V_UNKNOWN); \
224 CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH); \
225 CASE_VT(VT_UI8, ULONGLONG, V_UI8)
227 static BOOL
is_arg_type_supported(VARTYPE vt
)
230 #define CASE_VT(x,a,b) case x: return TRUE
231 BUILTIN_ARG_TYPES_SWITCH
;
237 static void add_func_info(dispex_data_t
*data
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
,
238 dispex_hook_invoke_t hook
)
244 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &name
, NULL
, NULL
, NULL
);
248 for(info
= data
->funcs
; info
< data
->funcs
+data
->func_cnt
; info
++) {
249 if(info
->id
== desc
->memid
|| !strcmpW(info
->name
, name
)) {
250 if(info
->tid
!= tid
) {
252 return; /* Duplicated in other interface */
258 if(info
== data
->funcs
+data
->func_cnt
) {
259 if(data
->func_cnt
== data
->func_size
)
260 data
->funcs
= heap_realloc_zero(data
->funcs
, (data
->func_size
<<= 1)*sizeof(func_info_t
));
261 info
= data
->funcs
+data
->func_cnt
;
265 info
->id
= desc
->memid
;
268 info
->func_disp_idx
= -1;
269 info
->prop_vt
= VT_EMPTY
;
275 if(desc
->invkind
& DISPATCH_METHOD
) {
278 info
->func_disp_idx
= data
->func_disp_cnt
++;
279 info
->argc
= desc
->cParams
;
281 assert(info
->argc
< MAX_ARGS
);
282 assert(desc
->funckind
== FUNC_DISPATCH
);
284 info
->arg_types
= heap_alloc(sizeof(*info
->arg_types
) * info
->argc
);
286 return; /* FIXME: real error instead of fallback */
288 for(i
=0; i
< info
->argc
; i
++)
289 info
->arg_types
[i
] = desc
->lprgelemdescParam
[i
].tdesc
.vt
;
291 info
->prop_vt
= desc
->elemdescFunc
.tdesc
.vt
;
292 if(info
->prop_vt
!= VT_VOID
&& !is_arg_type_supported(info
->prop_vt
)) {
293 TRACE("%s: return type %d\n", debugstr_w(info
->name
), info
->prop_vt
);
294 return; /* Fallback to ITypeInfo::Invoke */
297 if(desc
->cParamsOpt
) {
298 TRACE("%s: optional params\n", debugstr_w(info
->name
));
299 return; /* Fallback to ITypeInfo::Invoke */
302 for(i
=0; i
< info
->argc
; i
++) {
303 if(!is_arg_type_supported(info
->arg_types
[i
])) {
304 return; /* Fallback to ITypeInfo for unsupported arg types */
307 if(desc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
308 TRACE("%s param %d: default value\n", debugstr_w(info
->name
), i
);
309 return; /* Fallback to ITypeInfo::Invoke */
313 assert(info
->argc
<= MAX_ARGS
);
314 assert(desc
->callconv
== CC_STDCALL
);
316 info
->call_vtbl_off
= desc
->oVft
/sizeof(void*);
317 }else if(desc
->invkind
& (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYGET
)) {
318 VARTYPE vt
= VT_EMPTY
;
320 if(desc
->invkind
& DISPATCH_PROPERTYGET
) {
321 vt
= desc
->elemdescFunc
.tdesc
.vt
;
322 info
->get_vtbl_off
= desc
->oVft
/sizeof(void*);
324 if(desc
->invkind
& DISPATCH_PROPERTYPUT
) {
325 assert(desc
->cParams
== 1);
326 vt
= desc
->lprgelemdescParam
->tdesc
.vt
;
327 info
->put_vtbl_off
= desc
->oVft
/sizeof(void*);
330 assert(info
->prop_vt
== VT_EMPTY
|| vt
== info
->prop_vt
);
335 static HRESULT
process_interface(dispex_data_t
*data
, tid_t tid
, ITypeInfo
*disp_typeinfo
, const dispex_hook_t
*hooks
)
337 unsigned i
= 7; /* skip IDispatch functions */
342 hres
= get_typeinfo(tid
, &typeinfo
);
347 const dispex_hook_t
*hook
= NULL
;
349 hres
= ITypeInfo_GetFuncDesc(typeinfo
, i
++, &funcdesc
);
354 for(hook
= hooks
; hook
->dispid
!= DISPID_UNKNOWN
; hook
++) {
355 if(hook
->dispid
== funcdesc
->memid
)
358 if(hook
->dispid
== DISPID_UNKNOWN
)
362 if(!hook
|| hook
->invoke
) {
363 TRACE("adding...\n");
364 add_func_info(data
, tid
, funcdesc
, disp_typeinfo
? disp_typeinfo
: typeinfo
,
365 hook
? hook
->invoke
: NULL
);
368 ITypeInfo_ReleaseFuncDesc(typeinfo
, funcdesc
);
374 void dispex_info_add_interface(dispex_data_t
*info
, tid_t tid
, const dispex_hook_t
*hooks
)
378 hres
= process_interface(info
, tid
, NULL
, hooks
);
380 ERR("process_interface failed: %08x\n", hres
);
383 static int dispid_cmp(const void *p1
, const void *p2
)
385 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
388 static int func_name_cmp(const void *p1
, const void *p2
)
390 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
393 static dispex_data_t
*preprocess_dispex_data(dispex_static_data_t
*desc
, compat_mode_t compat_mode
)
402 hres
= get_typeinfo(desc
->disp_tid
, &dti
);
404 ERR("Could not get disp type info: %08x\n", hres
);
409 data
= heap_alloc(sizeof(dispex_data_t
));
411 ERR("Out of memory\n");
415 data
->compat_mode
= compat_mode
;
417 data
->func_disp_cnt
= 0;
418 data
->func_size
= 16;
419 data
->funcs
= heap_alloc_zero(data
->func_size
*sizeof(func_info_t
));
422 ERR("Out of memory\n");
425 list_add_tail(&dispex_data_list
, &data
->entry
);
428 desc
->init_info(data
, compat_mode
);
430 for(tid
= desc
->iface_tids
; *tid
; tid
++) {
431 hres
= process_interface(data
, *tid
, dti
, NULL
);
436 if(!data
->func_cnt
) {
437 heap_free(data
->funcs
);
438 data
->name_table
= NULL
;
445 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
446 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
448 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
449 for(i
=0; i
< data
->func_cnt
; i
++)
450 data
->name_table
[i
] = data
->funcs
+i
;
451 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
455 static int id_cmp(const void *p1
, const void *p2
)
457 return *(const DISPID
*)p1
- *(const DISPID
*)p2
;
460 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
462 unsigned i
, func_cnt
;
469 hres
= get_typeinfo(tid
, &ti
);
473 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
475 ITypeInfo_Release(ti
);
479 func_cnt
= attr
->cFuncs
;
480 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
482 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
484 ITypeInfo_Release(ti
);
485 return E_OUTOFMEMORY
;
488 for(i
=0; i
< func_cnt
; i
++) {
489 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
493 ids
[i
] = funcdesc
->memid
;
494 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
497 ITypeInfo_Release(ti
);
503 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
505 *ret_size
= func_cnt
;
510 static inline BOOL
is_custom_dispid(DISPID id
)
512 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
515 static inline BOOL
is_dynamic_dispid(DISPID id
)
517 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
520 dispex_prop_type_t
get_dispid_type(DISPID id
)
522 if(is_dynamic_dispid(id
))
523 return DISPEXPROP_DYNAMIC
;
524 if(is_custom_dispid(id
))
525 return DISPEXPROP_CUSTOM
;
526 return DISPEXPROP_BUILTIN
;
529 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
531 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
532 V_VT(dest
) = VT_BSTR
;
537 return VariantCopy(dest
, src
);
540 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
)
542 if(This
->dynamic_data
)
543 return This
->dynamic_data
;
545 This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
));
546 if(!This
->dynamic_data
)
549 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->populate_props
)
550 This
->info
->desc
->vtbl
->populate_props(This
);
552 return This
->dynamic_data
;
555 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
557 const BOOL alloc
= flags
& fdexNameEnsure
;
558 dispex_dynamic_data_t
*data
;
559 dynamic_prop_t
*prop
;
561 data
= get_dynamic_data(This
);
563 return E_OUTOFMEMORY
;
565 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
566 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
567 if(prop
->flags
& DYNPROP_DELETED
) {
569 return DISP_E_UNKNOWNNAME
;
570 prop
->flags
&= ~DYNPROP_DELETED
;
578 return DISP_E_UNKNOWNNAME
;
580 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
582 if(!data
->buf_size
) {
583 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
585 return E_OUTOFMEMORY
;
587 }else if(data
->buf_size
== data
->prop_cnt
) {
588 dynamic_prop_t
*new_props
;
590 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
592 return E_OUTOFMEMORY
;
594 data
->props
= new_props
;
595 data
->buf_size
<<= 1;
598 prop
= data
->props
+ data
->prop_cnt
;
600 prop
->name
= heap_strdupW(name
);
602 return E_OUTOFMEMORY
;
604 VariantInit(&prop
->var
);
611 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
613 dynamic_prop_t
*prop
;
616 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
624 HRESULT
dispex_get_dynid(DispatchEx
*This
, const WCHAR
*name
, DISPID
*id
)
626 dynamic_prop_t
*prop
;
629 hres
= get_dynamic_prop(This
, name
, fdexNameEnsure
, &prop
);
633 *id
= DISPID_DYNPROP_0
+ (prop
- This
->dynamic_data
->props
);
637 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
638 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
640 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->value
)
641 return This
->info
->desc
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
644 case DISPATCH_PROPERTYGET
:
646 V_BSTR(res
) = SysAllocString(objectW
);
648 return E_OUTOFMEMORY
;
651 FIXME("Unimplemented flags %x\n", flags
);
658 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
661 DISPPARAMS params
= {dp
->rgvarg
+dp
->cNamedArgs
, NULL
, dp
->cArgs
-dp
->cNamedArgs
, 0};
667 hres
= get_typeinfo(func
->tid
, &ti
);
669 ERR("Could not get type info: %08x\n", hres
);
673 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
675 ERR("Could not get iface %s: %08x\n", debugstr_mshtml_guid(tid_ids
[func
->tid
]), hres
);
679 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, ¶ms
, res
, ei
, &argerr
);
681 IUnknown_Release(unk
);
685 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
687 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
690 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
692 func_disp_t
*This
= impl_from_IUnknown(iface
);
694 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
696 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
697 *ppv
= &This
->IUnknown_iface
;
698 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
699 return *ppv
? S_OK
: E_NOINTERFACE
;
702 return E_NOINTERFACE
;
705 IUnknown_AddRef((IUnknown
*)*ppv
);
709 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
711 func_disp_t
*This
= impl_from_IUnknown(iface
);
712 LONG ref
= InterlockedIncrement(&This
->ref
);
714 TRACE("(%p) ref=%d\n", This
, ref
);
719 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
721 func_disp_t
*This
= impl_from_IUnknown(iface
);
722 LONG ref
= InterlockedDecrement(&This
->ref
);
724 TRACE("(%p) ref=%d\n", This
, ref
);
728 release_dispex(&This
->dispex
);
735 static const IUnknownVtbl FunctionUnkVtbl
= {
736 Function_QueryInterface
,
741 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
743 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
746 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
747 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
749 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
753 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
757 case DISPATCH_METHOD
:
760 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
762 case DISPATCH_PROPERTYGET
: {
767 static const WCHAR func_prefixW
[] =
768 {'\n','f','u','n','c','t','i','o','n',' '};
769 static const WCHAR func_suffixW
[] =
770 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
772 /* FIXME: This probably should be more generic. Also we should try to get IID_IActiveScriptSite and SID_GetCaller. */
774 return E_ACCESSDENIED
;
776 name_len
= SysStringLen(This
->info
->name
);
777 ptr
= str
= SysAllocStringLen(NULL
, name_len
+ ARRAY_SIZE(func_prefixW
) + ARRAY_SIZE(func_suffixW
));
779 return E_OUTOFMEMORY
;
781 memcpy(ptr
, func_prefixW
, sizeof(func_prefixW
));
782 ptr
+= ARRAY_SIZE(func_prefixW
);
784 memcpy(ptr
, This
->info
->name
, name_len
*sizeof(WCHAR
));
787 memcpy(ptr
, func_suffixW
, sizeof(func_suffixW
));
794 FIXME("Unimplemented flags %x\n", flags
);
801 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
808 static const tid_t function_iface_tids
[] = {0};
810 static dispex_static_data_t function_dispex
= {
811 &function_dispex_vtbl
,
816 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
820 ret
= heap_alloc_zero(sizeof(func_disp_t
));
824 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
825 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
833 static HRESULT
invoke_disp_value(DispatchEx
*This
, IDispatch
*func_disp
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
834 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
836 DISPID named_arg
= DISPID_THIS
;
837 DISPPARAMS new_dp
= {NULL
, &named_arg
, 0, 1};
842 FIXME("named args not supported\n");
846 new_dp
.rgvarg
= heap_alloc((dp
->cArgs
+1)*sizeof(VARIANTARG
));
848 return E_OUTOFMEMORY
;
850 new_dp
.cArgs
= dp
->cArgs
+1;
851 memcpy(new_dp
.rgvarg
+1, dp
->rgvarg
, dp
->cArgs
*sizeof(VARIANTARG
));
853 V_VT(new_dp
.rgvarg
) = VT_DISPATCH
;
854 V_DISPATCH(new_dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
856 hres
= IDispatch_QueryInterface(func_disp
, &IID_IDispatchEx
, (void**)&dispex
);
858 if(SUCCEEDED(hres
)) {
859 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, flags
, &new_dp
, res
, ei
, caller
);
860 IDispatchEx_Release(dispex
);
863 hres
= IDispatch_Invoke(func_disp
, DISPID_VALUE
, &IID_NULL
, lcid
, flags
, &new_dp
, res
, ei
, &err
);
866 TRACE("<<< %s\n", debugstr_variant(res
));
868 WARN("<<< %08x\n", hres
);
870 heap_free(new_dp
.rgvarg
);
874 static HRESULT
get_func_obj_entry(DispatchEx
*This
, func_info_t
*func
, func_obj_entry_t
**ret
)
876 dispex_dynamic_data_t
*dynamic_data
;
877 func_obj_entry_t
*entry
;
879 dynamic_data
= get_dynamic_data(This
);
881 return E_OUTOFMEMORY
;
883 if(!dynamic_data
->func_disps
) {
884 dynamic_data
->func_disps
= heap_alloc_zero(This
->info
->func_disp_cnt
* sizeof(*dynamic_data
->func_disps
));
885 if(!dynamic_data
->func_disps
)
886 return E_OUTOFMEMORY
;
889 entry
= dynamic_data
->func_disps
+ func
->func_disp_idx
;
890 if(!entry
->func_obj
) {
891 entry
->func_obj
= create_func_disp(This
, func
);
893 return E_OUTOFMEMORY
;
895 IDispatchEx_AddRef(&entry
->func_obj
->dispex
.IDispatchEx_iface
);
896 V_VT(&entry
->val
) = VT_DISPATCH
;
897 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
904 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
909 max
= data
->func_cnt
-1;
914 if(data
->funcs
[n
].id
== id
) {
915 *ret
= data
->funcs
+n
;
919 if(data
->funcs
[n
].id
< id
)
925 WARN("invalid id %x\n", id
);
926 return DISP_E_UNKNOWNNAME
;
929 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
934 max
= This
->info
->func_cnt
-1;
939 c
= strcmpiW(This
->info
->name_table
[n
]->name
, name
);
941 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(This
->info
->name_table
[n
]->name
, name
))
944 *ret
= This
->info
->name_table
[n
]->id
;
954 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->get_dispid
) {
957 hres
= This
->info
->desc
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
958 if(hres
!= DISP_E_UNKNOWNNAME
)
962 return DISP_E_UNKNOWNNAME
;
965 static HRESULT
change_type(VARIANT
*dst
, VARIANT
*src
, VARTYPE vt
, IServiceProvider
*caller
)
967 V_VT(dst
) = VT_EMPTY
;
970 IVariantChangeType
*change_type
= NULL
;
973 hres
= IServiceProvider_QueryService(caller
, &SID_VariantConversion
, &IID_IVariantChangeType
, (void**)&change_type
);
974 if(SUCCEEDED(hres
)) {
975 hres
= IVariantChangeType_ChangeType(change_type
, dst
, src
, LOCALE_NEUTRAL
, vt
);
976 IVariantChangeType_Release(change_type
);
983 if(V_VT(src
) == VT_BSTR
) {
985 V_BOOL(dst
) = variant_bool(V_BSTR(src
) && *V_BSTR(src
));
991 return VariantChangeType(dst
, src
, 0, vt
);
994 static HRESULT
builtin_propget(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
)
999 if(dp
&& dp
->cArgs
) {
1000 FIXME("cArgs %d\n", dp
->cArgs
);
1004 assert(func
->get_vtbl_off
);
1006 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1007 if(SUCCEEDED(hres
)) {
1008 switch(func
->prop_vt
) {
1009 #define CASE_VT(vt,type,access) \
1012 hres = ((HRESULT (WINAPI*)(IUnknown*,type*))((void**)iface->lpVtbl)[func->get_vtbl_off])(iface,&val); \
1013 if(SUCCEEDED(hres)) \
1014 access(res) = val; \
1017 BUILTIN_TYPES_SWITCH
;
1020 FIXME("Unhandled vt %d\n", func
->prop_vt
);
1023 IUnknown_Release(iface
);
1029 if(func
->prop_vt
!= VT_VARIANT
)
1030 V_VT(res
) = func
->prop_vt
== VT_PTR
? VT_DISPATCH
: func
->prop_vt
;
1034 static HRESULT
builtin_propput(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, IServiceProvider
*caller
)
1040 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1041 || dp
->cNamedArgs
> 1) {
1042 FIXME("invalid args\n");
1043 return E_INVALIDARG
;
1046 if(!func
->put_vtbl_off
) {
1047 FIXME("No setter\n");
1052 if(func
->prop_vt
!= VT_VARIANT
&& V_VT(v
) != func
->prop_vt
) {
1053 hres
= change_type(&tmpv
, v
, func
->prop_vt
, caller
);
1059 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1060 if(SUCCEEDED(hres
)) {
1061 switch(func
->prop_vt
) {
1062 #define CASE_VT(vt,type,access) \
1064 hres = ((HRESULT (WINAPI*)(IUnknown*,type))((void**)iface->lpVtbl)[func->put_vtbl_off])(iface,access(v)); \
1066 BUILTIN_TYPES_SWITCH
;
1069 FIXME("Unimplemented vt %d\n", func
->prop_vt
);
1073 IUnknown_Release(iface
);
1081 static HRESULT
invoke_builtin_function(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
, IServiceProvider
*caller
)
1083 VARIANT arg_buf
[MAX_ARGS
], *arg_ptrs
[MAX_ARGS
], *arg
, retv
, ret_ref
, vhres
;
1084 unsigned i
, nconv
= 0;
1088 if(dp
->cNamedArgs
) {
1089 FIXME("Named arguments not supported\n");
1093 if(dp
->cArgs
!= func
->argc
) {
1094 FIXME("Invalid argument count (expected %u, got %u)\n", func
->argc
, dp
->cArgs
);
1095 return E_INVALIDARG
;
1098 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1102 for(i
=0; i
< func
->argc
; i
++) {
1103 arg
= dp
->rgvarg
+dp
->cArgs
-i
-1;
1104 if(func
->arg_types
[i
] == V_VT(arg
)) {
1107 hres
= change_type(arg_buf
+nconv
, arg
, func
->arg_types
[i
], caller
);
1110 arg_ptrs
[i
] = arg_buf
+ nconv
++;
1114 if(SUCCEEDED(hres
)) {
1115 if(func
->prop_vt
== VT_VOID
) {
1116 V_VT(&retv
) = VT_EMPTY
;
1118 V_VT(&retv
) = func
->prop_vt
;
1119 arg_ptrs
[func
->argc
] = &ret_ref
;
1120 V_VT(&ret_ref
) = VT_BYREF
|func
->prop_vt
;
1122 switch(func
->prop_vt
) {
1123 #define CASE_VT(vt,type,access) \
1125 V_BYREF(&ret_ref) = &access(&retv); \
1127 BUILTIN_TYPES_SWITCH
;
1134 V_VT(&vhres
) = VT_ERROR
;
1135 hres
= DispCallFunc(iface
, func
->call_vtbl_off
*sizeof(void*), CC_STDCALL
, VT_ERROR
,
1136 func
->argc
+ (func
->prop_vt
== VT_VOID
? 0 : 1), func
->arg_types
, arg_ptrs
, &vhres
);
1140 VariantClear(arg_buf
+nconv
);
1141 IUnknown_Release(iface
);
1144 if(FAILED(V_ERROR(&vhres
)))
1145 return V_ERROR(&vhres
);
1150 VariantClear(&retv
);
1151 return V_ERROR(&vhres
);
1154 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
1155 EXCEPINFO
*ei
, IServiceProvider
*caller
)
1160 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1162 return E_INVALIDARG
;
1164 case DISPATCH_METHOD
:
1165 if(This
->dynamic_data
&& This
->dynamic_data
->func_disps
1166 && This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1167 func_obj_entry_t
*entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1169 if(V_VT(&entry
->val
) != VT_DISPATCH
) {
1170 FIXME("calling %s not supported\n", debugstr_variant(&entry
->val
));
1174 if((IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
!= V_DISPATCH(&entry
->val
)) {
1175 if(!V_DISPATCH(&entry
->val
)) {
1176 FIXME("Calling null\n");
1180 hres
= invoke_disp_value(This
, V_DISPATCH(&entry
->val
), 0, flags
, dp
, res
, ei
, NULL
);
1185 if(func
->call_vtbl_off
)
1186 hres
= invoke_builtin_function(This
, func
, dp
, res
, caller
);
1188 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1190 case DISPATCH_PROPERTYGET
: {
1191 func_obj_entry_t
*entry
;
1193 if(func
->id
== DISPID_VALUE
) {
1196 ret
= SysAllocString(objectW
);
1198 return E_OUTOFMEMORY
;
1200 V_VT(res
) = VT_BSTR
;
1205 hres
= get_func_obj_entry(This
, func
, &entry
);
1209 V_VT(res
) = VT_EMPTY
;
1210 return VariantCopy(res
, &entry
->val
);
1212 case DISPATCH_PROPERTYPUT
: {
1213 func_obj_entry_t
*entry
;
1215 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1216 || dp
->cNamedArgs
> 1) {
1217 FIXME("invalid args\n");
1218 return E_INVALIDARG
;
1222 * NOTE: Although we have IDispatchEx tests showing, that it's not allowed to set
1223 * function property using InvokeEx, it's possible to do that from jscript.
1224 * Native probably uses some undocumented interface in this case, but it should
1225 * be fine for us to allow IDispatchEx handle that.
1227 hres
= get_func_obj_entry(This
, func
, &entry
);
1231 return VariantCopy(&entry
->val
, dp
->rgvarg
);
1234 FIXME("Unimplemented flags %x\n", flags
);
1241 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
1242 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1247 hres
= get_builtin_func(This
->info
, id
, &func
);
1248 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
1249 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1254 hres
= func
->hook(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1259 if(func
->func_disp_idx
!= -1)
1260 return function_invoke(This
, func
, flags
, dp
, res
, ei
, caller
);
1263 case DISPATCH_PROPERTYPUT
:
1265 V_VT(res
) = VT_EMPTY
;
1266 hres
= builtin_propput(This
, func
, dp
, caller
);
1268 case DISPATCH_PROPERTYGET
:
1269 hres
= builtin_propget(This
, func
, dp
, res
);
1272 if(!func
->get_vtbl_off
) {
1273 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1277 hres
= builtin_propget(This
, func
, NULL
, &v
);
1281 if(flags
!= (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
) || dp
->cArgs
) {
1282 if(V_VT(&v
) != VT_DISPATCH
) {
1283 FIXME("Not a function %s flags %08x\n", debugstr_variant(&v
), flags
);
1288 hres
= invoke_disp_value(This
, V_DISPATCH(&v
), lcid
, flags
, dp
, res
, ei
, caller
);
1289 IDispatch_Release(V_DISPATCH(&v
));
1301 HRESULT
remove_attribute(DispatchEx
*This
, DISPID id
, VARIANT_BOOL
*success
)
1303 switch(get_dispid_type(id
)) {
1304 case DISPEXPROP_CUSTOM
:
1305 FIXME("DISPEXPROP_CUSTOM not supported\n");
1308 case DISPEXPROP_DYNAMIC
: {
1309 DWORD idx
= id
- DISPID_DYNPROP_0
;
1310 dynamic_prop_t
*prop
;
1312 prop
= This
->dynamic_data
->props
+idx
;
1313 VariantClear(&prop
->var
);
1314 prop
->flags
|= DYNPROP_DELETED
;
1315 *success
= VARIANT_TRUE
;
1318 case DISPEXPROP_BUILTIN
: {
1320 DISPPARAMS dp
= {&var
,NULL
,1,0};
1324 hres
= get_builtin_func(This
->info
, id
, &func
);
1328 /* For builtin functions, we set their value to the original function. */
1329 if(func
->func_disp_idx
!= -1) {
1330 func_obj_entry_t
*entry
;
1332 if(!This
->dynamic_data
|| !This
->dynamic_data
->func_disps
1333 || !This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1334 *success
= VARIANT_FALSE
;
1338 entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1339 if(V_VT(&entry
->val
) == VT_DISPATCH
1340 && V_DISPATCH(&entry
->val
) == (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
) {
1341 *success
= VARIANT_FALSE
;
1345 VariantClear(&entry
->val
);
1346 V_VT(&entry
->val
) = VT_DISPATCH
;
1347 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
1348 IDispatch_AddRef(V_DISPATCH(&entry
->val
));
1349 *success
= VARIANT_TRUE
;
1353 V_VT(&var
) = VT_EMPTY
;
1354 hres
= builtin_propput(This
, func
, &dp
, NULL
);
1358 *success
= VARIANT_TRUE
;
1367 compat_mode_t
dispex_compat_mode(DispatchEx
*dispex
)
1369 return dispex
->info
!= dispex
->info
->desc
->delayed_init_info
1370 ? dispex
->info
->compat_mode
1371 : dispex
->info
->desc
->vtbl
->get_compat_mode(dispex
);
1374 static dispex_data_t
*ensure_dispex_info(dispex_static_data_t
*desc
, compat_mode_t compat_mode
)
1376 if(!desc
->info_cache
[compat_mode
]) {
1377 EnterCriticalSection(&cs_dispex_static_data
);
1378 if(!desc
->info_cache
[compat_mode
])
1379 desc
->info_cache
[compat_mode
] = preprocess_dispex_data(desc
, compat_mode
);
1380 LeaveCriticalSection(&cs_dispex_static_data
);
1382 return desc
->info_cache
[compat_mode
];
1385 static BOOL
ensure_real_info(DispatchEx
*dispex
)
1387 if(dispex
->info
!= dispex
->info
->desc
->delayed_init_info
)
1390 dispex
->info
= ensure_dispex_info(dispex
->info
->desc
, dispex_compat_mode(dispex
));
1391 return dispex
->info
!= NULL
;
1394 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
1396 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
1399 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1401 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1403 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1406 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
1408 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1410 return IUnknown_AddRef(This
->outer
);
1413 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
1415 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1417 return IUnknown_Release(This
->outer
);
1420 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
1422 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1424 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1430 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
1431 LCID lcid
, ITypeInfo
**ppTInfo
)
1433 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1436 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1438 hres
= get_typeinfo(This
->info
->desc
->disp_tid
, ppTInfo
);
1442 ITypeInfo_AddRef(*ppTInfo
);
1446 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
1447 LPOLESTR
*rgszNames
, UINT cNames
,
1448 LCID lcid
, DISPID
*rgDispId
)
1450 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1454 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1457 for(i
=0; i
< cNames
; i
++) {
1458 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
1466 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
1467 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1468 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1470 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1472 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1473 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1475 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
1476 pVarResult
, pExcepInfo
, NULL
);
1479 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
1481 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1482 dynamic_prop_t
*dprop
;
1485 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
1487 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
1488 FIXME("Unsupported grfdex %x\n", grfdex
);
1490 if(!ensure_real_info(This
))
1491 return E_OUTOFMEMORY
;
1493 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
1494 if(hres
!= DISP_E_UNKNOWNNAME
)
1497 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
1501 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
1505 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1506 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
1508 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1511 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1513 if(!ensure_real_info(This
))
1514 return E_OUTOFMEMORY
;
1516 if(wFlags
== (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
))
1517 wFlags
= DISPATCH_PROPERTYPUT
;
1519 switch(get_dispid_type(id
)) {
1520 case DISPEXPROP_CUSTOM
:
1521 if(!This
->info
->desc
->vtbl
|| !This
->info
->desc
->vtbl
->invoke
)
1522 return DISP_E_UNKNOWNNAME
;
1523 return This
->info
->desc
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1525 case DISPEXPROP_DYNAMIC
: {
1526 DWORD idx
= id
- DISPID_DYNPROP_0
;
1527 dynamic_prop_t
*prop
;
1529 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1530 return DISP_E_UNKNOWNNAME
;
1532 prop
= This
->dynamic_data
->props
+idx
;
1535 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1537 return E_INVALIDARG
;
1539 case DISPATCH_METHOD
:
1540 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
1541 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
1545 return invoke_disp_value(This
, V_DISPATCH(&prop
->var
), lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1546 case DISPATCH_PROPERTYGET
:
1547 if(prop
->flags
& DYNPROP_DELETED
)
1548 return DISP_E_UNKNOWNNAME
;
1549 V_VT(pvarRes
) = VT_EMPTY
;
1550 return variant_copy(pvarRes
, &prop
->var
);
1551 case DISPATCH_PROPERTYPUT
:
1552 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1553 || pdp
->cNamedArgs
> 1) {
1554 FIXME("invalid args\n");
1555 return E_INVALIDARG
;
1558 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
1559 VariantClear(&prop
->var
);
1560 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
1564 prop
->flags
&= ~DYNPROP_DELETED
;
1567 FIXME("unhandled wFlags %x\n", wFlags
);
1571 case DISPEXPROP_BUILTIN
:
1572 if(wFlags
== DISPATCH_CONSTRUCT
) {
1573 if(id
== DISPID_VALUE
) {
1574 if(This
->info
->desc
->vtbl
&& This
->info
->desc
->vtbl
->value
) {
1575 return This
->info
->desc
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1577 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
1580 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
1584 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1591 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1593 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1595 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1597 /* Not implemented by IE */
1601 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1603 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1605 TRACE("(%p)->(%x)\n", This
, id
);
1607 /* Not implemented by IE */
1611 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1613 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1614 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1618 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1620 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1624 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1626 if(!ensure_real_info(This
))
1627 return E_OUTOFMEMORY
;
1629 if(is_dynamic_dispid(id
)) {
1630 DWORD idx
= id
- DISPID_DYNPROP_0
;
1632 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1633 return DISP_E_UNKNOWNNAME
;
1635 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1637 return E_OUTOFMEMORY
;
1642 hres
= get_builtin_func(This
->info
, id
, &func
);
1646 *pbstrName
= SysAllocString(func
->name
);
1648 return E_OUTOFMEMORY
;
1652 static HRESULT
next_dynamic_id(DispatchEx
*dispex
, DWORD idx
, DISPID
*ret_id
)
1654 while(idx
< dispex
->dynamic_data
->prop_cnt
&& dispex
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
)
1657 if(idx
== dispex
->dynamic_data
->prop_cnt
) {
1658 *ret_id
= DISPID_STARTENUM
;
1662 *ret_id
= DISPID_DYNPROP_0
+idx
;
1666 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1668 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1672 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1674 if(!ensure_real_info(This
))
1675 return E_OUTOFMEMORY
;
1677 if(is_dynamic_dispid(id
)) {
1678 DWORD idx
= id
- DISPID_DYNPROP_0
;
1680 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1681 return DISP_E_UNKNOWNNAME
;
1683 return next_dynamic_id(This
, idx
+1, pid
);
1686 if(id
== DISPID_STARTENUM
) {
1687 func
= This
->info
->funcs
;
1689 hres
= get_builtin_func(This
->info
, id
, &func
);
1695 while(func
< This
->info
->funcs
+ This
->info
->func_cnt
) {
1696 /* FIXME: Skip hidden properties */
1697 if(func
->func_disp_idx
== -1) {
1704 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
)
1705 return next_dynamic_id(This
, 0, pid
);
1707 *pid
= DISPID_STARTENUM
;
1711 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1713 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1714 FIXME("(%p)->(%p)\n", This
, ppunk
);
1718 static IDispatchExVtbl DispatchExVtbl
= {
1719 DispatchEx_QueryInterface
,
1722 DispatchEx_GetTypeInfoCount
,
1723 DispatchEx_GetTypeInfo
,
1724 DispatchEx_GetIDsOfNames
,
1726 DispatchEx_GetDispID
,
1727 DispatchEx_InvokeEx
,
1728 DispatchEx_DeleteMemberByName
,
1729 DispatchEx_DeleteMemberByDispID
,
1730 DispatchEx_GetMemberProperties
,
1731 DispatchEx_GetMemberName
,
1732 DispatchEx_GetNextDispID
,
1733 DispatchEx_GetNameSpaceParent
1736 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1738 if(IsEqualGUID(&IID_IDispatch
, riid
))
1739 *ppv
= &This
->IDispatchEx_iface
;
1740 else if(IsEqualGUID(&IID_IDispatchEx
, riid
))
1741 *ppv
= &This
->IDispatchEx_iface
;
1742 else if(IsEqualGUID(&IID_IDispatchJS
, riid
))
1744 else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
))
1746 else if(IsEqualGUID(&IID_IMarshal
, riid
))
1748 else if(IsEqualGUID(&IID_IManagedObject
, riid
))
1754 IUnknown_AddRef((IUnknown
*)*ppv
);
1758 void dispex_traverse(DispatchEx
*This
, nsCycleCollectionTraversalCallback
*cb
)
1760 dynamic_prop_t
*prop
;
1762 if(!This
->dynamic_data
)
1765 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1766 if(V_VT(&prop
->var
) == VT_DISPATCH
)
1767 note_cc_edge((nsISupports
*)V_DISPATCH(&prop
->var
), "dispex_data", cb
);
1770 /* FIXME: Traverse func_disps */
1773 void dispex_unlink(DispatchEx
*This
)
1775 dynamic_prop_t
*prop
;
1777 if(!This
->dynamic_data
)
1780 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1781 if(V_VT(&prop
->var
) == VT_DISPATCH
) {
1782 V_VT(&prop
->var
) = VT_EMPTY
;
1783 IDispatch_Release(V_DISPATCH(&prop
->var
));
1785 VariantClear(&prop
->var
);
1790 const void *dispex_get_vtbl(DispatchEx
*dispex
)
1792 return dispex
->info
->desc
->vtbl
;
1795 void release_dispex(DispatchEx
*This
)
1797 dynamic_prop_t
*prop
;
1799 if(!This
->dynamic_data
)
1802 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1803 VariantClear(&prop
->var
);
1804 heap_free(prop
->name
);
1807 heap_free(This
->dynamic_data
->props
);
1809 if(This
->dynamic_data
->func_disps
) {
1810 func_obj_entry_t
*iter
;
1812 for(iter
= This
->dynamic_data
->func_disps
; iter
< This
->dynamic_data
->func_disps
+ This
->info
->func_disp_cnt
; iter
++) {
1813 if(iter
->func_obj
) {
1814 iter
->func_obj
->obj
= NULL
;
1815 IDispatchEx_Release(&iter
->func_obj
->dispex
.IDispatchEx_iface
);
1817 VariantClear(&iter
->val
);
1820 heap_free(This
->dynamic_data
->func_disps
);
1823 heap_free(This
->dynamic_data
);
1826 void init_dispex_with_compat_mode(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
, compat_mode_t compat_mode
)
1828 assert(compat_mode
< COMPAT_MODE_CNT
);
1830 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1831 dispex
->outer
= outer
;
1832 dispex
->dynamic_data
= NULL
;
1834 if(data
->vtbl
&& data
->vtbl
->get_compat_mode
) {
1836 if(!data
->delayed_init_info
) {
1837 EnterCriticalSection(&cs_dispex_static_data
);
1838 if(!data
->delayed_init_info
) {
1839 dispex_data_t
*info
= heap_alloc_zero(sizeof(*data
->delayed_init_info
));
1842 data
->delayed_init_info
= info
;
1845 LeaveCriticalSection(&cs_dispex_static_data
);
1847 dispex
->info
= data
->delayed_init_info
;
1849 dispex
->info
= ensure_dispex_info(data
, compat_mode
);