2 * Copyright 2008-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
34 static const WCHAR objectW
[] = {'[','o','b','j','e','c','t',']',0};
43 struct dispex_data_t
{
46 func_info_t
**name_table
;
58 #define DYNPROP_DELETED 0x01
62 IUnknown IUnknown_iface
;
67 struct dispex_dynamic_data_t
{
70 dynamic_prop_t
*props
;
71 func_disp_t
**func_disps
;
74 #define DISPID_DYNPROP_0 0x50000000
75 #define DISPID_DYNPROP_MAX 0x5fffffff
77 #define FDEX_VERSION_MASK 0xf0000000
79 static ITypeLib
*typelib
;
80 static ITypeInfo
*typeinfos
[LAST_tid
];
81 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
83 static REFIID tid_ids
[] = {
84 #define XIID(iface) &IID_ ## iface,
85 #define XDIID(iface) &DIID_ ## iface,
91 static HRESULT
load_typelib(void)
96 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
98 ERR("LoadRegTypeLib failed: %08x\n", hres
);
102 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
103 ITypeLib_Release(tl
);
107 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
112 hres
= load_typelib();
116 if(!typeinfos
[tid
]) {
119 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
121 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
125 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
126 ITypeInfo_Release(ti
);
129 *typeinfo
= typeinfos
[tid
];
133 void release_typelib(void)
138 while(!list_empty(&dispex_data_list
)) {
139 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
140 list_remove(&iter
->entry
);
142 for(i
=0; i
< iter
->func_cnt
; i
++)
143 SysFreeString(iter
->funcs
[i
].name
);
145 heap_free(iter
->funcs
);
146 heap_free(iter
->name_table
);
153 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
155 ITypeInfo_Release(typeinfos
[i
]);
157 ITypeLib_Release(typelib
);
160 HRESULT
get_htmldoc_classinfo(ITypeInfo
**typeinfo
)
165 hres
= load_typelib();
169 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, &CLSID_HTMLDocument
, typeinfo
);
171 ERR("GetTypeInfoOfGuid failed: %08x\n", hres
);
175 static void add_func_info(dispex_data_t
*data
, DWORD
*size
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
)
179 if(data
->func_cnt
&& data
->funcs
[data
->func_cnt
-1].id
== desc
->memid
)
182 if(data
->func_cnt
== *size
)
183 data
->funcs
= heap_realloc(data
->funcs
, (*size
<<= 1)*sizeof(func_info_t
));
185 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &data
->funcs
[data
->func_cnt
].name
, NULL
, NULL
, NULL
);
189 data
->funcs
[data
->func_cnt
].id
= desc
->memid
;
190 data
->funcs
[data
->func_cnt
].tid
= tid
;
191 data
->funcs
[data
->func_cnt
].func_disp_idx
= (desc
->invkind
& DISPATCH_METHOD
) ? data
->func_disp_cnt
++ : -1;
196 static int dispid_cmp(const void *p1
, const void *p2
)
198 return ((const func_info_t
*)p1
)->id
- ((const func_info_t
*)p2
)->id
;
201 static int func_name_cmp(const void *p1
, const void *p2
)
203 return strcmpiW((*(func_info_t
* const*)p1
)->name
, (*(func_info_t
* const*)p2
)->name
);
206 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
208 const tid_t
*tid
= This
->data
->iface_tids
;
215 TRACE("(%p)\n", This
);
217 if(This
->data
->disp_tid
) {
218 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
220 ERR("Could not get disp type info: %08x\n", hres
);
225 data
= heap_alloc(sizeof(dispex_data_t
));
227 data
->func_disp_cnt
= 0;
228 data
->funcs
= heap_alloc(size
*sizeof(func_info_t
));
229 list_add_tail(&dispex_data_list
, &data
->entry
);
232 hres
= get_typeinfo(*tid
, &ti
);
238 hres
= ITypeInfo_GetFuncDesc(ti
, i
++, &funcdesc
);
242 add_func_info(data
, &size
, *tid
, funcdesc
, dti
);
243 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
249 if(!data
->func_cnt
) {
250 heap_free(data
->funcs
);
251 data
->name_table
= NULL
;
257 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
258 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
260 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
261 for(i
=0; i
< data
->func_cnt
; i
++)
262 data
->name_table
[i
] = data
->funcs
+i
;
263 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
268 static int id_cmp(const void *p1
, const void *p2
)
270 return *(const DISPID
*)p1
- *(const DISPID
*)p2
;
273 HRESULT
get_dispids(tid_t tid
, DWORD
*ret_size
, DISPID
**ret
)
275 unsigned i
, func_cnt
;
282 hres
= get_typeinfo(tid
, &ti
);
286 hres
= ITypeInfo_GetTypeAttr(ti
, &attr
);
288 ITypeInfo_Release(ti
);
292 func_cnt
= attr
->cFuncs
;
293 ITypeInfo_ReleaseTypeAttr(ti
, attr
);
295 ids
= heap_alloc(func_cnt
*sizeof(DISPID
));
297 ITypeInfo_Release(ti
);
298 return E_OUTOFMEMORY
;
301 for(i
=0; i
< func_cnt
; i
++) {
302 hres
= ITypeInfo_GetFuncDesc(ti
, i
, &funcdesc
);
306 ids
[i
] = funcdesc
->memid
;
307 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
310 ITypeInfo_Release(ti
);
316 qsort(ids
, func_cnt
, sizeof(DISPID
), id_cmp
);
318 *ret_size
= func_cnt
;
323 static CRITICAL_SECTION cs_dispex_static_data
;
324 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
326 0, 0, &cs_dispex_static_data
,
327 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
328 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
330 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
333 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
336 return This
->data
->data
;
338 EnterCriticalSection(&cs_dispex_static_data
);
340 if(!This
->data
->data
)
341 This
->data
->data
= preprocess_dispex_data(This
);
343 LeaveCriticalSection(&cs_dispex_static_data
);
345 return This
->data
->data
;
348 static inline BOOL
is_custom_dispid(DISPID id
)
350 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
353 static inline BOOL
is_dynamic_dispid(DISPID id
)
355 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
358 static HRESULT
variant_copy(VARIANT
*dest
, VARIANT
*src
)
360 if(V_VT(src
) == VT_BSTR
&& !V_BSTR(src
)) {
361 V_VT(dest
) = VT_BSTR
;
366 return VariantCopy(dest
, src
);
369 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
)
371 if(This
->dynamic_data
)
372 return This
->dynamic_data
;
374 This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
));
375 if(!This
->dynamic_data
)
378 if(This
->data
->vtbl
&& This
->data
->vtbl
->populate_props
)
379 This
->data
->vtbl
->populate_props(This
);
381 return This
->dynamic_data
;
384 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, DWORD flags
, dynamic_prop_t
**ret
)
386 const BOOL alloc
= flags
& fdexNameEnsure
;
387 dispex_dynamic_data_t
*data
;
388 dynamic_prop_t
*prop
;
390 data
= get_dynamic_data(This
);
392 return E_OUTOFMEMORY
;
394 for(prop
= data
->props
; prop
< data
->props
+data
->prop_cnt
; prop
++) {
395 if(flags
& fdexNameCaseInsensitive
? !strcmpiW(prop
->name
, name
) : !strcmpW(prop
->name
, name
)) {
396 if(prop
->flags
& DYNPROP_DELETED
) {
398 return DISP_E_UNKNOWNNAME
;
399 prop
->flags
&= ~DYNPROP_DELETED
;
407 return DISP_E_UNKNOWNNAME
;
409 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
411 if(!data
->buf_size
) {
412 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
414 return E_OUTOFMEMORY
;
416 }else if(data
->buf_size
== data
->prop_cnt
) {
417 dynamic_prop_t
*new_props
;
419 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
421 return E_OUTOFMEMORY
;
423 data
->props
= new_props
;
424 data
->buf_size
<<= 1;
427 prop
= data
->props
+ data
->prop_cnt
;
429 prop
->name
= heap_strdupW(name
);
431 return E_OUTOFMEMORY
;
433 VariantInit(&prop
->var
);
440 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
442 dynamic_prop_t
*prop
;
445 hres
= get_dynamic_prop(This
, name
, alloc
? fdexNameEnsure
: 0, &prop
);
453 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
454 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
456 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
457 return This
->data
->vtbl
->value(This
, lcid
, flags
, params
, res
, ei
, caller
);
460 case DISPATCH_PROPERTYGET
:
462 V_BSTR(res
) = SysAllocString(objectW
);
464 return E_OUTOFMEMORY
;
467 FIXME("Unimplemented flags %x\n", flags
);
474 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
482 hres
= get_typeinfo(func
->tid
, &ti
);
484 ERR("Could not get type info: %08x\n", hres
);
488 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
490 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids
[func
->tid
]), hres
);
494 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, dp
, res
, ei
, &argerr
);
496 IUnknown_Release(unk
);
500 static inline func_disp_t
*impl_from_IUnknown(IUnknown
*iface
)
502 return CONTAINING_RECORD(iface
, func_disp_t
, IUnknown_iface
);
505 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
507 func_disp_t
*This
= impl_from_IUnknown(iface
);
509 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
510 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
511 *ppv
= &This
->IUnknown_iface
;
512 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
513 return *ppv
? S_OK
: E_NOINTERFACE
;
516 return E_NOINTERFACE
;
519 IUnknown_AddRef((IUnknown
*)*ppv
);
523 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
525 func_disp_t
*This
= impl_from_IUnknown(iface
);
527 TRACE("(%p)\n", This
);
529 return IDispatchEx_AddRef(&This
->obj
->IDispatchEx_iface
);
532 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
534 func_disp_t
*This
= impl_from_IUnknown(iface
);
536 TRACE("(%p)\n", This
);
538 return IDispatchEx_Release(&This
->obj
->IDispatchEx_iface
);
541 static const IUnknownVtbl FunctionUnkVtbl
= {
542 Function_QueryInterface
,
547 static inline func_disp_t
*impl_from_DispatchEx(DispatchEx
*iface
)
549 return CONTAINING_RECORD(iface
, func_disp_t
, dispex
);
552 static HRESULT
function_value(DispatchEx
*dispex
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
553 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
555 func_disp_t
*This
= impl_from_DispatchEx(dispex
);
559 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
563 case DISPATCH_METHOD
:
564 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
567 FIXME("Unimplemented flags %x\n", flags
);
574 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
581 static const tid_t function_iface_tids
[] = {0};
583 static dispex_static_data_t function_dispex
= {
584 &function_dispex_vtbl
,
590 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
594 ret
= heap_alloc_zero(sizeof(func_disp_t
));
598 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
599 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
606 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
612 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
616 case DISPATCH_METHOD
:
617 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
619 case DISPATCH_PROPERTYGET
: {
620 dispex_dynamic_data_t
*dynamic_data
;
622 if(func
->id
== DISPID_VALUE
) {
625 ret
= SysAllocString(objectW
);
627 return E_OUTOFMEMORY
;
634 dynamic_data
= get_dynamic_data(This
);
636 return E_OUTOFMEMORY
;
638 if(!dynamic_data
->func_disps
) {
639 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(func_disp_t
*));
640 if(!dynamic_data
->func_disps
)
641 return E_OUTOFMEMORY
;
644 if(!dynamic_data
->func_disps
[func
->func_disp_idx
]) {
645 dynamic_data
->func_disps
[func
->func_disp_idx
] = create_func_disp(This
, func
);
646 if(!dynamic_data
->func_disps
[func
->func_disp_idx
])
647 return E_OUTOFMEMORY
;
650 V_VT(res
) = VT_DISPATCH
;
651 V_DISPATCH(res
) = (IDispatch
*)&dynamic_data
->func_disps
[func
->func_disp_idx
]->dispex
.IDispatchEx_iface
;
652 IDispatch_AddRef(V_DISPATCH(res
));
657 FIXME("Unimplemented flags %x\n", flags
);
659 case DISPATCH_PROPERTYPUT
:
666 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
671 max
= data
->func_cnt
-1;
676 if(data
->funcs
[n
].id
== id
) {
677 *ret
= data
->funcs
+n
;
681 if(data
->funcs
[n
].id
< id
)
687 WARN("invalid id %x\n", id
);
688 return DISP_E_UNKNOWNNAME
;
691 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
696 data
= get_dispex_data(This
);
701 max
= data
->func_cnt
-1;
706 c
= strcmpiW(data
->name_table
[n
]->name
, name
);
708 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, name
))
711 *ret
= data
->name_table
[n
]->id
;
721 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
724 hres
= This
->data
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
725 if(hres
!= DISP_E_UNKNOWNNAME
)
729 return DISP_E_UNKNOWNNAME
;
732 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
733 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
739 data
= get_dispex_data(This
);
743 hres
= get_builtin_func(data
, id
, &func
);
744 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
745 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
749 if(func
->func_disp_idx
== -1)
750 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
752 hres
= function_invoke(This
, func
, flags
, dp
, res
, ei
);
757 HRESULT
remove_prop(DispatchEx
*This
, BSTR name
, VARIANT_BOOL
*success
)
759 dynamic_prop_t
*prop
;
763 hres
= get_builtin_id(This
, name
, 0, &id
);
765 DISPID named_id
= DISPID_PROPERTYPUT
;
767 DISPPARAMS dp
= {&var
,&named_id
,1,1};
770 V_VT(&var
) = VT_EMPTY
;
771 memset(&ei
, 0, sizeof(ei
));
772 hres
= invoke_builtin_prop(This
, id
, 0, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
776 *success
= VARIANT_TRUE
;
780 hres
= get_dynamic_prop(This
, name
, 0, &prop
);
782 if(hres
!= DISP_E_UNKNOWNNAME
)
784 *success
= VARIANT_FALSE
;
788 VariantClear(&prop
->var
);
789 prop
->flags
|= DYNPROP_DELETED
;
790 *success
= VARIANT_TRUE
;
794 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
796 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
799 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
801 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
803 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
806 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
808 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
810 return IUnknown_AddRef(This
->outer
);
813 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
815 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
817 return IUnknown_Release(This
->outer
);
820 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
822 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
824 TRACE("(%p)->(%p)\n", This
, pctinfo
);
830 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
831 LCID lcid
, ITypeInfo
**ppTInfo
)
833 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
836 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
838 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
842 ITypeInfo_AddRef(*ppTInfo
);
846 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
847 LPOLESTR
*rgszNames
, UINT cNames
,
848 LCID lcid
, DISPID
*rgDispId
)
850 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
854 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
857 for(i
=0; i
< cNames
; i
++) {
858 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
866 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
867 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
868 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
870 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
872 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
873 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
875 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
876 pVarResult
, pExcepInfo
, NULL
);
879 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
881 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
882 dynamic_prop_t
*dprop
;
885 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
887 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
888 FIXME("Unsupported grfdex %x\n", grfdex
);
890 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
891 if(hres
!= DISP_E_UNKNOWNNAME
)
894 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
898 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
902 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
903 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
905 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
908 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
910 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
911 return This
->data
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
913 if(wFlags
== DISPATCH_CONSTRUCT
) {
914 if(id
== DISPID_VALUE
) {
915 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
916 return This
->data
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
918 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
921 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
925 if(is_dynamic_dispid(id
)) {
926 DWORD idx
= id
- DISPID_DYNPROP_0
;
927 dynamic_prop_t
*prop
;
929 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
930 return DISP_E_UNKNOWNNAME
;
932 prop
= This
->dynamic_data
->props
+idx
;
935 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
939 case DISPATCH_METHOD
: {
940 DISPID named_arg
= DISPID_THIS
;
941 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
944 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
945 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
949 if(pdp
->cNamedArgs
) {
950 FIXME("named args not supported\n");
954 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
956 return E_OUTOFMEMORY
;
958 dp
.cArgs
= pdp
->cArgs
+1;
959 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
961 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
962 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
964 hres
= IDispatch_QueryInterface(V_DISPATCH(&prop
->var
), &IID_IDispatchEx
, (void**)&dispex
);
965 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
966 if(SUCCEEDED(hres
)) {
967 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
968 IDispatchEx_Release(dispex
);
971 hres
= IDispatch_Invoke(V_DISPATCH(&prop
->var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
973 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
975 heap_free(dp
.rgvarg
);
978 case DISPATCH_PROPERTYGET
:
979 if(prop
->flags
& DYNPROP_DELETED
)
980 return DISP_E_UNKNOWNNAME
;
981 return variant_copy(pvarRes
, &prop
->var
);
982 case DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
:
983 case DISPATCH_PROPERTYPUT
:
984 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
985 || pdp
->cNamedArgs
> 1) {
986 FIXME("invalid args\n");
990 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
991 VariantClear(&prop
->var
);
992 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
996 prop
->flags
&= ~DYNPROP_DELETED
;
999 FIXME("unhandled wFlags %x\n", wFlags
);
1004 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1007 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1009 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1011 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1013 /* Not implemented by IE */
1017 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1019 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1021 TRACE("(%p)->(%x)\n", This
, id
);
1023 /* Not implemented by IE */
1027 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1029 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1030 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1034 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1036 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1037 dispex_data_t
*data
;
1041 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1043 if(is_dynamic_dispid(id
)) {
1044 DWORD idx
= id
- DISPID_DYNPROP_0
;
1046 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1047 return DISP_E_UNKNOWNNAME
;
1049 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1051 return E_OUTOFMEMORY
;
1056 data
= get_dispex_data(This
);
1060 hres
= get_builtin_func(data
, id
, &func
);
1064 *pbstrName
= SysAllocString(func
->name
);
1066 return E_OUTOFMEMORY
;
1070 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1072 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1073 dispex_data_t
*data
;
1077 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1079 if(is_dynamic_dispid(id
)) {
1080 DWORD idx
= id
- DISPID_DYNPROP_0
;
1082 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1083 return DISP_E_UNKNOWNNAME
;
1085 while(++idx
< This
->dynamic_data
->prop_cnt
&& This
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
);
1087 if(idx
== This
->dynamic_data
->prop_cnt
) {
1088 *pid
= DISPID_STARTENUM
;
1092 *pid
= DISPID_DYNPROP_0
+idx
;
1096 data
= get_dispex_data(This
);
1100 if(id
== DISPID_STARTENUM
) {
1103 hres
= get_builtin_func(data
, id
, &func
);
1109 while(func
< data
->funcs
+data
->func_cnt
) {
1110 /* FIXME: Skip hidden properties */
1111 if(func
->func_disp_idx
== -1) {
1118 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
) {
1119 *pid
= DISPID_DYNPROP_0
;
1123 *pid
= DISPID_STARTENUM
;
1127 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1129 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1130 FIXME("(%p)->(%p)\n", This
, ppunk
);
1134 static IDispatchExVtbl DispatchExVtbl
= {
1135 DispatchEx_QueryInterface
,
1138 DispatchEx_GetTypeInfoCount
,
1139 DispatchEx_GetTypeInfo
,
1140 DispatchEx_GetIDsOfNames
,
1142 DispatchEx_GetDispID
,
1143 DispatchEx_InvokeEx
,
1144 DispatchEx_DeleteMemberByName
,
1145 DispatchEx_DeleteMemberByDispID
,
1146 DispatchEx_GetMemberProperties
,
1147 DispatchEx_GetMemberName
,
1148 DispatchEx_GetNextDispID
,
1149 DispatchEx_GetNameSpaceParent
1152 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1154 static const IID IID_UndocumentedScriptIface
=
1155 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1156 static const IID IID_IDispatchJS
=
1157 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1159 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1160 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1161 *ppv
= &This
->IDispatchEx_iface
;
1162 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1163 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1164 *ppv
= &This
->IDispatchEx_iface
;
1165 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
1166 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
1168 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
1169 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
1176 IUnknown_AddRef((IUnknown
*)*ppv
);
1180 void release_dispex(DispatchEx
*This
)
1182 dynamic_prop_t
*prop
;
1184 if(!This
->dynamic_data
)
1187 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1188 VariantClear(&prop
->var
);
1189 heap_free(prop
->name
);
1192 heap_free(This
->dynamic_data
->props
);
1194 if(This
->dynamic_data
->func_disps
) {
1197 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
1198 if(This
->dynamic_data
->func_disps
[i
]) {
1199 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
1200 heap_free(This
->dynamic_data
->func_disps
[i
]);
1204 heap_free(This
->dynamic_data
->func_disps
);
1207 heap_free(This
->dynamic_data
);
1210 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1212 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1213 dispex
->outer
= outer
;
1214 dispex
->data
= data
;
1215 dispex
->dynamic_data
= NULL
;