2 * Copyright 2011 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 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(vbscript
);
27 #define FDEX_VERSION_MASK 0xf0000000
29 static inline BOOL
is_func_id(vbdisp_t
*This
, DISPID id
)
31 return id
< This
->desc
->func_cnt
;
34 static BOOL
get_func_id(vbdisp_t
*This
, const WCHAR
*name
, vbdisp_invoke_type_t invoke_type
, BOOL search_private
, DISPID
*id
)
38 for(i
= invoke_type
== VBDISP_ANY
? 0 : 1; i
< This
->desc
->func_cnt
; i
++) {
39 if(invoke_type
== VBDISP_ANY
) {
40 if(!search_private
&& !This
->desc
->funcs
[i
].is_public
)
42 if(!i
&& !This
->desc
->funcs
[0].name
) /* default value may not exist */
45 if(!This
->desc
->funcs
[i
].entries
[invoke_type
]
46 || (!search_private
&& !This
->desc
->funcs
[i
].entries
[invoke_type
]->is_public
))
50 if(!strcmpiW(This
->desc
->funcs
[i
].name
, name
)) {
59 HRESULT
vbdisp_get_id(vbdisp_t
*This
, BSTR name
, vbdisp_invoke_type_t invoke_type
, BOOL search_private
, DISPID
*id
)
63 if(get_func_id(This
, name
, invoke_type
, search_private
, id
))
66 for(i
=0; i
< This
->desc
->prop_cnt
; i
++) {
67 if(!search_private
&& !This
->desc
->props
[i
].is_public
)
70 if(!strcmpiW(This
->desc
->props
[i
].name
, name
)) {
71 *id
= i
+ This
->desc
->func_cnt
;
76 if(This
->desc
->typeinfo
) {
79 hres
= ITypeInfo_GetIDsOfNames(This
->desc
->typeinfo
, &name
, 1, id
);
85 return DISP_E_UNKNOWNNAME
;
88 static VARIANT
*get_propput_arg(const DISPPARAMS
*dp
)
92 for(i
=0; i
< dp
->cNamedArgs
; i
++) {
93 if(dp
->rgdispidNamedArgs
[i
] == DISPID_PROPERTYPUT
)
100 static HRESULT
invoke_variant_prop(VARIANT
*v
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
)
105 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
106 case DISPATCH_PROPERTYGET
:
108 WARN("called with arguments\n");
109 return DISP_E_MEMBERNOTFOUND
; /* That's what tests show */
112 hres
= VariantCopy(res
, v
);
115 case DISPATCH_PROPERTYPUT
: {
118 put_val
= get_propput_arg(dp
);
120 WARN("no value to set\n");
121 return DISP_E_PARAMNOTOPTIONAL
;
125 V_VT(res
) = VT_EMPTY
;
127 hres
= VariantCopy(v
, put_val
);
132 FIXME("unimplemented flags %x\n", flags
);
139 static HRESULT
invoke_builtin(vbdisp_t
*This
, const builtin_prop_t
*prop
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*res
)
141 VARIANT
*args
, arg_buf
[8];
145 case DISPATCH_PROPERTYGET
:
146 if(!(prop
->flags
& (BP_GET
|BP_GETPUT
))) {
147 FIXME("property does not support DISPATCH_PROPERTYGET\n");
151 case DISPATCH_PROPERTYGET
|DISPATCH_METHOD
:
153 case DISPATCH_METHOD
:
154 if(prop
->flags
& (BP_GET
|BP_GETPUT
)) {
155 FIXME("Call on property\n");
159 case DISPATCH_PROPERTYPUT
:
160 if(!(prop
->flags
& (BP_GET
|BP_GETPUT
))) {
161 FIXME("property does not support DISPATCH_PROPERTYPUT\n");
168 FIXME("unsupported flags %x\n", flags
);
174 if(argn
< prop
->min_args
|| argn
> (prop
->max_args
? prop
->max_args
: prop
->min_args
)) {
175 FIXME("invalid number of arguments\n");
182 if(V_VT(dp
->rgvarg
) == (VT_BYREF
|VT_VARIANT
))
183 args
= V_VARIANTREF(dp
->rgvarg
);
187 assert(argn
< sizeof(arg_buf
)/sizeof(*arg_buf
));
189 for(i
=0; i
< argn
; i
++) {
190 if(V_VT(dp
->rgvarg
+i
) == (VT_BYREF
|VT_VARIANT
)) {
191 for(i
=0; i
< argn
; i
++) {
192 if(V_VT(dp
->rgvarg
+i
) == (VT_BYREF
|VT_VARIANT
))
193 arg_buf
[i
] = *V_VARIANTREF(dp
->rgvarg
+i
);
195 arg_buf
[i
] = dp
->rgvarg
[i
];
203 return prop
->proc(This
, args
, dp
->cArgs
, res
);
206 static BOOL
run_terminator(vbdisp_t
*This
)
210 if(This
->terminator_ran
)
212 This
->terminator_ran
= TRUE
;
214 if(!This
->desc
->class_terminate_id
)
218 exec_script(This
->desc
->ctx
, This
->desc
->funcs
[This
->desc
->class_terminate_id
].entries
[VBDISP_CALLGET
],
219 (IDispatch
*)&This
->IDispatchEx_iface
, &dp
, NULL
);
223 static void clean_props(vbdisp_t
*This
)
230 for(i
=0; i
< This
->desc
->prop_cnt
; i
++)
231 VariantClear(This
->props
+i
);
234 static inline vbdisp_t
*impl_from_IDispatchEx(IDispatchEx
*iface
)
236 return CONTAINING_RECORD(iface
, vbdisp_t
, IDispatchEx_iface
);
239 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
241 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
243 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
244 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
245 *ppv
= &This
->IDispatchEx_iface
;
246 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
247 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
248 *ppv
= &This
->IDispatchEx_iface
;
249 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
250 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
251 *ppv
= &This
->IDispatchEx_iface
;
253 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
255 return E_NOINTERFACE
;
258 IUnknown_AddRef((IUnknown
*)*ppv
);
262 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
264 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
265 LONG ref
= InterlockedIncrement(&This
->ref
);
267 TRACE("(%p) ref=%d\n", This
, ref
);
272 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
274 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
275 LONG ref
= InterlockedDecrement(&This
->ref
);
277 TRACE("(%p) ref=%d\n", This
, ref
);
279 if(!ref
&& run_terminator(This
)) {
281 list_remove(&This
->entry
);
288 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
290 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
292 TRACE("(%p)->(%p)\n", This
, pctinfo
);
298 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
, LCID lcid
,
301 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
302 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
306 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
307 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
,
310 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
311 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
316 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
317 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
318 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
320 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
321 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
322 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
326 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
328 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
330 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
332 grfdex
&= ~FDEX_VERSION_MASK
;
337 /* Tests show that fdexNameCaseSensitive is ignored */
339 if(grfdex
& ~(fdexNameEnsure
|fdexNameCaseInsensitive
|fdexNameCaseSensitive
)) {
340 FIXME("unsupported flags %x\n", grfdex
);
344 return vbdisp_get_id(This
, bstrName
, VBDISP_ANY
, FALSE
, pid
);
347 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
348 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
350 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
352 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
358 V_VT(pvarRes
) = VT_EMPTY
;
361 return DISP_E_MEMBERNOTFOUND
;
363 if(is_func_id(This
, id
)) {
367 case DISPATCH_METHOD
:
368 case DISPATCH_METHOD
|DISPATCH_PROPERTYGET
:
369 func
= This
->desc
->funcs
[id
].entries
[VBDISP_CALLGET
];
371 FIXME("no invoke/getter\n");
372 return DISP_E_MEMBERNOTFOUND
;
375 return exec_script(This
->desc
->ctx
, func
, (IDispatch
*)&This
->IDispatchEx_iface
, pdp
, pvarRes
);
376 case DISPATCH_PROPERTYPUT
: {
378 DISPPARAMS dp
= {NULL
, NULL
, 1, 0};
381 FIXME("arguments not implemented\n");
385 put_val
= get_propput_arg(pdp
);
387 WARN("no value to set\n");
388 return DISP_E_PARAMNOTOPTIONAL
;
392 func
= This
->desc
->funcs
[id
].entries
[V_VT(put_val
) == VT_DISPATCH
? VBDISP_SET
: VBDISP_LET
];
394 FIXME("no letter/setter\n");
395 return DISP_E_MEMBERNOTFOUND
;
398 return exec_script(This
->desc
->ctx
, func
, (IDispatch
*)&This
->IDispatchEx_iface
, &dp
, NULL
);
401 FIXME("flags %x\n", wFlags
);
402 return DISP_E_MEMBERNOTFOUND
;
406 if(id
< This
->desc
->prop_cnt
+ This
->desc
->func_cnt
)
407 return invoke_variant_prop(This
->props
+(id
-This
->desc
->func_cnt
), wFlags
, pdp
, pvarRes
);
409 if(This
->desc
->builtin_prop_cnt
) {
410 unsigned min
= 0, max
= This
->desc
->builtin_prop_cnt
-1, i
;
414 if(This
->desc
->builtin_props
[i
].id
== id
)
415 return invoke_builtin(This
, This
->desc
->builtin_props
+i
, wFlags
, pdp
, pvarRes
);
416 if(This
->desc
->builtin_props
[i
].id
< id
)
423 return DISP_E_MEMBERNOTFOUND
;
426 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
428 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
429 FIXME("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
433 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
435 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
436 FIXME("(%p)->(%x)\n", This
, id
);
440 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
442 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
443 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
447 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
449 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
450 FIXME("(%p)->(%x %p)\n", This
, id
, pbstrName
);
454 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
456 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
457 FIXME("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
461 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
463 vbdisp_t
*This
= impl_from_IDispatchEx(iface
);
464 FIXME("(%p)->(%p)\n", This
, ppunk
);
468 static IDispatchExVtbl DispatchExVtbl
= {
469 DispatchEx_QueryInterface
,
472 DispatchEx_GetTypeInfoCount
,
473 DispatchEx_GetTypeInfo
,
474 DispatchEx_GetIDsOfNames
,
476 DispatchEx_GetDispID
,
478 DispatchEx_DeleteMemberByName
,
479 DispatchEx_DeleteMemberByDispID
,
480 DispatchEx_GetMemberProperties
,
481 DispatchEx_GetMemberName
,
482 DispatchEx_GetNextDispID
,
483 DispatchEx_GetNameSpaceParent
486 static inline vbdisp_t
*unsafe_impl_from_IDispatch(IDispatch
*iface
)
488 return iface
->lpVtbl
== (IDispatchVtbl
*)&DispatchExVtbl
489 ? CONTAINING_RECORD(iface
, vbdisp_t
, IDispatchEx_iface
)
493 HRESULT
create_vbdisp(const class_desc_t
*desc
, vbdisp_t
**ret
)
497 vbdisp
= heap_alloc_zero( FIELD_OFFSET( vbdisp_t
, props
[desc
->prop_cnt
] ));
499 return E_OUTOFMEMORY
;
501 vbdisp
->IDispatchEx_iface
.lpVtbl
= &DispatchExVtbl
;
505 list_add_tail(&desc
->ctx
->objects
, &vbdisp
->entry
);
507 if(desc
->class_initialize_id
) {
511 hres
= exec_script(desc
->ctx
, desc
->funcs
[desc
->class_initialize_id
].entries
[VBDISP_CALLGET
],
512 (IDispatch
*)&vbdisp
->IDispatchEx_iface
, &dp
, NULL
);
514 IDispatchEx_Release(&vbdisp
->IDispatchEx_iface
);
523 static HRESULT
Procedure_invoke(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
525 script_ctx_t
*ctx
= This
->desc
->ctx
;
530 IActiveScriptSite_OnEnterScript(ctx
->site
);
531 hres
= exec_script(ctx
, This
->desc
->value_func
, NULL
, NULL
, NULL
);
532 IActiveScriptSite_OnLeaveScript(ctx
->site
);
537 static const builtin_prop_t procedure_props
[] = {
538 {DISPID_VALUE
, Procedure_invoke
, 0}
541 HRESULT
create_procedure_disp(script_ctx_t
*ctx
, vbscode_t
*code
, IDispatch
**ret
)
547 desc
= heap_alloc_zero(sizeof(*desc
));
549 return E_OUTOFMEMORY
;
552 desc
->builtin_prop_cnt
= sizeof(procedure_props
)/sizeof(*procedure_props
);
553 desc
->builtin_props
= procedure_props
;
554 desc
->value_func
= &code
->main_code
;
556 hres
= create_vbdisp(desc
, &vbdisp
);
562 desc
->next
= ctx
->procs
;
565 *ret
= (IDispatch
*)&vbdisp
->IDispatchEx_iface
;
569 struct _ident_map_t
{
578 static inline DISPID
ident_to_id(ScriptDisp
*This
, ident_map_t
*ident
)
580 return (ident
-This
->ident_map
)+1;
583 static inline ident_map_t
*id_to_ident(ScriptDisp
*This
, DISPID id
)
585 return 0 < id
&& id
<= This
->ident_map_cnt
? This
->ident_map
+id
-1 : NULL
;
588 static ident_map_t
*add_ident(ScriptDisp
*This
, const WCHAR
*name
)
592 if(!This
->ident_map_size
) {
593 This
->ident_map
= heap_alloc(4 * sizeof(*This
->ident_map
));
596 This
->ident_map_size
= 4;
597 }else if(This
->ident_map_cnt
== This
->ident_map_size
) {
598 ident_map_t
*new_map
;
600 new_map
= heap_realloc(This
->ident_map
, 2*This
->ident_map_size
*sizeof(*new_map
));
603 This
->ident_map
= new_map
;
604 This
->ident_map_size
*= 2;
607 ret
= This
->ident_map
+ This
->ident_map_cnt
++;
612 static inline ScriptDisp
*ScriptDisp_from_IDispatchEx(IDispatchEx
*iface
)
614 return CONTAINING_RECORD(iface
, ScriptDisp
, IDispatchEx_iface
);
617 static HRESULT WINAPI
ScriptDisp_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
619 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
621 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
622 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
623 *ppv
= &This
->IDispatchEx_iface
;
624 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
625 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
626 *ppv
= &This
->IDispatchEx_iface
;
627 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
628 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
629 *ppv
= &This
->IDispatchEx_iface
;
631 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
633 return E_NOINTERFACE
;
636 IUnknown_AddRef((IUnknown
*)*ppv
);
640 static ULONG WINAPI
ScriptDisp_AddRef(IDispatchEx
*iface
)
642 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
643 LONG ref
= InterlockedIncrement(&This
->ref
);
645 TRACE("(%p) ref=%d\n", This
, ref
);
650 static ULONG WINAPI
ScriptDisp_Release(IDispatchEx
*iface
)
652 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
653 LONG ref
= InterlockedDecrement(&This
->ref
);
655 TRACE("(%p) ref=%d\n", This
, ref
);
659 heap_free(This
->ident_map
);
666 static HRESULT WINAPI
ScriptDisp_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
668 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
670 TRACE("(%p)->(%p)\n", This
, pctinfo
);
676 static HRESULT WINAPI
ScriptDisp_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
, LCID lcid
,
679 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
680 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
684 static HRESULT WINAPI
ScriptDisp_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
685 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
,
688 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
689 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
694 static HRESULT WINAPI
ScriptDisp_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
695 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
696 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
698 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
699 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
700 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
704 static HRESULT WINAPI
ScriptDisp_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
706 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
711 TRACE("(%p)->(%s %x %p)\n", This
, debugstr_w(bstrName
), grfdex
, pid
);
716 for(ident
= This
->ident_map
; ident
< This
->ident_map
+This
->ident_map_cnt
; ident
++) {
717 if(!strcmpiW(ident
->name
, bstrName
)) {
718 *pid
= ident_to_id(This
, ident
);
723 for(var
= This
->ctx
->global_vars
; var
; var
= var
->next
) {
724 if(!strcmpiW(var
->name
, bstrName
)) {
725 ident
= add_ident(This
, var
->name
);
727 return E_OUTOFMEMORY
;
729 ident
->is_var
= TRUE
;
731 *pid
= ident_to_id(This
, ident
);
736 for(func
= This
->ctx
->global_funcs
; func
; func
= func
->next
) {
737 if(!strcmpiW(func
->name
, bstrName
)) {
738 ident
= add_ident(This
, func
->name
);
740 return E_OUTOFMEMORY
;
742 ident
->is_var
= FALSE
;
743 ident
->u
.func
= func
;
744 *pid
= ident_to_id(This
, ident
);
750 return DISP_E_UNKNOWNNAME
;
753 static HRESULT WINAPI
ScriptDisp_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
754 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
756 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
760 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
762 ident
= id_to_ident(This
, id
);
764 return DISP_E_MEMBERNOTFOUND
;
767 if(ident
->u
.var
->is_const
) {
768 FIXME("const not supported\n");
772 return invoke_variant_prop(&ident
->u
.var
->v
, wFlags
, pdp
, pvarRes
);
776 IActiveScriptSite_OnEnterScript(This
->ctx
->site
);
777 hres
= exec_script(This
->ctx
, ident
->u
.func
, NULL
, pdp
, pvarRes
);
778 IActiveScriptSite_OnLeaveScript(This
->ctx
->site
);
783 static HRESULT WINAPI
ScriptDisp_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
785 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
786 FIXME("(%p)->(%s %x)\n", This
, debugstr_w(bstrName
), grfdex
);
790 static HRESULT WINAPI
ScriptDisp_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
792 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
793 FIXME("(%p)->(%x)\n", This
, id
);
797 static HRESULT WINAPI
ScriptDisp_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
799 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
800 FIXME("(%p)->(%x %x %p)\n", This
, id
, grfdexFetch
, pgrfdex
);
804 static HRESULT WINAPI
ScriptDisp_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
806 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
807 FIXME("(%p)->(%x %p)\n", This
, id
, pbstrName
);
811 static HRESULT WINAPI
ScriptDisp_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
813 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
814 FIXME("(%p)->(%x %x %p)\n", This
, grfdex
, id
, pid
);
818 static HRESULT WINAPI
ScriptDisp_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
820 ScriptDisp
*This
= ScriptDisp_from_IDispatchEx(iface
);
821 FIXME("(%p)->(%p)\n", This
, ppunk
);
825 static IDispatchExVtbl ScriptDispVtbl
= {
826 ScriptDisp_QueryInterface
,
829 ScriptDisp_GetTypeInfoCount
,
830 ScriptDisp_GetTypeInfo
,
831 ScriptDisp_GetIDsOfNames
,
833 ScriptDisp_GetDispID
,
835 ScriptDisp_DeleteMemberByName
,
836 ScriptDisp_DeleteMemberByDispID
,
837 ScriptDisp_GetMemberProperties
,
838 ScriptDisp_GetMemberName
,
839 ScriptDisp_GetNextDispID
,
840 ScriptDisp_GetNameSpaceParent
843 HRESULT
create_script_disp(script_ctx_t
*ctx
, ScriptDisp
**ret
)
845 ScriptDisp
*script_disp
;
847 script_disp
= heap_alloc_zero(sizeof(*script_disp
));
849 return E_OUTOFMEMORY
;
851 script_disp
->IDispatchEx_iface
.lpVtbl
= &ScriptDispVtbl
;
852 script_disp
->ref
= 1;
853 script_disp
->ctx
= ctx
;
859 void collect_objects(script_ctx_t
*ctx
)
861 vbdisp_t
*iter
, *iter2
;
863 LIST_FOR_EACH_ENTRY_SAFE(iter
, iter2
, &ctx
->objects
, vbdisp_t
, entry
)
864 run_terminator(iter
);
866 while(!list_empty(&ctx
->objects
)) {
867 iter
= LIST_ENTRY(list_head(&ctx
->objects
), vbdisp_t
, entry
);
869 IDispatchEx_AddRef(&iter
->IDispatchEx_iface
);
872 list_remove(&iter
->entry
);
873 list_init(&iter
->entry
);
874 IDispatchEx_Release(&iter
->IDispatchEx_iface
);
878 HRESULT
disp_get_id(IDispatch
*disp
, BSTR name
, vbdisp_invoke_type_t invoke_type
, BOOL search_private
, DISPID
*id
)
884 vbdisp
= unsafe_impl_from_IDispatch(disp
);
886 return vbdisp_get_id(vbdisp
, name
, invoke_type
, search_private
, id
);
888 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
890 TRACE("using IDispatch\n");
891 return IDispatch_GetIDsOfNames(disp
, &IID_NULL
, &name
, 1, 0, id
);
894 hres
= IDispatchEx_GetDispID(dispex
, name
, fdexNameCaseInsensitive
, id
);
895 IDispatchEx_Release(dispex
);
899 HRESULT
disp_call(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, DISPPARAMS
*dp
, VARIANT
*retv
)
901 const WORD flags
= DISPATCH_METHOD
|(retv
? DISPATCH_PROPERTYGET
: 0);
906 memset(&ei
, 0, sizeof(ei
));
908 V_VT(retv
) = VT_EMPTY
;
910 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
914 TRACE("using IDispatch\n");
915 return IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, flags
, dp
, retv
, &ei
, &err
);
918 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, flags
, dp
, retv
, &ei
, NULL
/* CALLER_FIXME */);
919 IDispatchEx_Release(dispex
);
923 HRESULT
disp_propput(script_ctx_t
*ctx
, IDispatch
*disp
, DISPID id
, DISPPARAMS
*dp
)
929 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
930 if(SUCCEEDED(hres
)) {
931 hres
= IDispatchEx_InvokeEx(dispex
, id
, ctx
->lcid
, DISPATCH_PROPERTYPUT
, dp
, NULL
, &ei
, NULL
/* FIXME! */);
932 IDispatchEx_Release(dispex
);
936 TRACE("using IDispatch\n");
937 hres
= IDispatch_Invoke(disp
, id
, &IID_NULL
, ctx
->lcid
, DISPATCH_PROPERTYPUT
, dp
, NULL
, &ei
, &err
);