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
30 #include "wine/debug.h"
32 #include "mshtml_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 static CRITICAL_SECTION cs_dispex_static_data
;
39 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
41 0, 0, &cs_dispex_static_data
,
42 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
43 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
45 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
48 static const WCHAR objectW
[] = {'[','o','b','j','e','c','t',']',0};
63 struct dispex_data_t
{
66 func_info_t
**name_table
;
78 #define DYNPROP_DELETED 0x01
82 IUnknown IUnknown_iface
;
89 func_disp_t
*func_obj
;
93 struct dispex_dynamic_data_t
{
96 dynamic_prop_t
*props
;
97 func_obj_entry_t
*func_disps
;
100 #define DISPID_DYNPROP_0 0x50000000
101 #define DISPID_DYNPROP_MAX 0x5fffffff
103 #define FDEX_VERSION_MASK 0xf0000000
105 static ITypeLib
*typelib
;
106 static ITypeInfo
*typeinfos
[LAST_tid
];
107 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
109 static REFIID tid_ids
[] = {
110 #define XIID(iface) &IID_ ## iface,
111 #define XDIID(iface) &DIID_ ## iface,
117 static HRESULT
load_typelib(void)
122 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
124 ERR("LoadRegTypeLib failed: %08x\n", hres
);
128 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
129 ITypeLib_Release(tl
);
133 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
138 hres
= load_typelib();
142 if(!typeinfos
[tid
]) {
145 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
147 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_mshtml_guid(tid_ids
[tid
]), hres
);
151 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
152 ITypeInfo_Release(ti
);
155 *typeinfo
= typeinfos
[tid
];
159 void release_typelib(void)
164 while(!list_empty(&dispex_data_list
)) {
165 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
166 list_remove(&iter
->entry
);
168 for(i
=0; i
< iter
->func_cnt
; i
++)
169 SysFreeString(iter
->funcs
[i
].name
);
171 heap_free(iter
->funcs
);
172 heap_free(iter
->name_table
);
179 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
181 ITypeInfo_Release(typeinfos
[i
]);
183 ITypeLib_Release(typelib
);
184 DeleteCriticalSection(&cs_dispex_static_data
);
187 HRESULT
get_htmldoc_classinfo(ITypeInfo
**typeinfo
)
192 hres
= load_typelib();
196 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, &CLSID_HTMLDocument
, typeinfo
);
198 ERR("GetTypeInfoOfGuid failed: %08x\n", hres
);
202 /* Not all argument types are supported yet */
203 #define BUILTIN_ARG_TYPES_SWITCH \
204 CASE_VT(VT_I2, INT16, V_I2); \
205 CASE_VT(VT_I4, INT32, V_I4); \
206 CASE_VT(VT_R4, float, V_R4); \
207 CASE_VT(VT_BSTR, BSTR, V_BSTR); \
208 CASE_VT(VT_BOOL, VARIANT_BOOL, V_BOOL)
210 /* List all types used by IDispatchEx-based properties */
211 #define BUILTIN_TYPES_SWITCH \
212 BUILTIN_ARG_TYPES_SWITCH; \
213 CASE_VT(VT_VARIANT, VARIANT, *); \
214 CASE_VT(VT_PTR, void*, V_BYREF); \
215 CASE_VT(VT_UNKNOWN, IUnknown*, V_UNKNOWN); \
216 CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH)
218 static BOOL
is_arg_type_supported(VARTYPE vt
)
221 #define CASE_VT(x,a,b) case x: return TRUE
222 BUILTIN_ARG_TYPES_SWITCH
;
228 static void add_func_info(dispex_data_t
*data
, DWORD
*size
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
)
233 for(info
= data
->funcs
; info
< data
->funcs
+data
->func_cnt
; info
++) {
234 if(info
->id
== desc
->memid
) {
236 return; /* Duplicated in other interface */
241 if(info
== data
->funcs
+data
->func_cnt
) {
242 if(data
->func_cnt
== *size
)
243 data
->funcs
= heap_realloc_zero(data
->funcs
, (*size
<<= 1)*sizeof(func_info_t
));
244 info
= data
->funcs
+data
->func_cnt
;
246 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &info
->name
, NULL
, NULL
, NULL
);
252 info
->id
= desc
->memid
;
254 info
->func_disp_idx
= -1;
255 info
->prop_vt
= VT_EMPTY
;
258 if(desc
->invkind
& DISPATCH_METHOD
) {
261 info
->func_disp_idx
= data
->func_disp_cnt
++;
262 info
->argc
= desc
->cParams
;
264 assert(info
->argc
< MAX_ARGS
);
265 assert(desc
->funckind
== FUNC_DISPATCH
);
267 info
->arg_types
= heap_alloc(sizeof(*info
->arg_types
) * info
->argc
);
269 return; /* FIXME: real error instead of fallback */
271 for(i
=0; i
< info
->argc
; i
++)
272 info
->arg_types
[i
] = desc
->lprgelemdescParam
[i
].tdesc
.vt
;
274 info
->prop_vt
= desc
->elemdescFunc
.tdesc
.vt
;
275 if(info
->prop_vt
!= VT_VOID
&& !is_arg_type_supported(info
->prop_vt
)) {
276 TRACE("%s: return type %d\n", debugstr_w(info
->name
), info
->prop_vt
);
277 return; /* Fallback to ITypeInfo::Invoke */
280 if(desc
->cParamsOpt
) {
281 TRACE("%s: optional params\n", debugstr_w(info
->name
));
282 return; /* Fallback to ITypeInfo::Invoke */
285 for(i
=0; i
< info
->argc
; i
++) {
286 if(!is_arg_type_supported(info
->arg_types
[i
])) {
287 return; /* Fallback to ITypeInfo for unsupported arg types */
290 if(desc
->lprgelemdescParam
[i
].u
.paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
) {
291 TRACE("%s param %d: default value\n", debugstr_w(info
->name
), i
);
292 return; /* Fallback to ITypeInfo::Invoke */
296 assert(info
->argc
<= MAX_ARGS
);
297 assert(desc
->callconv
== CC_STDCALL
);
299 info
->call_vtbl_off
= desc
->oVft
/sizeof(void*);
300 }else if(desc
->invkind
& (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYGET
)) {
301 VARTYPE vt
= VT_EMPTY
;
303 if(desc
->invkind
& DISPATCH_PROPERTYGET
) {
304 vt
= desc
->elemdescFunc
.tdesc
.vt
;
305 info
->get_vtbl_off
= desc
->oVft
/sizeof(void*);
307 if(desc
->invkind
& DISPATCH_PROPERTYPUT
) {
308 assert(desc
->cParams
== 1);
309 vt
= desc
->lprgelemdescParam
->tdesc
.vt
;
310 info
->put_vtbl_off
= desc
->oVft
/sizeof(void*);
313 assert(info
->prop_vt
== VT_EMPTY
|| vt
== info
->prop_vt
);
318 static HRESULT
process_interface(dispex_data_t
*data
, tid_t tid
, ITypeInfo
*disp_typeinfo
, DWORD
*size
)
320 unsigned i
= 7; /* skip IDispatch functions */
325 hres
= get_typeinfo(tid
, &typeinfo
);
330 hres
= ITypeInfo_GetFuncDesc(typeinfo
, i
++, &funcdesc
);
334 TRACE("adding...\n");
336 add_func_info(data
, size
, tid
, funcdesc
, disp_typeinfo
? disp_typeinfo
: typeinfo
);
337 ITypeInfo_ReleaseFuncDesc(typeinfo
, funcdesc
);
343 static int dispid_cmp(const void *p1
, const void *p2
)
345 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
348 static int func_name_cmp(const void *p1
, const void *p2
)
350 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
353 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
361 TRACE("(%p)\n", This
);
363 if(This
->data
->disp_tid
) {
364 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
366 ERR("Could not get disp type info: %08x\n", hres
);
371 data
= heap_alloc(sizeof(dispex_data_t
));
373 ERR("Out of memory\n");
377 data
->func_disp_cnt
= 0;
378 data
->funcs
= heap_alloc_zero(size
*sizeof(func_info_t
));
381 ERR("Out of memory\n");
384 list_add_tail(&dispex_data_list
, &data
->entry
);
386 for(tid
= This
->data
->iface_tids
; *tid
; tid
++) {
387 hres
= process_interface(data
, *tid
, dti
, &size
);
392 if(This
->data
->additional_tid
)
393 process_interface(data
, This
->data
->additional_tid
, NULL
, &size
);
395 if(!data
->func_cnt
) {
396 heap_free(data
->funcs
);
397 data
->name_table
= NULL
;
403 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
404 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
406 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
407 for(i
=0; i
< data
->func_cnt
; i
++)
408 data
->name_table
[i
] = data
->funcs
+i
;
409 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
413 static int id_cmp(const void *p1
, const void *p2
)
415 return *(const DISPID
*)p1
- *(const DISPID
*)p2
;
418 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
420 unsigned i
, func_cnt
;
427 hres
= get_typeinfo(tid
, &ti
);
431 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
433 ITypeInfo_Release(ti
);
437 func_cnt
= attr
->cFuncs
;
438 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
440 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
442 ITypeInfo_Release(ti
);
443 return E_OUTOFMEMORY
;
446 for(i
=0; i
< func_cnt
; i
++) {
447 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
451 ids
[i
] = funcdesc
->memid
;
452 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
455 ITypeInfo_Release(ti
);
461 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
463 *ret_size
= func_cnt
;
468 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
471 return This
->data
->data
;
473 EnterCriticalSection(&cs_dispex_static_data
);
475 if(!This
->data
->data
)
476 This
->data
->data
= preprocess_dispex_data(This
);
478 LeaveCriticalSection(&cs_dispex_static_data
);
480 return This
->data
->data
;
483 static inline BOOL
is_custom_dispid(DISPID id
)
485 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
488 static inline BOOL
is_dynamic_dispid(DISPID id
)
490 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
493 dispex_prop_type_t
get_dispid_type(DISPID id
)
495 if(is_dynamic_dispid(id
))
496 return DISPEXPROP_DYNAMIC
;
497 if(is_custom_dispid(id
))
498 return DISPEXPROP_CUSTOM
;
499 return DISPEXPROP_BUILTIN
;
502 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
504 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
505 V_VT(dest
) = VT_BSTR
;
510 return VariantCopy(dest
, src
);
513 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
)
515 if(This
->dynamic_data
)
516 return This
->dynamic_data
;
518 This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
));
519 if(!This
->dynamic_data
)
522 if(This
->data
->vtbl
&& This
->data
->vtbl
->populate_props
)
523 This
->data
->vtbl
->populate_props(This
);
525 return This
->dynamic_data
;
528 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
530 const BOOL alloc
= flags
& fdexNameEnsure
;
531 dispex_dynamic_data_t
*data
;
532 dynamic_prop_t
*prop
;
534 data
= get_dynamic_data(This
);
536 return E_OUTOFMEMORY
;
538 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
539 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
540 if(prop
->flags
& DYNPROP_DELETED
) {
542 return DISP_E_UNKNOWNNAME
;
543 prop
->flags
&= ~DYNPROP_DELETED
;
551 return DISP_E_UNKNOWNNAME
;
553 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
555 if(!data
->buf_size
) {
556 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
558 return E_OUTOFMEMORY
;
560 }else if(data
->buf_size
== data
->prop_cnt
) {
561 dynamic_prop_t
*new_props
;
563 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
565 return E_OUTOFMEMORY
;
567 data
->props
= new_props
;
568 data
->buf_size
<<= 1;
571 prop
= data
->props
+ data
->prop_cnt
;
573 prop
->name
= heap_strdupW(name
);
575 return E_OUTOFMEMORY
;
577 VariantInit(&prop
->var
);
584 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
586 dynamic_prop_t
*prop
;
589 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
597 HRESULT
dispex_get_dynid(DispatchEx
*This
, const WCHAR
*name
, DISPID
*id
)
599 dynamic_prop_t
*prop
;
602 hres
= get_dynamic_prop(This
, name
, fdexNameEnsure
, &prop
);
606 *id
= DISPID_DYNPROP_0
+ (prop
- This
->dynamic_data
->props
);
610 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
611 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
613 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
614 return This
->data
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
617 case DISPATCH_PROPERTYGET
:
619 V_BSTR(res
) = SysAllocString(objectW
);
621 return E_OUTOFMEMORY
;
624 FIXME("Unimplemented flags %x\n", flags
);
631 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
634 DISPPARAMS params
= {dp
->rgvarg
+dp
->cNamedArgs
, NULL
, dp
->cArgs
-dp
->cNamedArgs
, 0};
640 hres
= get_typeinfo(func
->tid
, &ti
);
642 ERR("Could not get type info: %08x\n", hres
);
646 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
648 ERR("Could not get iface %s: %08x\n", debugstr_mshtml_guid(tid_ids
[func
->tid
]), hres
);
652 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, ¶ms
, res
, ei
, &argerr
);
654 IUnknown_Release(unk
);
658 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
660 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
663 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
665 func_disp_t
*This
= impl_from_IUnknown(iface
);
667 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
669 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
670 *ppv
= &This
->IUnknown_iface
;
671 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
672 return *ppv
? S_OK
: E_NOINTERFACE
;
675 return E_NOINTERFACE
;
678 IUnknown_AddRef((IUnknown
*)*ppv
);
682 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
684 func_disp_t
*This
= impl_from_IUnknown(iface
);
685 LONG ref
= InterlockedIncrement(&This
->ref
);
687 TRACE("(%p) ref=%d\n", This
, ref
);
692 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
694 func_disp_t
*This
= impl_from_IUnknown(iface
);
695 LONG ref
= InterlockedDecrement(&This
->ref
);
697 TRACE("(%p) ref=%d\n", This
, ref
);
701 release_dispex(&This
->dispex
);
708 static const IUnknownVtbl FunctionUnkVtbl
= {
709 Function_QueryInterface
,
714 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
716 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
719 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
720 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
722 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
726 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
730 case DISPATCH_METHOD
:
733 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
735 case DISPATCH_PROPERTYGET
: {
740 static const WCHAR func_prefixW
[] =
741 {'\n','f','u','n','c','t','i','o','n',' '};
742 static const WCHAR func_suffixW
[] =
743 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
745 /* FIXME: This probably should be more generic. Also we should try to get IID_IActiveScriptSite and SID_GetCaller. */
747 return E_ACCESSDENIED
;
749 name_len
= SysStringLen(This
->info
->name
);
750 ptr
= str
= SysAllocStringLen(NULL
, name_len
+ (sizeof(func_prefixW
)+sizeof(func_suffixW
))/sizeof(WCHAR
));
752 return E_OUTOFMEMORY
;
754 memcpy(ptr
, func_prefixW
, sizeof(func_prefixW
));
755 ptr
+= sizeof(func_prefixW
)/sizeof(WCHAR
);
757 memcpy(ptr
, This
->info
->name
, name_len
*sizeof(WCHAR
));
760 memcpy(ptr
, func_suffixW
, sizeof(func_suffixW
));
767 FIXME("Unimplemented flags %x\n", flags
);
774 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
781 static const tid_t function_iface_tids
[] = {0};
783 static dispex_static_data_t function_dispex
= {
784 &function_dispex_vtbl
,
790 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
794 ret
= heap_alloc_zero(sizeof(func_disp_t
));
798 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
799 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
807 static HRESULT
invoke_disp_value(DispatchEx
*This
, IDispatch
*func_disp
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
808 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
810 DISPID named_arg
= DISPID_THIS
;
811 DISPPARAMS new_dp
= {NULL
, &named_arg
, 0, 1};
816 FIXME("named args not supported\n");
820 new_dp
.rgvarg
= heap_alloc((dp
->cArgs
+1)*sizeof(VARIANTARG
));
822 return E_OUTOFMEMORY
;
824 new_dp
.cArgs
= dp
->cArgs
+1;
825 memcpy(new_dp
.rgvarg
+1, dp
->rgvarg
, dp
->cArgs
*sizeof(VARIANTARG
));
827 V_VT(new_dp
.rgvarg
) = VT_DISPATCH
;
828 V_DISPATCH(new_dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
830 hres
= IDispatch_QueryInterface(func_disp
, &IID_IDispatchEx
, (void**)&dispex
);
832 if(SUCCEEDED(hres
)) {
833 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, flags
, &new_dp
, res
, ei
, caller
);
834 IDispatchEx_Release(dispex
);
837 hres
= IDispatch_Invoke(func_disp
, DISPID_VALUE
, &IID_NULL
, lcid
, flags
, &new_dp
, res
, ei
, &err
);
840 TRACE("<<< %s\n", debugstr_variant(res
));
842 WARN("<<< %08x\n", hres
);
844 heap_free(new_dp
.rgvarg
);
848 static HRESULT
get_func_obj_entry(DispatchEx
*This
, func_info_t
*func
, func_obj_entry_t
**ret
)
850 dispex_dynamic_data_t
*dynamic_data
;
851 func_obj_entry_t
*entry
;
853 dynamic_data
= get_dynamic_data(This
);
855 return E_OUTOFMEMORY
;
857 if(!dynamic_data
->func_disps
) {
858 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(*dynamic_data
->func_disps
));
859 if(!dynamic_data
->func_disps
)
860 return E_OUTOFMEMORY
;
863 entry
= dynamic_data
->func_disps
+ func
->func_disp_idx
;
864 if(!entry
->func_obj
) {
865 entry
->func_obj
= create_func_disp(This
, func
);
867 return E_OUTOFMEMORY
;
869 IDispatchEx_AddRef(&entry
->func_obj
->dispex
.IDispatchEx_iface
);
870 V_VT(&entry
->val
) = VT_DISPATCH
;
871 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
878 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
883 max
= data
->func_cnt
-1;
888 if(data
->funcs
[n
].id
== id
) {
889 *ret
= data
->funcs
+n
;
893 if(data
->funcs
[n
].id
< id
)
899 WARN("invalid id %x\n", id
);
900 return DISP_E_UNKNOWNNAME
;
903 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
908 data
= get_dispex_data(This
);
913 max
= data
->func_cnt
-1;
918 c
= strcmpiW(data
->name_table
[n
]->name
, name
);
920 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, name
))
923 *ret
= data
->name_table
[n
]->id
;
933 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
936 hres
= This
->data
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
937 if(hres
!= DISP_E_UNKNOWNNAME
)
941 return DISP_E_UNKNOWNNAME
;
944 static HRESULT
change_type(VARIANT
*dst
, VARIANT
*src
, VARTYPE vt
, IServiceProvider
*caller
)
946 V_VT(dst
) = VT_EMPTY
;
949 IVariantChangeType
*change_type
= NULL
;
952 hres
= IServiceProvider_QueryService(caller
, &SID_VariantConversion
, &IID_IVariantChangeType
, (void**)&change_type
);
953 if(SUCCEEDED(hres
)) {
954 hres
= IVariantChangeType_ChangeType(change_type
, dst
, src
, LOCALE_NEUTRAL
, vt
);
955 IVariantChangeType_Release(change_type
);
962 if(V_VT(src
) == VT_BSTR
) {
964 V_BOOL(dst
) = V_BSTR(src
) && *V_BSTR(src
) ? VARIANT_TRUE
: VARIANT_FALSE
;
970 return VariantChangeType(dst
, src
, 0, vt
);
973 static HRESULT
builtin_propget(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
)
978 if(dp
&& dp
->cArgs
) {
979 FIXME("cArgs %d\n", dp
->cArgs
);
983 assert(func
->get_vtbl_off
);
985 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
986 if(SUCCEEDED(hres
)) {
987 switch(func
->prop_vt
) {
988 #define CASE_VT(vt,type,access) \
991 hres = ((HRESULT (WINAPI*)(IUnknown*,type*))((void**)iface->lpVtbl)[func->get_vtbl_off])(iface,&val); \
992 if(SUCCEEDED(hres)) \
996 BUILTIN_TYPES_SWITCH
;
999 FIXME("Unhandled vt %d\n", func
->prop_vt
);
1002 IUnknown_Release(iface
);
1008 if(func
->prop_vt
!= VT_VARIANT
)
1009 V_VT(res
) = func
->prop_vt
== VT_PTR
? VT_DISPATCH
: func
->prop_vt
;
1013 static HRESULT
builtin_propput(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, IServiceProvider
*caller
)
1019 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1020 || dp
->cNamedArgs
> 1) {
1021 FIXME("invalid args\n");
1022 return E_INVALIDARG
;
1025 if(!func
->put_vtbl_off
) {
1026 FIXME("No setter\n");
1031 if(func
->prop_vt
!= VT_VARIANT
&& V_VT(v
) != func
->prop_vt
) {
1032 hres
= change_type(&tmpv
, v
, func
->prop_vt
, caller
);
1038 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1039 if(SUCCEEDED(hres
)) {
1040 switch(func
->prop_vt
) {
1041 #define CASE_VT(vt,type,access) \
1043 hres = ((HRESULT (WINAPI*)(IUnknown*,type))((void**)iface->lpVtbl)[func->put_vtbl_off])(iface,access(v)); \
1045 BUILTIN_TYPES_SWITCH
;
1048 FIXME("Unimplemented vt %d\n", func
->prop_vt
);
1052 IUnknown_Release(iface
);
1060 static HRESULT
invoke_builtin_function(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
, IServiceProvider
*caller
)
1062 VARIANT arg_buf
[MAX_ARGS
], *arg_ptrs
[MAX_ARGS
], *arg
, retv
, ret_ref
, vhres
;
1063 unsigned i
, nconv
= 0;
1067 if(dp
->cNamedArgs
) {
1068 FIXME("Named arguments not supported\n");
1072 if(dp
->cArgs
!= func
->argc
) {
1073 FIXME("Invalid argument count (expected %u, got %u)\n", func
->argc
, dp
->cArgs
);
1074 return E_INVALIDARG
;
1077 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1081 for(i
=0; i
< func
->argc
; i
++) {
1082 arg
= dp
->rgvarg
+dp
->cArgs
-i
-1;
1083 if(func
->arg_types
[i
] == V_VT(arg
)) {
1086 hres
= change_type(arg_buf
+nconv
, arg
, func
->arg_types
[i
], caller
);
1089 arg_ptrs
[i
] = arg_buf
+ nconv
++;
1093 if(SUCCEEDED(hres
)) {
1094 if(func
->prop_vt
== VT_VOID
) {
1095 V_VT(&retv
) = VT_EMPTY
;
1097 V_VT(&retv
) = func
->prop_vt
;
1098 arg_ptrs
[func
->argc
] = &ret_ref
;
1099 V_VT(&ret_ref
) = VT_BYREF
|func
->prop_vt
;
1101 switch(func
->prop_vt
) {
1102 #define CASE_VT(vt,type,access) \
1104 V_BYREF(&ret_ref) = &access(&retv); \
1106 BUILTIN_TYPES_SWITCH
;
1113 V_VT(&vhres
) = VT_ERROR
;
1114 hres
= DispCallFunc(iface
, func
->call_vtbl_off
*sizeof(void*), CC_STDCALL
, VT_ERROR
,
1115 func
->argc
+ (func
->prop_vt
== VT_VOID
? 0 : 1), func
->arg_types
, arg_ptrs
, &vhres
);
1119 VariantClear(arg_buf
+nconv
);
1120 IUnknown_Release(iface
);
1123 if(FAILED(V_ERROR(&vhres
)))
1124 return V_ERROR(&vhres
);
1129 VariantClear(&retv
);
1130 return V_ERROR(&vhres
);
1133 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
1134 EXCEPINFO
*ei
, IServiceProvider
*caller
)
1139 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1141 return E_INVALIDARG
;
1143 case DISPATCH_METHOD
:
1144 if(This
->dynamic_data
&& This
->dynamic_data
->func_disps
1145 && This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1146 func_obj_entry_t
*entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1148 if(V_VT(&entry
->val
) != VT_DISPATCH
) {
1149 FIXME("calling %s not supported\n", debugstr_variant(&entry
->val
));
1153 if((IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
!= V_DISPATCH(&entry
->val
)) {
1154 if(!V_DISPATCH(&entry
->val
)) {
1155 FIXME("Calling null\n");
1159 hres
= invoke_disp_value(This
, V_DISPATCH(&entry
->val
), 0, flags
, dp
, res
, ei
, NULL
);
1164 if(func
->call_vtbl_off
)
1165 hres
= invoke_builtin_function(This
, func
, dp
, res
, caller
);
1167 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1169 case DISPATCH_PROPERTYGET
: {
1170 func_obj_entry_t
*entry
;
1172 if(func
->id
== DISPID_VALUE
) {
1175 ret
= SysAllocString(objectW
);
1177 return E_OUTOFMEMORY
;
1179 V_VT(res
) = VT_BSTR
;
1184 hres
= get_func_obj_entry(This
, func
, &entry
);
1188 V_VT(res
) = VT_EMPTY
;
1189 return VariantCopy(res
, &entry
->val
);
1191 case DISPATCH_PROPERTYPUT
: {
1192 func_obj_entry_t
*entry
;
1194 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1195 || dp
->cNamedArgs
> 1) {
1196 FIXME("invalid args\n");
1197 return E_INVALIDARG
;
1201 * NOTE: Although we have IDispatchEx tests showing, that it's not allowed to set
1202 * function property using InvokeEx, it's possible to do that from jscript.
1203 * Native probably uses some undocumented interface in this case, but it should
1204 * be fine for us to allow IDispatchEx handle that.
1206 hres
= get_func_obj_entry(This
, func
, &entry
);
1210 return VariantCopy(&entry
->val
, dp
->rgvarg
);
1213 FIXME("Unimplemented flags %x\n", flags
);
1220 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
1221 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1223 dispex_data_t
*data
;
1227 data
= get_dispex_data(This
);
1231 hres
= get_builtin_func(data
, id
, &func
);
1232 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
1233 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1237 if(func
->func_disp_idx
!= -1)
1238 return function_invoke(This
, func
, flags
, dp
, res
, ei
, caller
);
1241 case DISPATCH_PROPERTYPUT
:
1243 V_VT(res
) = VT_EMPTY
;
1244 hres
= builtin_propput(This
, func
, dp
, caller
);
1246 case DISPATCH_PROPERTYGET
:
1247 hres
= builtin_propget(This
, func
, dp
, res
);
1250 if(!func
->get_vtbl_off
) {
1251 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1255 hres
= builtin_propget(This
, func
, NULL
, &v
);
1259 if(flags
!= (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
) || dp
->cArgs
) {
1260 if(V_VT(&v
) != VT_DISPATCH
) {
1261 FIXME("Not a function %s flags %08x\n", debugstr_variant(&v
), flags
);
1266 hres
= invoke_disp_value(This
, V_DISPATCH(&v
), lcid
, flags
, dp
, res
, ei
, caller
);
1267 IDispatch_Release(V_DISPATCH(&v
));
1279 HRESULT
remove_attribute(DispatchEx
*This
, DISPID id
, VARIANT_BOOL
*success
)
1281 switch(get_dispid_type(id
)) {
1282 case DISPEXPROP_CUSTOM
:
1283 FIXME("DISPEXPROP_CUSTOM not supported\n");
1286 case DISPEXPROP_DYNAMIC
: {
1287 DWORD idx
= id
- DISPID_DYNPROP_0
;
1288 dynamic_prop_t
*prop
;
1290 prop
= This
->dynamic_data
->props
+idx
;
1291 VariantClear(&prop
->var
);
1292 prop
->flags
|= DYNPROP_DELETED
;
1293 *success
= VARIANT_TRUE
;
1296 case DISPEXPROP_BUILTIN
: {
1298 DISPPARAMS dp
= {&var
,NULL
,1,0};
1299 dispex_data_t
*data
;
1303 data
= get_dispex_data(This
);
1307 hres
= get_builtin_func(data
, id
, &func
);
1311 /* For builtin functions, we set their value to the original function. */
1312 if(func
->func_disp_idx
!= -1) {
1313 func_obj_entry_t
*entry
;
1315 if(!This
->dynamic_data
|| !This
->dynamic_data
->func_disps
1316 || !This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1317 *success
= VARIANT_FALSE
;
1321 entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1322 if(V_VT(&entry
->val
) == VT_DISPATCH
1323 && V_DISPATCH(&entry
->val
) == (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
) {
1324 *success
= VARIANT_FALSE
;
1328 VariantClear(&entry
->val
);
1329 V_VT(&entry
->val
) = VT_DISPATCH
;
1330 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
1331 IDispatch_AddRef(V_DISPATCH(&entry
->val
));
1332 *success
= VARIANT_TRUE
;
1336 V_VT(&var
) = VT_EMPTY
;
1337 hres
= builtin_propput(This
, func
, &dp
, NULL
);
1341 *success
= VARIANT_TRUE
;
1350 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
1352 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
1355 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1357 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1359 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1362 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
1364 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1366 return IUnknown_AddRef(This
->outer
);
1369 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
1371 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1373 return IUnknown_Release(This
->outer
);
1376 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
1378 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1380 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1386 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
1387 LCID lcid
, ITypeInfo
**ppTInfo
)
1389 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1392 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1394 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
1398 ITypeInfo_AddRef(*ppTInfo
);
1402 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
1403 LPOLESTR
*rgszNames
, UINT cNames
,
1404 LCID lcid
, DISPID
*rgDispId
)
1406 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1410 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1413 for(i
=0; i
< cNames
; i
++) {
1414 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
1422 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
1423 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1424 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1426 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1428 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1429 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1431 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
1432 pVarResult
, pExcepInfo
, NULL
);
1435 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
1437 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1438 dynamic_prop_t
*dprop
;
1441 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
1443 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
1444 FIXME("Unsupported grfdex %x\n", grfdex
);
1446 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
1447 if(hres
!= DISP_E_UNKNOWNNAME
)
1450 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
1454 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
1458 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1459 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
1461 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1464 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1466 if(wFlags
== (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
))
1467 wFlags
= DISPATCH_PROPERTYPUT
;
1469 switch(get_dispid_type(id
)) {
1470 case DISPEXPROP_CUSTOM
:
1471 if(!This
->data
->vtbl
|| !This
->data
->vtbl
->invoke
)
1472 return DISP_E_UNKNOWNNAME
;
1473 return This
->data
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1475 case DISPEXPROP_DYNAMIC
: {
1476 DWORD idx
= id
- DISPID_DYNPROP_0
;
1477 dynamic_prop_t
*prop
;
1479 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1480 return DISP_E_UNKNOWNNAME
;
1482 prop
= This
->dynamic_data
->props
+idx
;
1485 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1487 return E_INVALIDARG
;
1489 case DISPATCH_METHOD
:
1490 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
1491 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
1495 return invoke_disp_value(This
, V_DISPATCH(&prop
->var
), lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1496 case DISPATCH_PROPERTYGET
:
1497 if(prop
->flags
& DYNPROP_DELETED
)
1498 return DISP_E_UNKNOWNNAME
;
1499 V_VT(pvarRes
) = VT_EMPTY
;
1500 return variant_copy(pvarRes
, &prop
->var
);
1501 case DISPATCH_PROPERTYPUT
:
1502 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1503 || pdp
->cNamedArgs
> 1) {
1504 FIXME("invalid args\n");
1505 return E_INVALIDARG
;
1508 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
1509 VariantClear(&prop
->var
);
1510 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
1514 prop
->flags
&= ~DYNPROP_DELETED
;
1517 FIXME("unhandled wFlags %x\n", wFlags
);
1521 case DISPEXPROP_BUILTIN
:
1522 if(wFlags
== DISPATCH_CONSTRUCT
) {
1523 if(id
== DISPID_VALUE
) {
1524 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
1525 return This
->data
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1527 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
1530 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
1534 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1541 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1543 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1545 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1547 /* Not implemented by IE */
1551 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1553 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1555 TRACE("(%p)->(%x)\n", This
, id
);
1557 /* Not implemented by IE */
1561 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1563 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1564 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1568 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1570 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1571 dispex_data_t
*data
;
1575 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1577 if(is_dynamic_dispid(id
)) {
1578 DWORD idx
= id
- DISPID_DYNPROP_0
;
1580 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1581 return DISP_E_UNKNOWNNAME
;
1583 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1585 return E_OUTOFMEMORY
;
1590 data
= get_dispex_data(This
);
1594 hres
= get_builtin_func(data
, id
, &func
);
1598 *pbstrName
= SysAllocString(func
->name
);
1600 return E_OUTOFMEMORY
;
1604 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1606 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1607 dispex_data_t
*data
;
1611 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1613 if(is_dynamic_dispid(id
)) {
1614 DWORD idx
= id
- DISPID_DYNPROP_0
;
1616 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1617 return DISP_E_UNKNOWNNAME
;
1619 while(++idx
< This
->dynamic_data
->prop_cnt
&& This
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
);
1621 if(idx
== This
->dynamic_data
->prop_cnt
) {
1622 *pid
= DISPID_STARTENUM
;
1626 *pid
= DISPID_DYNPROP_0
+idx
;
1630 data
= get_dispex_data(This
);
1634 if(id
== DISPID_STARTENUM
) {
1637 hres
= get_builtin_func(data
, id
, &func
);
1643 while(func
< data
->funcs
+data
->func_cnt
) {
1644 /* FIXME: Skip hidden properties */
1645 if(func
->func_disp_idx
== -1) {
1652 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
) {
1653 *pid
= DISPID_DYNPROP_0
;
1657 *pid
= DISPID_STARTENUM
;
1661 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1663 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1664 FIXME("(%p)->(%p)\n", This
, ppunk
);
1668 static IDispatchExVtbl DispatchExVtbl
= {
1669 DispatchEx_QueryInterface
,
1672 DispatchEx_GetTypeInfoCount
,
1673 DispatchEx_GetTypeInfo
,
1674 DispatchEx_GetIDsOfNames
,
1676 DispatchEx_GetDispID
,
1677 DispatchEx_InvokeEx
,
1678 DispatchEx_DeleteMemberByName
,
1679 DispatchEx_DeleteMemberByDispID
,
1680 DispatchEx_GetMemberProperties
,
1681 DispatchEx_GetMemberName
,
1682 DispatchEx_GetNextDispID
,
1683 DispatchEx_GetNameSpaceParent
1686 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1688 if(IsEqualGUID(&IID_IDispatch
, riid
))
1689 *ppv
= &This
->IDispatchEx_iface
;
1690 else if(IsEqualGUID(&IID_IDispatchEx
, riid
))
1691 *ppv
= &This
->IDispatchEx_iface
;
1692 else if(IsEqualGUID(&IID_IDispatchJS
, riid
))
1694 else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
))
1700 IUnknown_AddRef((IUnknown
*)*ppv
);
1704 void dispex_traverse(DispatchEx
*This
, nsCycleCollectionTraversalCallback
*cb
)
1706 dynamic_prop_t
*prop
;
1708 if(!This
->dynamic_data
)
1711 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1712 if(V_VT(&prop
->var
) == VT_DISPATCH
)
1713 note_cc_edge((nsISupports
*)V_DISPATCH(&prop
->var
), "dispex_data", cb
);
1716 /* FIXME: Traverse func_disps */
1719 void dispex_unlink(DispatchEx
*This
)
1721 dynamic_prop_t
*prop
;
1723 if(!This
->dynamic_data
)
1726 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1727 if(V_VT(&prop
->var
) == VT_DISPATCH
) {
1728 V_VT(&prop
->var
) = VT_EMPTY
;
1729 IDispatch_Release(V_DISPATCH(&prop
->var
));
1731 VariantClear(&prop
->var
);
1736 void release_dispex(DispatchEx
*This
)
1738 dynamic_prop_t
*prop
;
1740 if(!This
->dynamic_data
)
1743 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1744 VariantClear(&prop
->var
);
1745 heap_free(prop
->name
);
1748 heap_free(This
->dynamic_data
->props
);
1750 if(This
->dynamic_data
->func_disps
) {
1751 func_obj_entry_t
*iter
;
1753 for(iter
= This
->dynamic_data
->func_disps
; iter
< This
->dynamic_data
->func_disps
+This
->data
->data
->func_disp_cnt
; iter
++) {
1754 if(iter
->func_obj
) {
1755 iter
->func_obj
->obj
= NULL
;
1756 IDispatchEx_Release(&iter
->func_obj
->dispex
.IDispatchEx_iface
);
1758 VariantClear(&iter
->val
);
1761 heap_free(This
->dynamic_data
->func_disps
);
1764 heap_free(This
->dynamic_data
);
1767 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1769 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1770 dispex
->outer
= outer
;
1771 dispex
->data
= data
;
1772 dispex
->dynamic_data
= NULL
;