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
));
245 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 int dispid_cmp(const void *p1
, const void *p2
)
320 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
323 static int func_name_cmp(const void *p1
, const void *p2
)
325 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
328 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
330 const tid_t
*tid
= This
->data
->iface_tids
;
337 TRACE("(%p)\n", This
);
339 if(This
->data
->disp_tid
) {
340 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
342 ERR("Could not get disp type info: %08x\n", hres
);
347 data
= heap_alloc(sizeof(dispex_data_t
));
349 ERR("Out of memory\n");
353 data
->func_disp_cnt
= 0;
354 data
->funcs
= heap_alloc_zero(size
*sizeof(func_info_t
));
357 ERR("Out of memory\n");
360 list_add_tail(&dispex_data_list
, &data
->entry
);
363 hres
= get_typeinfo(*tid
, &ti
);
369 hres
= ITypeInfo_GetFuncDesc(ti
, i
++, &funcdesc
);
373 add_func_info(data
, &size
, *tid
, funcdesc
, dti
);
374 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
380 if(!data
->func_cnt
) {
381 heap_free(data
->funcs
);
382 data
->name_table
= NULL
;
388 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
389 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
391 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
392 for(i
=0; i
< data
->func_cnt
; i
++)
393 data
->name_table
[i
] = data
->funcs
+i
;
394 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
399 static int id_cmp(const void *p1
, const void *p2
)
401 return *(const DISPID
*)p1
- *(const DISPID
*)p2
;
404 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
406 unsigned i
, func_cnt
;
413 hres
= get_typeinfo(tid
, &ti
);
417 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
419 ITypeInfo_Release(ti
);
423 func_cnt
= attr
->cFuncs
;
424 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
426 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
428 ITypeInfo_Release(ti
);
429 return E_OUTOFMEMORY
;
432 for(i
=0; i
< func_cnt
; i
++) {
433 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
437 ids
[i
] = funcdesc
->memid
;
438 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
441 ITypeInfo_Release(ti
);
447 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
449 *ret_size
= func_cnt
;
454 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
457 return This
->data
->data
;
459 EnterCriticalSection(&cs_dispex_static_data
);
461 if(!This
->data
->data
)
462 This
->data
->data
= preprocess_dispex_data(This
);
464 LeaveCriticalSection(&cs_dispex_static_data
);
466 return This
->data
->data
;
469 static inline BOOL
is_custom_dispid(DISPID id
)
471 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
474 static inline BOOL
is_dynamic_dispid(DISPID id
)
476 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
479 dispex_prop_type_t
get_dispid_type(DISPID id
)
481 if(is_dynamic_dispid(id
))
482 return DISPEXPROP_DYNAMIC
;
483 if(is_custom_dispid(id
))
484 return DISPEXPROP_CUSTOM
;
485 return DISPEXPROP_BUILTIN
;
488 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
490 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
491 V_VT(dest
) = VT_BSTR
;
496 return VariantCopy(dest
, src
);
499 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
)
501 if(This
->dynamic_data
)
502 return This
->dynamic_data
;
504 This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
));
505 if(!This
->dynamic_data
)
508 if(This
->data
->vtbl
&& This
->data
->vtbl
->populate_props
)
509 This
->data
->vtbl
->populate_props(This
);
511 return This
->dynamic_data
;
514 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
516 const BOOL alloc
= flags
& fdexNameEnsure
;
517 dispex_dynamic_data_t
*data
;
518 dynamic_prop_t
*prop
;
520 data
= get_dynamic_data(This
);
522 return E_OUTOFMEMORY
;
524 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
525 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
526 if(prop
->flags
& DYNPROP_DELETED
) {
528 return DISP_E_UNKNOWNNAME
;
529 prop
->flags
&= ~DYNPROP_DELETED
;
537 return DISP_E_UNKNOWNNAME
;
539 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
541 if(!data
->buf_size
) {
542 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
544 return E_OUTOFMEMORY
;
546 }else if(data
->buf_size
== data
->prop_cnt
) {
547 dynamic_prop_t
*new_props
;
549 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
551 return E_OUTOFMEMORY
;
553 data
->props
= new_props
;
554 data
->buf_size
<<= 1;
557 prop
= data
->props
+ data
->prop_cnt
;
559 prop
->name
= heap_strdupW(name
);
561 return E_OUTOFMEMORY
;
563 VariantInit(&prop
->var
);
570 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
572 dynamic_prop_t
*prop
;
575 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
583 HRESULT
dispex_get_dynid(DispatchEx
*This
, const WCHAR
*name
, DISPID
*id
)
585 dynamic_prop_t
*prop
;
588 hres
= get_dynamic_prop(This
, name
, fdexNameEnsure
, &prop
);
592 *id
= DISPID_DYNPROP_0
+ (prop
- This
->dynamic_data
->props
);
596 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
597 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
599 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
600 return This
->data
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
603 case DISPATCH_PROPERTYGET
:
605 V_BSTR(res
) = SysAllocString(objectW
);
607 return E_OUTOFMEMORY
;
610 FIXME("Unimplemented flags %x\n", flags
);
617 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
625 hres
= get_typeinfo(func
->tid
, &ti
);
627 ERR("Could not get type info: %08x\n", hres
);
631 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
633 ERR("Could not get iface %s: %08x\n", debugstr_mshtml_guid(tid_ids
[func
->tid
]), hres
);
637 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, dp
, res
, ei
, &argerr
);
639 IUnknown_Release(unk
);
643 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
645 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
648 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
650 func_disp_t
*This
= impl_from_IUnknown(iface
);
652 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
654 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
655 *ppv
= &This
->IUnknown_iface
;
656 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
657 return *ppv
? S_OK
: E_NOINTERFACE
;
660 return E_NOINTERFACE
;
663 IUnknown_AddRef((IUnknown
*)*ppv
);
667 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
669 func_disp_t
*This
= impl_from_IUnknown(iface
);
670 LONG ref
= InterlockedIncrement(&This
->ref
);
672 TRACE("(%p) ref=%d\n", This
, ref
);
677 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
679 func_disp_t
*This
= impl_from_IUnknown(iface
);
680 LONG ref
= InterlockedDecrement(&This
->ref
);
682 TRACE("(%p) ref=%d\n", This
, ref
);
686 release_dispex(&This
->dispex
);
693 static const IUnknownVtbl FunctionUnkVtbl
= {
694 Function_QueryInterface
,
699 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
701 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
704 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
705 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
707 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
711 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
715 case DISPATCH_METHOD
:
718 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
720 case DISPATCH_PROPERTYGET
: {
725 static const WCHAR func_prefixW
[] =
726 {'\n','f','u','n','c','t','i','o','n',' '};
727 static const WCHAR func_suffixW
[] =
728 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
730 /* FIXME: This probably should be more generic. Also we should try to get IID_IActiveScriptSite and SID_GetCaller. */
732 return E_ACCESSDENIED
;
734 name_len
= SysStringLen(This
->info
->name
);
735 ptr
= str
= SysAllocStringLen(NULL
, name_len
+ (sizeof(func_prefixW
)+sizeof(func_suffixW
))/sizeof(WCHAR
));
737 return E_OUTOFMEMORY
;
739 memcpy(ptr
, func_prefixW
, sizeof(func_prefixW
));
740 ptr
+= sizeof(func_prefixW
)/sizeof(WCHAR
);
742 memcpy(ptr
, This
->info
->name
, name_len
*sizeof(WCHAR
));
745 memcpy(ptr
, func_suffixW
, sizeof(func_suffixW
));
752 FIXME("Unimplemented flags %x\n", flags
);
759 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
766 static const tid_t function_iface_tids
[] = {0};
768 static dispex_static_data_t function_dispex
= {
769 &function_dispex_vtbl
,
775 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
779 ret
= heap_alloc_zero(sizeof(func_disp_t
));
783 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
784 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
792 static HRESULT
invoke_disp_value(DispatchEx
*This
, IDispatch
*func_disp
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
793 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
795 DISPID named_arg
= DISPID_THIS
;
796 DISPPARAMS new_dp
= {NULL
, &named_arg
, 0, 1};
801 FIXME("named args not supported\n");
805 new_dp
.rgvarg
= heap_alloc((dp
->cArgs
+1)*sizeof(VARIANTARG
));
807 return E_OUTOFMEMORY
;
809 new_dp
.cArgs
= dp
->cArgs
+1;
810 memcpy(new_dp
.rgvarg
+1, dp
->rgvarg
, dp
->cArgs
*sizeof(VARIANTARG
));
812 V_VT(new_dp
.rgvarg
) = VT_DISPATCH
;
813 V_DISPATCH(new_dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
815 hres
= IDispatch_QueryInterface(func_disp
, &IID_IDispatchEx
, (void**)&dispex
);
817 if(SUCCEEDED(hres
)) {
818 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, flags
, &new_dp
, res
, ei
, caller
);
819 IDispatchEx_Release(dispex
);
822 hres
= IDispatch_Invoke(func_disp
, DISPID_VALUE
, &IID_NULL
, lcid
, flags
, &new_dp
, res
, ei
, &err
);
825 TRACE("<<< %s\n", debugstr_variant(res
));
827 WARN("<<< %08x\n", hres
);
829 heap_free(new_dp
.rgvarg
);
833 static HRESULT
get_func_obj_entry(DispatchEx
*This
, func_info_t
*func
, func_obj_entry_t
**ret
)
835 dispex_dynamic_data_t
*dynamic_data
;
836 func_obj_entry_t
*entry
;
838 dynamic_data
= get_dynamic_data(This
);
840 return E_OUTOFMEMORY
;
842 if(!dynamic_data
->func_disps
) {
843 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(*dynamic_data
->func_disps
));
844 if(!dynamic_data
->func_disps
)
845 return E_OUTOFMEMORY
;
848 entry
= dynamic_data
->func_disps
+ func
->func_disp_idx
;
849 if(!entry
->func_obj
) {
850 entry
->func_obj
= create_func_disp(This
, func
);
852 return E_OUTOFMEMORY
;
854 IDispatchEx_AddRef(&entry
->func_obj
->dispex
.IDispatchEx_iface
);
855 V_VT(&entry
->val
) = VT_DISPATCH
;
856 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
863 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
868 max
= data
->func_cnt
-1;
873 if(data
->funcs
[n
].id
== id
) {
874 *ret
= data
->funcs
+n
;
878 if(data
->funcs
[n
].id
< id
)
884 WARN("invalid id %x\n", id
);
885 return DISP_E_UNKNOWNNAME
;
888 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
893 data
= get_dispex_data(This
);
898 max
= data
->func_cnt
-1;
903 c
= strcmpiW(data
->name_table
[n
]->name
, name
);
905 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, name
))
908 *ret
= data
->name_table
[n
]->id
;
918 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
921 hres
= This
->data
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
922 if(hres
!= DISP_E_UNKNOWNNAME
)
926 return DISP_E_UNKNOWNNAME
;
929 static HRESULT
change_type(VARIANT
*dst
, VARIANT
*src
, VARTYPE vt
, IServiceProvider
*caller
)
931 V_VT(dst
) = VT_EMPTY
;
934 IVariantChangeType
*change_type
= NULL
;
937 hres
= IServiceProvider_QueryService(caller
, &SID_VariantConversion
, &IID_IVariantChangeType
, (void**)&change_type
);
938 if(SUCCEEDED(hres
)) {
939 hres
= IVariantChangeType_ChangeType(change_type
, dst
, src
, LOCALE_NEUTRAL
, vt
);
940 IVariantChangeType_Release(change_type
);
947 if(V_VT(src
) == VT_BSTR
) {
949 V_BOOL(dst
) = V_BSTR(src
) && *V_BSTR(src
) ? VARIANT_TRUE
: VARIANT_FALSE
;
955 return VariantChangeType(dst
, src
, 0, vt
);
958 static HRESULT
builtin_propget(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
)
963 if(dp
&& dp
->cArgs
) {
964 FIXME("cArgs %d\n", dp
->cArgs
);
968 assert(func
->get_vtbl_off
);
970 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
971 if(SUCCEEDED(hres
)) {
972 switch(func
->prop_vt
) {
973 #define CASE_VT(vt,type,access) \
976 hres = ((HRESULT (WINAPI*)(IUnknown*,type*))((void**)iface->lpVtbl)[func->get_vtbl_off])(iface,&val); \
977 if(SUCCEEDED(hres)) \
981 BUILTIN_TYPES_SWITCH
;
984 FIXME("Unhandled vt %d\n", func
->prop_vt
);
987 IUnknown_Release(iface
);
993 if(func
->prop_vt
!= VT_VARIANT
)
994 V_VT(res
) = func
->prop_vt
== VT_PTR
? VT_DISPATCH
: func
->prop_vt
;
998 static HRESULT
builtin_propput(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, IServiceProvider
*caller
)
1004 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1005 || dp
->cNamedArgs
> 1) {
1006 FIXME("invalid args\n");
1007 return E_INVALIDARG
;
1010 if(!func
->put_vtbl_off
) {
1011 FIXME("No setter\n");
1016 if(func
->prop_vt
!= VT_VARIANT
&& V_VT(v
) != func
->prop_vt
) {
1017 hres
= change_type(&tmpv
, v
, func
->prop_vt
, caller
);
1023 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1024 if(SUCCEEDED(hres
)) {
1025 switch(func
->prop_vt
) {
1026 #define CASE_VT(vt,type,access) \
1028 hres = ((HRESULT (WINAPI*)(IUnknown*,type))((void**)iface->lpVtbl)[func->put_vtbl_off])(iface,access(v)); \
1030 BUILTIN_TYPES_SWITCH
;
1033 FIXME("Unimplemented vt %d\n", func
->prop_vt
);
1037 IUnknown_Release(iface
);
1045 static HRESULT
invoke_builtin_function(DispatchEx
*This
, func_info_t
*func
, DISPPARAMS
*dp
, VARIANT
*res
, IServiceProvider
*caller
)
1047 VARIANT arg_buf
[MAX_ARGS
], *arg_ptrs
[MAX_ARGS
], *arg
, retv
, ret_ref
, vhres
;
1048 unsigned i
, nconv
= 0;
1052 if(dp
->cNamedArgs
) {
1053 FIXME("Named arguments not supported\n");
1057 if(dp
->cArgs
!= func
->argc
) {
1058 FIXME("Invalid argument count (expected %u, got %u)\n", func
->argc
, dp
->cArgs
);
1059 return E_INVALIDARG
;
1062 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&iface
);
1066 for(i
=0; i
< func
->argc
; i
++) {
1067 arg
= dp
->rgvarg
+dp
->cArgs
-i
-1;
1068 if(func
->arg_types
[i
] == V_VT(arg
)) {
1071 hres
= change_type(arg_buf
+nconv
, arg
, func
->arg_types
[i
], caller
);
1074 arg_ptrs
[i
] = arg_buf
+ nconv
++;
1078 if(SUCCEEDED(hres
)) {
1079 if(func
->prop_vt
== VT_VOID
) {
1080 V_VT(&retv
) = VT_EMPTY
;
1082 V_VT(&retv
) = func
->prop_vt
;
1083 arg_ptrs
[func
->argc
] = &ret_ref
;
1084 V_VT(&ret_ref
) = VT_BYREF
|func
->prop_vt
;
1086 switch(func
->prop_vt
) {
1087 #define CASE_VT(vt,type,access) \
1089 V_BYREF(&ret_ref) = &access(&retv); \
1091 BUILTIN_TYPES_SWITCH
;
1098 V_VT(&vhres
) = VT_ERROR
;
1099 hres
= DispCallFunc(iface
, func
->call_vtbl_off
*sizeof(void*), CC_STDCALL
, VT_ERROR
,
1100 func
->argc
+ (func
->prop_vt
== VT_VOID
? 0 : 1), func
->arg_types
, arg_ptrs
, &vhres
);
1104 VariantClear(arg_buf
+nconv
);
1105 IUnknown_Release(iface
);
1108 if(FAILED(V_ERROR(&vhres
)))
1109 return V_ERROR(&vhres
);
1114 VariantClear(&retv
);
1115 return V_ERROR(&vhres
);
1118 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
1119 EXCEPINFO
*ei
, IServiceProvider
*caller
)
1124 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1126 return E_INVALIDARG
;
1128 case DISPATCH_METHOD
:
1129 if(This
->dynamic_data
&& This
->dynamic_data
->func_disps
1130 && This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1131 func_obj_entry_t
*entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1133 if(V_VT(&entry
->val
) != VT_DISPATCH
) {
1134 FIXME("calling %s not supported\n", debugstr_variant(&entry
->val
));
1138 if((IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
!= V_DISPATCH(&entry
->val
)) {
1139 if(!V_DISPATCH(&entry
->val
)) {
1140 FIXME("Calling null\n");
1144 hres
= invoke_disp_value(This
, V_DISPATCH(&entry
->val
), 0, flags
, dp
, res
, ei
, NULL
);
1149 if(func
->call_vtbl_off
)
1150 hres
= invoke_builtin_function(This
, func
, dp
, res
, caller
);
1152 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1154 case DISPATCH_PROPERTYGET
: {
1155 func_obj_entry_t
*entry
;
1157 if(func
->id
== DISPID_VALUE
) {
1160 ret
= SysAllocString(objectW
);
1162 return E_OUTOFMEMORY
;
1164 V_VT(res
) = VT_BSTR
;
1169 hres
= get_func_obj_entry(This
, func
, &entry
);
1173 V_VT(res
) = VT_EMPTY
;
1174 return VariantCopy(res
, &entry
->val
);
1176 case DISPATCH_PROPERTYPUT
: {
1177 func_obj_entry_t
*entry
;
1179 if(dp
->cArgs
!= 1 || (dp
->cNamedArgs
== 1 && *dp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1180 || dp
->cNamedArgs
> 1) {
1181 FIXME("invalid args\n");
1182 return E_INVALIDARG
;
1186 * NOTE: Although we have IDispatchEx tests showing, that it's not allowed to set
1187 * function property using InvokeEx, it's possible to do that from jscript.
1188 * Native probably uses some undocumented interface in this case, but it should
1189 * be fine for us to allow IDispatchEx handle that.
1191 hres
= get_func_obj_entry(This
, func
, &entry
);
1195 return VariantCopy(&entry
->val
, dp
->rgvarg
);
1198 FIXME("Unimplemented flags %x\n", flags
);
1205 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
1206 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1208 dispex_data_t
*data
;
1212 data
= get_dispex_data(This
);
1216 hres
= get_builtin_func(data
, id
, &func
);
1217 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
1218 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
1222 if(func
->func_disp_idx
!= -1)
1223 return function_invoke(This
, func
, flags
, dp
, res
, ei
, caller
);
1226 case DISPATCH_PROPERTYPUT
:
1228 V_VT(res
) = VT_EMPTY
;
1229 hres
= builtin_propput(This
, func
, dp
, caller
);
1231 case DISPATCH_PROPERTYGET
:
1232 hres
= builtin_propget(This
, func
, dp
, res
);
1235 if(!func
->get_vtbl_off
) {
1236 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
1240 hres
= builtin_propget(This
, func
, NULL
, &v
);
1244 if(flags
!= (DISPATCH_PROPERTYGET
|DISPATCH_METHOD
) || dp
->cArgs
) {
1245 if(V_VT(&v
) != VT_DISPATCH
) {
1246 FIXME("Not a function %s flags %08x\n", debugstr_variant(&v
), flags
);
1251 hres
= invoke_disp_value(This
, V_DISPATCH(&v
), lcid
, flags
, dp
, res
, ei
, caller
);
1252 IDispatch_Release(V_DISPATCH(&v
));
1264 HRESULT
remove_attribute(DispatchEx
*This
, DISPID id
, VARIANT_BOOL
*success
)
1266 switch(get_dispid_type(id
)) {
1267 case DISPEXPROP_CUSTOM
:
1268 FIXME("DISPEXPROP_CUSTOM not supported\n");
1271 case DISPEXPROP_DYNAMIC
: {
1272 DWORD idx
= id
- DISPID_DYNPROP_0
;
1273 dynamic_prop_t
*prop
;
1275 prop
= This
->dynamic_data
->props
+idx
;
1276 VariantClear(&prop
->var
);
1277 prop
->flags
|= DYNPROP_DELETED
;
1278 *success
= VARIANT_TRUE
;
1281 case DISPEXPROP_BUILTIN
: {
1283 DISPPARAMS dp
= {&var
,NULL
,1,0};
1284 dispex_data_t
*data
;
1288 data
= get_dispex_data(This
);
1292 hres
= get_builtin_func(data
, id
, &func
);
1296 /* For builtin functions, we set their value to the original function. */
1297 if(func
->func_disp_idx
!= -1) {
1298 func_obj_entry_t
*entry
;
1300 if(!This
->dynamic_data
|| !This
->dynamic_data
->func_disps
1301 || !This
->dynamic_data
->func_disps
[func
->func_disp_idx
].func_obj
) {
1302 *success
= VARIANT_FALSE
;
1306 entry
= This
->dynamic_data
->func_disps
+ func
->func_disp_idx
;
1307 if(V_VT(&entry
->val
) == VT_DISPATCH
1308 && V_DISPATCH(&entry
->val
) == (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
) {
1309 *success
= VARIANT_FALSE
;
1313 VariantClear(&entry
->val
);
1314 V_VT(&entry
->val
) = VT_DISPATCH
;
1315 V_DISPATCH(&entry
->val
) = (IDispatch
*)&entry
->func_obj
->dispex
.IDispatchEx_iface
;
1316 IDispatch_AddRef(V_DISPATCH(&entry
->val
));
1317 *success
= VARIANT_TRUE
;
1321 V_VT(&var
) = VT_EMPTY
;
1322 hres
= builtin_propput(This
, func
, &dp
, NULL
);
1326 *success
= VARIANT_TRUE
;
1335 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
1337 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
1340 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
1342 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1344 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
1347 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
1349 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1351 return IUnknown_AddRef(This
->outer
);
1354 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
1356 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1358 return IUnknown_Release(This
->outer
);
1361 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
1363 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1365 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1371 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
1372 LCID lcid
, ITypeInfo
**ppTInfo
)
1374 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1377 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1379 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
1383 ITypeInfo_AddRef(*ppTInfo
);
1387 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
1388 LPOLESTR
*rgszNames
, UINT cNames
,
1389 LCID lcid
, DISPID
*rgDispId
)
1391 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1395 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1398 for(i
=0; i
< cNames
; i
++) {
1399 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
1407 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
1408 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1409 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1411 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1413 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1414 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1416 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
1417 pVarResult
, pExcepInfo
, NULL
);
1420 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
1422 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1423 dynamic_prop_t
*dprop
;
1426 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
1428 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
1429 FIXME("Unsupported grfdex %x\n", grfdex
);
1431 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
1432 if(hres
!= DISP_E_UNKNOWNNAME
)
1435 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
1439 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
1443 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1444 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
1446 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1449 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1451 if(wFlags
== (DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
))
1452 wFlags
= DISPATCH_PROPERTYPUT
;
1454 switch(get_dispid_type(id
)) {
1455 case DISPEXPROP_CUSTOM
:
1456 if(!This
->data
->vtbl
|| !This
->data
->vtbl
->invoke
)
1457 return DISP_E_UNKNOWNNAME
;
1458 return This
->data
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1460 case DISPEXPROP_DYNAMIC
: {
1461 DWORD idx
= id
- DISPID_DYNPROP_0
;
1462 dynamic_prop_t
*prop
;
1464 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1465 return DISP_E_UNKNOWNNAME
;
1467 prop
= This
->dynamic_data
->props
+idx
;
1470 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
1472 return E_INVALIDARG
;
1474 case DISPATCH_METHOD
:
1475 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
1476 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
1480 return invoke_disp_value(This
, V_DISPATCH(&prop
->var
), lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1481 case DISPATCH_PROPERTYGET
:
1482 if(prop
->flags
& DYNPROP_DELETED
)
1483 return DISP_E_UNKNOWNNAME
;
1484 V_VT(pvarRes
) = VT_EMPTY
;
1485 return variant_copy(pvarRes
, &prop
->var
);
1486 case DISPATCH_PROPERTYPUT
:
1487 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
1488 || pdp
->cNamedArgs
> 1) {
1489 FIXME("invalid args\n");
1490 return E_INVALIDARG
;
1493 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
1494 VariantClear(&prop
->var
);
1495 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
1499 prop
->flags
&= ~DYNPROP_DELETED
;
1502 FIXME("unhandled wFlags %x\n", wFlags
);
1506 case DISPEXPROP_BUILTIN
:
1507 if(wFlags
== DISPATCH_CONSTRUCT
) {
1508 if(id
== DISPID_VALUE
) {
1509 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
1510 return This
->data
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1512 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
1515 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
1519 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1526 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1528 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1530 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1532 /* Not implemented by IE */
1536 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1538 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1540 TRACE("(%p)->(%x)\n", This
, id
);
1542 /* Not implemented by IE */
1546 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1548 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1549 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1553 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1555 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1556 dispex_data_t
*data
;
1560 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1562 if(is_dynamic_dispid(id
)) {
1563 DWORD idx
= id
- DISPID_DYNPROP_0
;
1565 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1566 return DISP_E_UNKNOWNNAME
;
1568 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1570 return E_OUTOFMEMORY
;
1575 data
= get_dispex_data(This
);
1579 hres
= get_builtin_func(data
, id
, &func
);
1583 *pbstrName
= SysAllocString(func
->name
);
1585 return E_OUTOFMEMORY
;
1589 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1591 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1592 dispex_data_t
*data
;
1596 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1598 if(is_dynamic_dispid(id
)) {
1599 DWORD idx
= id
- DISPID_DYNPROP_0
;
1601 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1602 return DISP_E_UNKNOWNNAME
;
1604 while(++idx
< This
->dynamic_data
->prop_cnt
&& This
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
);
1606 if(idx
== This
->dynamic_data
->prop_cnt
) {
1607 *pid
= DISPID_STARTENUM
;
1611 *pid
= DISPID_DYNPROP_0
+idx
;
1615 data
= get_dispex_data(This
);
1619 if(id
== DISPID_STARTENUM
) {
1622 hres
= get_builtin_func(data
, id
, &func
);
1628 while(func
< data
->funcs
+data
->func_cnt
) {
1629 /* FIXME: Skip hidden properties */
1630 if(func
->func_disp_idx
== -1) {
1637 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
) {
1638 *pid
= DISPID_DYNPROP_0
;
1642 *pid
= DISPID_STARTENUM
;
1646 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1648 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1649 FIXME("(%p)->(%p)\n", This
, ppunk
);
1653 static IDispatchExVtbl DispatchExVtbl
= {
1654 DispatchEx_QueryInterface
,
1657 DispatchEx_GetTypeInfoCount
,
1658 DispatchEx_GetTypeInfo
,
1659 DispatchEx_GetIDsOfNames
,
1661 DispatchEx_GetDispID
,
1662 DispatchEx_InvokeEx
,
1663 DispatchEx_DeleteMemberByName
,
1664 DispatchEx_DeleteMemberByDispID
,
1665 DispatchEx_GetMemberProperties
,
1666 DispatchEx_GetMemberName
,
1667 DispatchEx_GetNextDispID
,
1668 DispatchEx_GetNameSpaceParent
1671 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1673 if(IsEqualGUID(&IID_IDispatch
, riid
))
1674 *ppv
= &This
->IDispatchEx_iface
;
1675 else if(IsEqualGUID(&IID_IDispatchEx
, riid
))
1676 *ppv
= &This
->IDispatchEx_iface
;
1677 else if(IsEqualGUID(&IID_IDispatchJS
, riid
))
1679 else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
))
1685 IUnknown_AddRef((IUnknown
*)*ppv
);
1689 void dispex_traverse(DispatchEx
*This
, nsCycleCollectionTraversalCallback
*cb
)
1691 dynamic_prop_t
*prop
;
1693 if(!This
->dynamic_data
)
1696 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1697 if(V_VT(&prop
->var
) == VT_DISPATCH
)
1698 note_cc_edge((nsISupports
*)V_DISPATCH(&prop
->var
), "dispex_data", cb
);
1701 /* FIXME: Traverse func_disps */
1704 void dispex_unlink(DispatchEx
*This
)
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 V_VT(&prop
->var
) = VT_EMPTY
;
1714 IDispatch_Release(V_DISPATCH(&prop
->var
));
1716 VariantClear(&prop
->var
);
1721 void release_dispex(DispatchEx
*This
)
1723 dynamic_prop_t
*prop
;
1725 if(!This
->dynamic_data
)
1728 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1729 VariantClear(&prop
->var
);
1730 heap_free(prop
->name
);
1733 heap_free(This
->dynamic_data
->props
);
1735 if(This
->dynamic_data
->func_disps
) {
1736 func_obj_entry_t
*iter
;
1738 for(iter
= This
->dynamic_data
->func_disps
; iter
< This
->dynamic_data
->func_disps
+This
->data
->data
->func_disp_cnt
; iter
++) {
1739 if(iter
->func_obj
) {
1740 iter
->func_obj
->obj
= NULL
;
1741 IDispatchEx_Release(&iter
->func_obj
->dispex
.IDispatchEx_iface
);
1743 VariantClear(&iter
->val
);
1746 heap_free(This
->dynamic_data
->func_disps
);
1749 heap_free(This
->dynamic_data
);
1752 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1754 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1755 dispex
->outer
= outer
;
1756 dispex
->data
= data
;
1757 dispex
->dynamic_data
= NULL
;