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
:
562 case DISPATCH_METHOD
:
563 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
566 FIXME("Unimplemented flags %x\n", flags
);
573 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
580 static const tid_t function_iface_tids
[] = {0};
582 static dispex_static_data_t function_dispex
= {
583 &function_dispex_vtbl
,
589 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
593 ret
= heap_alloc_zero(sizeof(func_disp_t
));
597 ret
->IUnknown_iface
.lpVtbl
= &FunctionUnkVtbl
;
598 init_dispex(&ret
->dispex
, &ret
->IUnknown_iface
, &function_dispex
);
605 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
611 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
614 case DISPATCH_METHOD
:
615 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
617 case DISPATCH_PROPERTYGET
: {
618 dispex_dynamic_data_t
*dynamic_data
;
620 if(func
->id
== DISPID_VALUE
) {
623 ret
= SysAllocString(objectW
);
625 return E_OUTOFMEMORY
;
632 dynamic_data
= get_dynamic_data(This
);
634 return E_OUTOFMEMORY
;
636 if(!dynamic_data
->func_disps
) {
637 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(func_disp_t
*));
638 if(!dynamic_data
->func_disps
)
639 return E_OUTOFMEMORY
;
642 if(!dynamic_data
->func_disps
[func
->func_disp_idx
]) {
643 dynamic_data
->func_disps
[func
->func_disp_idx
] = create_func_disp(This
, func
);
644 if(!dynamic_data
->func_disps
[func
->func_disp_idx
])
645 return E_OUTOFMEMORY
;
648 V_VT(res
) = VT_DISPATCH
;
649 V_DISPATCH(res
) = (IDispatch
*)&dynamic_data
->func_disps
[func
->func_disp_idx
]->dispex
.IDispatchEx_iface
;
650 IDispatch_AddRef(V_DISPATCH(res
));
655 FIXME("Unimplemented flags %x\n", flags
);
656 case DISPATCH_PROPERTYPUT
:
663 static HRESULT
get_builtin_func(dispex_data_t
*data
, DISPID id
, func_info_t
**ret
)
668 max
= data
->func_cnt
-1;
673 if(data
->funcs
[n
].id
== id
) {
674 *ret
= data
->funcs
+n
;
678 if(data
->funcs
[n
].id
< id
)
684 WARN("invalid id %x\n", id
);
685 return DISP_E_UNKNOWNNAME
;
688 static HRESULT
get_builtin_id(DispatchEx
*This
, BSTR name
, DWORD grfdex
, DISPID
*ret
)
693 data
= get_dispex_data(This
);
698 max
= data
->func_cnt
-1;
703 c
= strcmpiW(data
->name_table
[n
]->name
, name
);
705 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, name
))
708 *ret
= data
->name_table
[n
]->id
;
718 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
721 hres
= This
->data
->vtbl
->get_dispid(This
, name
, grfdex
, ret
);
722 if(hres
!= DISP_E_UNKNOWNNAME
)
726 return DISP_E_UNKNOWNNAME
;
729 static HRESULT
invoke_builtin_prop(DispatchEx
*This
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*dp
,
730 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
736 data
= get_dispex_data(This
);
740 hres
= get_builtin_func(data
, id
, &func
);
741 if(id
== DISPID_VALUE
&& hres
== DISP_E_UNKNOWNNAME
)
742 return dispex_value(This
, lcid
, flags
, dp
, res
, ei
, caller
);
746 if(func
->func_disp_idx
== -1)
747 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
749 hres
= function_invoke(This
, func
, flags
, dp
, res
, ei
);
754 HRESULT
remove_prop(DispatchEx
*This
, BSTR name
, VARIANT_BOOL
*success
)
756 dynamic_prop_t
*prop
;
760 hres
= get_builtin_id(This
, name
, 0, &id
);
762 DISPID named_id
= DISPID_PROPERTYPUT
;
764 DISPPARAMS dp
= {&var
,&named_id
,1,1};
767 V_VT(&var
) = VT_EMPTY
;
768 memset(&ei
, 0, sizeof(ei
));
769 hres
= invoke_builtin_prop(This
, id
, 0, DISPATCH_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
773 *success
= VARIANT_TRUE
;
777 hres
= get_dynamic_prop(This
, name
, 0, &prop
);
779 if(hres
!= DISP_E_UNKNOWNNAME
)
781 *success
= VARIANT_FALSE
;
785 VariantClear(&prop
->var
);
786 prop
->flags
|= DYNPROP_DELETED
;
787 *success
= VARIANT_TRUE
;
791 static inline DispatchEx
*impl_from_IDispatchEx(IDispatchEx
*iface
)
793 return CONTAINING_RECORD(iface
, DispatchEx
, IDispatchEx_iface
);
796 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
798 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
800 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
803 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
805 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
807 return IUnknown_AddRef(This
->outer
);
810 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
812 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
814 return IUnknown_Release(This
->outer
);
817 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
819 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
821 TRACE("(%p)->(%p)\n", This
, pctinfo
);
827 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
828 LCID lcid
, ITypeInfo
**ppTInfo
)
830 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
833 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
835 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
839 ITypeInfo_AddRef(*ppTInfo
);
843 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
844 LPOLESTR
*rgszNames
, UINT cNames
,
845 LCID lcid
, DISPID
*rgDispId
)
847 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
851 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
854 for(i
=0; i
< cNames
; i
++) {
855 hres
= IDispatchEx_GetDispID(&This
->IDispatchEx_iface
, rgszNames
[i
], 0, rgDispId
+i
);
863 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
864 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
865 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
867 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
869 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
870 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
872 return IDispatchEx_InvokeEx(&This
->IDispatchEx_iface
, dispIdMember
, lcid
, wFlags
, pDispParams
,
873 pVarResult
, pExcepInfo
, NULL
);
876 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
878 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
879 dynamic_prop_t
*dprop
;
882 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
884 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameCaseInsensitive
|fdexNameEnsure
|fdexNameImplicit
|FDEX_VERSION_MASK
))
885 FIXME("Unsupported grfdex %x\n", grfdex
);
887 hres
= get_builtin_id(This
, bstrName
, grfdex
, pid
);
888 if(hres
!= DISP_E_UNKNOWNNAME
)
891 hres
= get_dynamic_prop(This
, bstrName
, grfdex
, &dprop
);
895 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
899 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
900 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
902 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
905 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
907 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
908 return This
->data
->vtbl
->invoke(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
910 if(wFlags
== DISPATCH_CONSTRUCT
) {
911 if(id
== DISPID_VALUE
) {
912 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
) {
913 return This
->data
->vtbl
->value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
915 FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
918 FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
922 if(is_dynamic_dispid(id
)) {
923 DWORD idx
= id
- DISPID_DYNPROP_0
;
924 dynamic_prop_t
*prop
;
926 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
927 return DISP_E_UNKNOWNNAME
;
929 prop
= This
->dynamic_data
->props
+idx
;
932 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
935 case DISPATCH_METHOD
: {
936 DISPID named_arg
= DISPID_THIS
;
937 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
940 if(V_VT(&prop
->var
) != VT_DISPATCH
) {
941 FIXME("invoke %s\n", debugstr_variant(&prop
->var
));
945 if(pdp
->cNamedArgs
) {
946 FIXME("named args not supported\n");
950 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
952 return E_OUTOFMEMORY
;
954 dp
.cArgs
= pdp
->cArgs
+1;
955 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
957 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
958 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)&This
->IDispatchEx_iface
;
960 hres
= IDispatch_QueryInterface(V_DISPATCH(&prop
->var
), &IID_IDispatchEx
, (void**)&dispex
);
961 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
962 if(SUCCEEDED(hres
)) {
963 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
964 IDispatchEx_Release(dispex
);
967 hres
= IDispatch_Invoke(V_DISPATCH(&prop
->var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
969 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
971 heap_free(dp
.rgvarg
);
974 case DISPATCH_PROPERTYGET
:
975 if(prop
->flags
& DYNPROP_DELETED
)
976 return DISP_E_UNKNOWNNAME
;
977 return variant_copy(pvarRes
, &prop
->var
);
978 case DISPATCH_PROPERTYPUT
|DISPATCH_PROPERTYPUTREF
:
979 case DISPATCH_PROPERTYPUT
:
980 if(pdp
->cArgs
!= 1 || (pdp
->cNamedArgs
== 1 && *pdp
->rgdispidNamedArgs
!= DISPID_PROPERTYPUT
)
981 || pdp
->cNamedArgs
> 1) {
982 FIXME("invalid args\n");
986 TRACE("put %s\n", debugstr_variant(pdp
->rgvarg
));
987 VariantClear(&prop
->var
);
988 hres
= variant_copy(&prop
->var
, pdp
->rgvarg
);
992 prop
->flags
&= ~DYNPROP_DELETED
;
995 FIXME("unhandled wFlags %x\n", wFlags
);
1000 return invoke_builtin_prop(This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
1003 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
1005 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1007 TRACE("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
1009 /* Not implemented by IE */
1013 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
1015 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1017 TRACE("(%p)->(%x)\n", This
, id
);
1019 /* Not implemented by IE */
1023 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
1025 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1026 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
1030 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
1032 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1033 dispex_data_t
*data
;
1037 TRACE("(%p)->(%x %p)\n", This
, id
, pbstrName
);
1039 if(is_dynamic_dispid(id
)) {
1040 DWORD idx
= id
- DISPID_DYNPROP_0
;
1042 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1043 return DISP_E_UNKNOWNNAME
;
1045 *pbstrName
= SysAllocString(This
->dynamic_data
->props
[idx
].name
);
1047 return E_OUTOFMEMORY
;
1052 data
= get_dispex_data(This
);
1056 hres
= get_builtin_func(data
, id
, &func
);
1060 *pbstrName
= SysAllocString(func
->name
);
1062 return E_OUTOFMEMORY
;
1066 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
1068 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1069 dispex_data_t
*data
;
1073 TRACE("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
1075 if(is_dynamic_dispid(id
)) {
1076 DWORD idx
= id
- DISPID_DYNPROP_0
;
1078 if(!get_dynamic_data(This
) || This
->dynamic_data
->prop_cnt
<= idx
)
1079 return DISP_E_UNKNOWNNAME
;
1081 while(++idx
< This
->dynamic_data
->prop_cnt
&& This
->dynamic_data
->props
[idx
].flags
& DYNPROP_DELETED
);
1083 if(idx
== This
->dynamic_data
->prop_cnt
) {
1084 *pid
= DISPID_STARTENUM
;
1088 *pid
= DISPID_DYNPROP_0
+idx
;
1092 data
= get_dispex_data(This
);
1096 if(id
== DISPID_STARTENUM
) {
1099 hres
= get_builtin_func(data
, id
, &func
);
1105 while(func
< data
->funcs
+data
->func_cnt
) {
1106 /* FIXME: Skip hidden properties */
1107 if(func
->func_disp_idx
== -1) {
1114 if(get_dynamic_data(This
) && This
->dynamic_data
->prop_cnt
) {
1115 *pid
= DISPID_DYNPROP_0
;
1119 *pid
= DISPID_STARTENUM
;
1123 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
1125 DispatchEx
*This
= impl_from_IDispatchEx(iface
);
1126 FIXME("(%p)->(%p)\n", This
, ppunk
);
1130 static IDispatchExVtbl DispatchExVtbl
= {
1131 DispatchEx_QueryInterface
,
1134 DispatchEx_GetTypeInfoCount
,
1135 DispatchEx_GetTypeInfo
,
1136 DispatchEx_GetIDsOfNames
,
1138 DispatchEx_GetDispID
,
1139 DispatchEx_InvokeEx
,
1140 DispatchEx_DeleteMemberByName
,
1141 DispatchEx_DeleteMemberByDispID
,
1142 DispatchEx_GetMemberProperties
,
1143 DispatchEx_GetMemberName
,
1144 DispatchEx_GetNextDispID
,
1145 DispatchEx_GetNameSpaceParent
1148 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
1150 static const IID IID_UndocumentedScriptIface
=
1151 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
1152 static const IID IID_IDispatchJS
=
1153 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
1155 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1156 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1157 *ppv
= &This
->IDispatchEx_iface
;
1158 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1159 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1160 *ppv
= &This
->IDispatchEx_iface
;
1161 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
1162 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
1164 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
1165 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
1172 IUnknown_AddRef((IUnknown
*)*ppv
);
1176 void release_dispex(DispatchEx
*This
)
1178 dynamic_prop_t
*prop
;
1180 if(!This
->dynamic_data
)
1183 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
1184 VariantClear(&prop
->var
);
1185 heap_free(prop
->name
);
1188 heap_free(This
->dynamic_data
->props
);
1190 if(This
->dynamic_data
->func_disps
) {
1193 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
1194 if(This
->dynamic_data
->func_disps
[i
]) {
1195 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
1196 heap_free(This
->dynamic_data
->func_disps
[i
]);
1200 heap_free(This
->dynamic_data
->func_disps
);
1203 heap_free(This
->dynamic_data
);
1206 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
1208 dispex
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
1209 dispex
->outer
= outer
;
1210 dispex
->data
= data
;
1211 dispex
->dynamic_data
= NULL
;