2 * Copyright 2008 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
);
41 struct dispex_data_t
{
44 func_info_t
**name_table
;
57 const IUnknownVtbl
*lpIUnknownVtbl
;
62 #define FUNCUNKNOWN(x) ((IUnknown*) &(x)->lpIUnknownVtbl)
64 struct dispex_dynamic_data_t
{
67 dynamic_prop_t
*props
;
68 func_disp_t
**func_disps
;
71 #define DISPID_DYNPROP_0 0x50000000
72 #define DISPID_DYNPROP_MAX 0x5fffffff
74 static ITypeLib
*typelib
;
75 static ITypeInfo
*typeinfos
[LAST_tid
];
76 static struct list dispex_data_list
= LIST_INIT(dispex_data_list
);
78 static REFIID tid_ids
[] = {
81 &DIID_DispDOMChildrenCollection
,
83 &DIID_DispHTMLCommentElement
,
84 &DIID_DispHTMLCurrentStyle
,
85 &DIID_DispHTMLDocument
,
86 &DIID_DispHTMLDOMTextNode
,
87 &DIID_DispHTMLElementCollection
,
88 &DIID_DispHTMLGenericElement
,
91 &DIID_DispHTMLInputElement
,
92 &DIID_DispHTMLLocation
,
93 &DIID_DispHTMLNavigator
,
94 &DIID_DispHTMLOptionElement
,
95 &DIID_DispHTMLSelectElement
,
98 &DIID_DispHTMLTableRow
,
99 &DIID_DispHTMLUnknownElement
,
100 &DIID_DispHTMLWindow2
,
101 &IID_IHTMLBodyElement
,
102 &IID_IHTMLBodyElement2
,
103 &IID_IHTMLCommentElement
,
104 &IID_IHTMLCurrentStyle
,
105 &IID_IHTMLCurrentStyle2
,
106 &IID_IHTMLCurrentStyle3
,
107 &IID_IHTMLCurrentStyle4
,
112 &IID_IHTMLDOMChildrenCollection
,
115 &IID_IHTMLDOMTextNode
,
120 &IID_IHTMLElementCollection
,
122 &IID_IHTMLFrameBase2
,
123 &IID_IHTMLGenericElement
,
124 &IID_IHTMLImgElement
,
125 &IID_IHTMLInputElement
,
127 &IID_IHTMLOptionElement
,
128 &IID_IHTMLSelectElement
,
135 &IID_IHTMLTextContainer
,
136 &IID_IHTMLUniqueName
,
142 static HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
149 hres
= LoadRegTypeLib(&LIBID_MSHTML
, 4, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
151 ERR("LoadRegTypeLib failed: %08x\n", hres
);
155 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
156 ITypeLib_Release(tl
);
159 if(!typeinfos
[tid
]) {
162 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &typeinfo
);
164 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
168 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), typeinfo
, NULL
))
169 ITypeInfo_Release(typeinfo
);
172 *typeinfo
= typeinfos
[tid
];
176 void release_typelib(void)
181 while(!list_empty(&dispex_data_list
)) {
182 iter
= LIST_ENTRY(list_head(&dispex_data_list
), dispex_data_t
, entry
);
183 list_remove(&iter
->entry
);
185 for(i
=0; i
< iter
->func_cnt
; i
++)
186 SysFreeString(iter
->funcs
[i
].name
);
188 heap_free(iter
->funcs
);
189 heap_free(iter
->name_table
);
196 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
198 ITypeInfo_Release(typeinfos
[i
]);
200 ITypeLib_Release(typelib
);
203 static void add_func_info(dispex_data_t
*data
, DWORD
*size
, tid_t tid
, const FUNCDESC
*desc
, ITypeInfo
*dti
)
207 if(data
->func_cnt
&& data
->funcs
[data
->func_cnt
-1].id
== desc
->memid
)
210 if(data
->func_cnt
== *size
)
211 data
->funcs
= heap_realloc(data
->funcs
, (*size
<<= 1)*sizeof(func_info_t
));
213 hres
= ITypeInfo_GetDocumentation(dti
, desc
->memid
, &data
->funcs
[data
->func_cnt
].name
, NULL
, NULL
, NULL
);
217 data
->funcs
[data
->func_cnt
].id
= desc
->memid
;
218 data
->funcs
[data
->func_cnt
].tid
= tid
;
219 data
->funcs
[data
->func_cnt
].func_disp_idx
= desc
->invkind
== INVOKE_FUNC
? data
->func_disp_cnt
++ : -1;
224 static int dispid_cmp(const void *p1
, const void *p2
)
226 return ((func_info_t
*)p1
)->id
- ((func_info_t
*)p2
)->id
;
229 static int func_name_cmp(const void *p1
, const void *p2
)
231 return strcmpiW((*(func_info_t
**)p1
)->name
, (*(func_info_t
**)p2
)->name
);
234 static dispex_data_t
*preprocess_dispex_data(DispatchEx
*This
)
236 const tid_t
*tid
= This
->data
->iface_tids
;
243 TRACE("(%p)\n", This
);
245 hres
= get_typeinfo(This
->data
->disp_tid
, &dti
);
247 ERR("Could not get disp type info: %08x\n", hres
);
251 data
= heap_alloc(sizeof(dispex_data_t
));
253 data
->func_disp_cnt
= 0;
254 data
->funcs
= heap_alloc(size
*sizeof(func_info_t
));
255 list_add_tail(&dispex_data_list
, &data
->entry
);
258 hres
= get_typeinfo(*tid
, &ti
);
264 hres
= ITypeInfo_GetFuncDesc(ti
, i
++, &funcdesc
);
268 add_func_info(data
, &size
, *tid
, funcdesc
, dti
);
269 ITypeInfo_ReleaseFuncDesc(ti
, funcdesc
);
275 if(!data
->func_cnt
) {
276 heap_free(data
->funcs
);
278 }else if(data
->func_cnt
!= size
) {
279 data
->funcs
= heap_realloc(data
->funcs
, data
->func_cnt
* sizeof(func_info_t
));
282 qsort(data
->funcs
, data
->func_cnt
, sizeof(func_info_t
), dispid_cmp
);
285 data
->name_table
= heap_alloc(data
->func_cnt
* sizeof(func_info_t
*));
286 for(i
=0; i
< data
->func_cnt
; i
++)
287 data
->name_table
[i
] = data
->funcs
+i
;
288 qsort(data
->name_table
, data
->func_cnt
, sizeof(func_info_t
*), func_name_cmp
);
290 data
->name_table
= NULL
;
296 static CRITICAL_SECTION cs_dispex_static_data
;
297 static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg
=
299 0, 0, &cs_dispex_static_data
,
300 { &cs_dispex_static_data_dbg
.ProcessLocksList
, &cs_dispex_static_data_dbg
.ProcessLocksList
},
301 0, 0, { (DWORD_PTR
)(__FILE__
": dispex_static_data") }
303 static CRITICAL_SECTION cs_dispex_static_data
= { &cs_dispex_static_data_dbg
, -1, 0, 0, 0, 0 };
306 static dispex_data_t
*get_dispex_data(DispatchEx
*This
)
309 return This
->data
->data
;
311 EnterCriticalSection(&cs_dispex_static_data
);
313 if(!This
->data
->data
)
314 This
->data
->data
= preprocess_dispex_data(This
);
316 LeaveCriticalSection(&cs_dispex_static_data
);
318 return This
->data
->data
;
321 void call_disp_func(HTMLDocument
*doc
, IDispatch
*disp
, IDispatch
*this_obj
)
323 DISPID named_arg
= DISPID_THIS
;
325 DISPPARAMS params
= {&arg
, &named_arg
, 1, 1};
331 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
333 FIXME("Could not get IDispatchEx interface: %08x\n", hres
);
337 V_VT(&arg
) = VT_DISPATCH
;
338 V_DISPATCH(&arg
) = this_obj
;
340 memset(&ei
, 0, sizeof(ei
));
342 hres
= IDispatchEx_InvokeEx(dispex
, 0, GetUserDefaultLCID(), DISPATCH_METHOD
, ¶ms
, &res
, &ei
, NULL
);
343 IDispatchEx_Release(dispex
);
345 TRACE("%p returned %08x\n", disp
, hres
);
350 static inline BOOL
is_custom_dispid(DISPID id
)
352 return MSHTML_DISPID_CUSTOM_MIN
<= id
&& id
<= MSHTML_DISPID_CUSTOM_MAX
;
355 static inline BOOL
is_dynamic_dispid(DISPID id
)
357 return DISPID_DYNPROP_0
<= id
&& id
<= DISPID_DYNPROP_MAX
;
360 static inline dispex_dynamic_data_t
*get_dynamic_data(DispatchEx
*This
, BOOL alloc
)
362 return !alloc
|| This
->dynamic_data
364 : (This
->dynamic_data
= heap_alloc_zero(sizeof(dispex_dynamic_data_t
)));
367 static HRESULT
get_dynamic_prop(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, dynamic_prop_t
**ret
)
369 dispex_dynamic_data_t
*data
= get_dynamic_data(This
, alloc
);
374 return E_OUTOFMEMORY
;
376 TRACE("not found %s\n", debugstr_w(name
));
377 return DISP_E_UNKNOWNNAME
;
380 for(i
=0; i
< data
->prop_cnt
; i
++) {
381 if(!strcmpW(data
->props
[i
].name
, name
)) {
382 *ret
= data
->props
+i
;
387 TRACE("creating dynamic prop %s\n", debugstr_w(name
));
389 if(!data
->buf_size
) {
390 data
->props
= heap_alloc(sizeof(dynamic_prop_t
)*4);
392 return E_OUTOFMEMORY
;
394 }else if(data
->buf_size
== data
->prop_cnt
) {
395 dynamic_prop_t
*new_props
;
397 new_props
= heap_realloc(data
->props
, sizeof(dynamic_prop_t
)*(data
->buf_size
<<1));
399 return E_OUTOFMEMORY
;
401 data
->props
= new_props
;
402 data
->buf_size
<<= 1;
405 data
->props
[data
->prop_cnt
].name
= heap_strdupW(name
);
406 VariantInit(&data
->props
[data
->prop_cnt
].var
);
407 *ret
= data
->props
+ data
->prop_cnt
++;
412 HRESULT
dispex_get_dprop_ref(DispatchEx
*This
, const WCHAR
*name
, BOOL alloc
, VARIANT
**ret
)
414 dynamic_prop_t
*prop
;
417 hres
= get_dynamic_prop(This
, name
, alloc
, &prop
);
425 static HRESULT
dispex_value(DispatchEx
*This
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
426 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
428 static const WCHAR objectW
[] = {'[','o','b','j','e','c','t',']',0};
430 if(This
->data
->vtbl
&& This
->data
->vtbl
->value
)
431 return This
->data
->vtbl
->value(This
->outer
, lcid
, flags
, params
, res
, ei
, caller
);
434 case DISPATCH_PROPERTYGET
:
436 V_BSTR(res
) = SysAllocString(objectW
);
438 return E_OUTOFMEMORY
;
441 FIXME("Unimplemented flags %x\n", flags
);
448 static HRESULT
typeinfo_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
456 hres
= get_typeinfo(func
->tid
, &ti
);
458 ERR("Could not get type info: %08x\n", hres
);
462 hres
= IUnknown_QueryInterface(This
->outer
, tid_ids
[func
->tid
], (void**)&unk
);
464 ERR("Could not get iface %s: %08x\n", debugstr_guid(tid_ids
[func
->tid
]), hres
);
468 hres
= ITypeInfo_Invoke(ti
, unk
, func
->id
, flags
, dp
, res
, ei
, &argerr
);
470 IUnknown_Release(unk
);
474 #define FUNCTION_THIS(iface) DEFINE_THIS(func_disp_t, IUnknown, iface)
476 static HRESULT WINAPI
Function_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
478 func_disp_t
*This
= FUNCTION_THIS(iface
);
480 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
481 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
482 *ppv
= FUNCUNKNOWN(This
);
483 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
484 return *ppv
? S_OK
: E_NOINTERFACE
;
487 return E_NOINTERFACE
;
490 IUnknown_AddRef((IUnknown
*)*ppv
);
494 static ULONG WINAPI
Function_AddRef(IUnknown
*iface
)
496 func_disp_t
*This
= FUNCTION_THIS(iface
);
498 TRACE("(%p)\n", This
);
500 return IDispatchEx_AddRef(DISPATCHEX(This
->obj
));
503 static ULONG WINAPI
Function_Release(IUnknown
*iface
)
505 func_disp_t
*This
= FUNCTION_THIS(iface
);
507 TRACE("(%p)\n", This
);
509 return IDispatchEx_Release(DISPATCHEX(This
->obj
));
512 static HRESULT
function_value(IUnknown
*iface
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
513 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
515 func_disp_t
*This
= FUNCTION_THIS(iface
);
519 case DISPATCH_METHOD
:
520 hres
= typeinfo_invoke(This
->obj
, This
->info
, flags
, params
, res
, ei
);
523 FIXME("Unimplemented flags %x\n", flags
);
532 static const IUnknownVtbl FunctionUnkVtbl
= {
533 Function_QueryInterface
,
538 static const dispex_static_data_vtbl_t function_dispex_vtbl
= {
544 static dispex_static_data_t function_dispex
= {
545 &function_dispex_vtbl
,
551 static func_disp_t
*create_func_disp(DispatchEx
*obj
, func_info_t
*info
)
555 ret
= heap_alloc_zero(sizeof(func_disp_t
));
559 ret
->lpIUnknownVtbl
= &FunctionUnkVtbl
;
560 init_dispex(&ret
->dispex
, FUNCUNKNOWN(ret
), &function_dispex
);
567 static HRESULT
function_invoke(DispatchEx
*This
, func_info_t
*func
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
,
573 case DISPATCH_METHOD
:
574 hres
= typeinfo_invoke(This
, func
, flags
, dp
, res
, ei
);
576 case DISPATCH_PROPERTYGET
: {
577 dispex_dynamic_data_t
*dynamic_data
;
579 dynamic_data
= get_dynamic_data(This
, TRUE
);
581 return E_OUTOFMEMORY
;
583 if(!dynamic_data
->func_disps
) {
584 dynamic_data
->func_disps
= heap_alloc_zero(This
->data
->data
->func_disp_cnt
* sizeof(func_disp_t
*));
585 if(!dynamic_data
->func_disps
)
586 return E_OUTOFMEMORY
;
589 if(!dynamic_data
->func_disps
[func
->func_disp_idx
]) {
590 dynamic_data
->func_disps
[func
->func_disp_idx
] = create_func_disp(This
, func
);
591 if(!dynamic_data
->func_disps
[func
->func_disp_idx
])
592 return E_OUTOFMEMORY
;
595 V_VT(res
) = VT_DISPATCH
;
596 V_DISPATCH(res
) = (IDispatch
*)DISPATCHEX(&dynamic_data
->func_disps
[func
->func_disp_idx
]->dispex
);
597 IDispatch_AddRef(V_DISPATCH(res
));
602 FIXME("Unimplemented flags %x\n", flags
);
603 case DISPATCH_PROPERTYPUT
:
610 #define DISPATCHEX_THIS(iface) DEFINE_THIS(DispatchEx, IDispatchEx, iface)
612 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
614 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
616 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
619 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
621 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
623 return IUnknown_AddRef(This
->outer
);
626 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
628 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
630 return IUnknown_Release(This
->outer
);
633 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
635 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
637 TRACE("(%p)->(%p)\n", This
, pctinfo
);
643 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
644 LCID lcid
, ITypeInfo
**ppTInfo
)
646 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
649 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
651 hres
= get_typeinfo(This
->data
->disp_tid
, ppTInfo
);
655 ITypeInfo_AddRef(*ppTInfo
);
659 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
660 LPOLESTR
*rgszNames
, UINT cNames
,
661 LCID lcid
, DISPID
*rgDispId
)
663 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
667 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
670 for(i
=0; i
< cNames
; i
++) {
671 hres
= IDispatchEx_GetDispID(DISPATCHEX(This
), rgszNames
[i
], 0, rgDispId
+i
);
679 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
680 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
681 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
683 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
685 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
686 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
688 return IDispatchEx_InvokeEx(DISPATCHEX(This
), dispIdMember
, lcid
, wFlags
,
689 pDispParams
, pVarResult
, pExcepInfo
, NULL
);
692 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
694 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
695 dynamic_prop_t
*dprop
;
700 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
702 if(grfdex
& ~(fdexNameCaseSensitive
|fdexNameEnsure
|fdexNameImplicit
))
703 FIXME("Unsupported grfdex %x\n", grfdex
);
705 data
= get_dispex_data(This
);
710 max
= data
->func_cnt
-1;
715 c
= strcmpiW(data
->name_table
[n
]->name
, bstrName
);
717 if((grfdex
& fdexNameCaseSensitive
) && strcmpW(data
->name_table
[n
]->name
, bstrName
))
720 *pid
= data
->name_table
[n
]->id
;
730 if(This
->data
->vtbl
&& This
->data
->vtbl
->get_dispid
) {
733 hres
= This
->data
->vtbl
->get_dispid(This
->outer
, bstrName
, grfdex
, pid
);
734 if(hres
!= DISP_E_UNKNOWNNAME
)
738 hres
= get_dynamic_prop(This
, bstrName
, grfdex
&fdexNameEnsure
, &dprop
);
742 *pid
= DISPID_DYNPROP_0
+ (dprop
- This
->dynamic_data
->props
);
746 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
747 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
749 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
754 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
756 if(id
== DISPID_VALUE
)
757 return dispex_value(This
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
759 if(is_custom_dispid(id
) && This
->data
->vtbl
&& This
->data
->vtbl
->invoke
)
760 return This
->data
->vtbl
->invoke(This
->outer
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
762 if(wFlags
== DISPATCH_CONSTRUCT
) {
763 FIXME("DISPATCH_CONSTRUCT not implemented\n");
767 if(is_dynamic_dispid(id
)) {
768 DWORD idx
= id
- DISPID_DYNPROP_0
;
771 if(!This
->dynamic_data
|| This
->dynamic_data
->prop_cnt
<= idx
)
772 return DISP_E_UNKNOWNNAME
;
774 var
= &This
->dynamic_data
->props
[idx
].var
;
778 DISPID named_arg
= DISPID_THIS
;
779 DISPPARAMS dp
= {NULL
, &named_arg
, 0, 1};
782 if(V_VT(var
) != VT_DISPATCH
) {
783 FIXME("invoke vt %d\n", V_VT(var
));
787 if(pdp
->cNamedArgs
) {
788 FIXME("named args not supported\n");
792 dp
.rgvarg
= heap_alloc((pdp
->cArgs
+1)*sizeof(VARIANTARG
));
794 return E_OUTOFMEMORY
;
796 dp
.cArgs
= pdp
->cArgs
+1;
797 memcpy(dp
.rgvarg
+1, pdp
->rgvarg
, pdp
->cArgs
*sizeof(VARIANTARG
));
799 V_VT(dp
.rgvarg
) = VT_DISPATCH
;
800 V_DISPATCH(dp
.rgvarg
) = (IDispatch
*)DISPATCHEX(This
);
802 hres
= IDispatch_QueryInterface(V_DISPATCH(var
), &IID_IDispatchEx
, (void**)&dispex
);
803 TRACE("%s call\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
));
804 if(SUCCEEDED(hres
)) {
805 hres
= IDispatchEx_InvokeEx(dispex
, DISPID_VALUE
, lcid
, wFlags
, &dp
, pvarRes
, pei
, pspCaller
);
806 IDispatchEx_Release(dispex
);
809 hres
= IDispatch_Invoke(V_DISPATCH(var
), DISPID_VALUE
, &IID_NULL
, lcid
, wFlags
, pdp
, pvarRes
, pei
, &err
);
811 TRACE("%s ret %08x\n", debugstr_w(This
->dynamic_data
->props
[idx
].name
), hres
);
813 heap_free(dp
.rgvarg
);
816 case INVOKE_PROPERTYGET
:
817 return VariantCopy(pvarRes
, var
);
818 case INVOKE_PROPERTYPUT
:
820 return VariantCopy(var
, pdp
->rgvarg
);
822 FIXME("unhandled wFlags %x\n", wFlags
);
827 data
= get_dispex_data(This
);
832 max
= data
->func_cnt
-1;
837 if(data
->funcs
[n
].id
== id
)
840 if(data
->funcs
[n
].id
< id
)
847 WARN("invalid id %x\n", id
);
848 return DISP_E_UNKNOWNNAME
;
851 if(data
->funcs
[n
].func_disp_idx
== -1)
852 hres
= typeinfo_invoke(This
, data
->funcs
+n
, wFlags
, pdp
, pvarRes
, pei
);
854 hres
= function_invoke(This
, data
->funcs
+n
, wFlags
, pdp
, pvarRes
, pei
);
859 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
861 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
862 FIXME("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
866 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
868 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
869 FIXME("(%p)->(%x)\n", This
, id
);
873 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
875 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
876 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
880 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
882 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
883 FIXME("(%p)->(%x %p)\n", This
, id
, pbstrName
);
887 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
889 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
890 FIXME("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
894 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
896 DispatchEx
*This
= DISPATCHEX_THIS(iface
);
897 FIXME("(%p)->(%p)\n", This
, ppunk
);
901 #undef DISPATCHEX_THIS
903 static IDispatchExVtbl DispatchExVtbl
= {
904 DispatchEx_QueryInterface
,
907 DispatchEx_GetTypeInfoCount
,
908 DispatchEx_GetTypeInfo
,
909 DispatchEx_GetIDsOfNames
,
911 DispatchEx_GetDispID
,
913 DispatchEx_DeleteMemberByName
,
914 DispatchEx_DeleteMemberByDispID
,
915 DispatchEx_GetMemberProperties
,
916 DispatchEx_GetMemberName
,
917 DispatchEx_GetNextDispID
,
918 DispatchEx_GetNameSpaceParent
921 BOOL
dispex_query_interface(DispatchEx
*This
, REFIID riid
, void **ppv
)
923 static const IID IID_UndocumentedScriptIface
=
924 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
925 static const IID IID_IDispatchJS
=
926 {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa6}};
928 if(IsEqualGUID(&IID_IDispatch
, riid
)) {
929 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
930 *ppv
= DISPATCHEX(This
);
931 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
932 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
933 *ppv
= DISPATCHEX(This
);
934 }else if(IsEqualGUID(&IID_IDispatchJS
, riid
)) {
935 TRACE("(%p)->(IID_IDispatchJS %p) returning NULL\n", This
, ppv
);
937 }else if(IsEqualGUID(&IID_UndocumentedScriptIface
, riid
)) {
938 TRACE("(%p)->(IID_UndocumentedScriptIface %p) returning NULL\n", This
, ppv
);
945 IUnknown_AddRef((IUnknown
*)*ppv
);
949 void release_dispex(DispatchEx
*This
)
951 dynamic_prop_t
*prop
;
953 if(!This
->dynamic_data
)
956 for(prop
= This
->dynamic_data
->props
; prop
< This
->dynamic_data
->props
+ This
->dynamic_data
->prop_cnt
; prop
++) {
957 VariantClear(&prop
->var
);
958 heap_free(prop
->name
);
961 heap_free(This
->dynamic_data
->props
);
963 if(This
->dynamic_data
->func_disps
) {
966 for(i
=0; i
< This
->data
->data
->func_disp_cnt
; i
++) {
967 if(This
->dynamic_data
->func_disps
[i
]) {
968 release_dispex(&This
->dynamic_data
->func_disps
[i
]->dispex
);
969 heap_free(This
->dynamic_data
->func_disps
[i
]);
973 heap_free(This
->dynamic_data
->func_disps
);
976 heap_free(This
->dynamic_data
);
979 void init_dispex(DispatchEx
*dispex
, IUnknown
*outer
, dispex_static_data_t
*data
)
981 dispex
->lpIDispatchExVtbl
= &DispatchExVtbl
;
982 dispex
->outer
= outer
;
984 dispex
->dynamic_data
= NULL
;