2011-09-05 11:14:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vbscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
|
|
|
|
|
2011-09-15 14:21:33 +02:00
|
|
|
static inline BOOL is_func_id(vbdisp_t *This, DISPID id)
|
|
|
|
{
|
|
|
|
return id < This->desc->func_cnt;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
static BOOL get_func_id(vbdisp_t *This, const WCHAR *name, vbdisp_invoke_type_t invoke_type, BOOL search_private, DISPID *id)
|
2011-09-15 14:21:13 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
for(i = invoke_type == VBDISP_ANY ? 0 : 1; i < This->desc->func_cnt; i++) {
|
|
|
|
if(invoke_type == VBDISP_ANY) {
|
|
|
|
if(!search_private && !This->desc->funcs[i].is_public)
|
|
|
|
continue;
|
|
|
|
if(!i && !This->desc->funcs[0].name) /* default value may not exist */
|
|
|
|
continue;
|
|
|
|
}else {
|
|
|
|
if(!This->desc->funcs[i].entries[invoke_type]
|
|
|
|
|| (!search_private && !This->desc->funcs[i].entries[invoke_type]->is_public))
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-15 14:21:13 +02:00
|
|
|
|
|
|
|
if(!strcmpiW(This->desc->funcs[i].name, name)) {
|
|
|
|
*id = i;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
HRESULT vbdisp_get_id(vbdisp_t *This, BSTR name, vbdisp_invoke_type_t invoke_type, BOOL search_private, DISPID *id)
|
2011-09-15 14:21:58 +02:00
|
|
|
{
|
2011-09-16 13:27:31 +02:00
|
|
|
unsigned i;
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
if(get_func_id(This, name, invoke_type, search_private, id))
|
2011-09-15 14:21:58 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2011-09-16 13:27:31 +02:00
|
|
|
for(i=0; i < This->desc->prop_cnt; i++) {
|
|
|
|
if(!search_private && !This->desc->props[i].is_public)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(!strcmpiW(This->desc->props[i].name, name)) {
|
|
|
|
*id = i + This->desc->func_cnt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 14:08:38 +02:00
|
|
|
if(This->desc->typeinfo) {
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetIDsOfNames(This->desc->typeinfo, &name, 1, id);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:21:58 +02:00
|
|
|
*id = -1;
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:27:48 +02:00
|
|
|
static VARIANT *get_propput_arg(const DISPPARAMS *dp)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for(i=0; i < dp->cNamedArgs; i++) {
|
|
|
|
if(dp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
|
|
|
|
return dp->rgvarg+i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT invoke_variant_prop(vbdisp_t *This, VARIANT *v, WORD flags, DISPPARAMS *dp, VARIANT *res)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
|
|
|
|
if(dp->cArgs) {
|
|
|
|
WARN("called with arguments\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND; /* That's what tests show */
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = VariantCopy(res, v);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DISPATCH_PROPERTYPUT: {
|
|
|
|
VARIANT *put_val;
|
|
|
|
|
|
|
|
put_val = get_propput_arg(dp);
|
|
|
|
if(!put_val) {
|
|
|
|
WARN("no value to set\n");
|
|
|
|
return DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(res)
|
|
|
|
V_VT(res) = VT_EMPTY;
|
|
|
|
|
|
|
|
hres = VariantCopy(v, put_val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-09-19 14:08:38 +02:00
|
|
|
static HRESULT invoke_builtin(vbdisp_t *This, const builtin_prop_t *prop, WORD flags, DISPPARAMS *dp, VARIANT *res)
|
|
|
|
{
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_PROPERTYGET:
|
|
|
|
if(!(prop->flags & (BP_GET|BP_GETPUT))) {
|
|
|
|
FIXME("property does not support DISPATCH_PROPERTYGET\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
|
|
|
|
if(arg_cnt(dp) < prop->min_args || arg_cnt(dp) > (prop->max_args ? prop->max_args : prop->min_args)) {
|
|
|
|
FIXME("invalid number of arguments\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prop->proc(This, dp->rgvarg, dp->cArgs, res);
|
|
|
|
case DISPATCH_PROPERTYPUT:
|
|
|
|
if(!(prop->flags & (BP_GET|BP_GETPUT))) {
|
|
|
|
FIXME("property does not support DISPATCH_PROPERTYPUT\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("call put\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
default:
|
|
|
|
FIXME("unsupported flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 14:08:15 +02:00
|
|
|
static BOOL run_terminator(vbdisp_t *This)
|
2011-09-16 13:29:37 +02:00
|
|
|
{
|
2011-09-19 14:08:15 +02:00
|
|
|
DISPPARAMS dp = {0};
|
|
|
|
|
2011-09-16 13:29:37 +02:00
|
|
|
if(This->terminator_ran)
|
2011-09-19 14:08:15 +02:00
|
|
|
return TRUE;
|
2011-09-16 13:29:37 +02:00
|
|
|
This->terminator_ran = TRUE;
|
|
|
|
|
2011-09-19 14:08:15 +02:00
|
|
|
if(!This->desc->class_terminate_id)
|
|
|
|
return TRUE;
|
2011-09-16 13:29:37 +02:00
|
|
|
|
2011-09-19 14:08:15 +02:00
|
|
|
This->ref++;
|
|
|
|
exec_script(This->desc->ctx, This->desc->funcs[This->desc->class_terminate_id].entries[VBDISP_CALLGET],
|
|
|
|
(IDispatch*)&This->IDispatchEx_iface, &dp, NULL);
|
|
|
|
return !--This->ref;
|
2011-09-16 13:29:37 +02:00
|
|
|
}
|
|
|
|
|
2011-09-16 13:27:48 +02:00
|
|
|
static void clean_props(vbdisp_t *This)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2011-09-16 13:29:47 +02:00
|
|
|
if(!This->desc)
|
|
|
|
return;
|
|
|
|
|
2011-09-16 13:27:48 +02:00
|
|
|
for(i=0; i < This->desc->prop_cnt; i++)
|
|
|
|
VariantClear(This->props+i);
|
|
|
|
}
|
|
|
|
|
2011-09-05 11:14:14 +02:00
|
|
|
static inline vbdisp_t *impl_from_IDispatchEx(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, vbdisp_t, IDispatchEx_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IDispatchEx_iface;
|
|
|
|
}else if(IsEqualGUID(&IID_IDispatch, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IDispatchEx_iface;
|
|
|
|
}else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
|
|
|
|
*ppv = &This->IDispatchEx_iface;
|
|
|
|
}else {
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
2011-09-16 13:29:37 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2011-09-05 11:14:14 +02:00
|
|
|
|
2011-09-19 14:08:15 +02:00
|
|
|
if(!ref && run_terminator(This)) {
|
2011-09-16 13:27:48 +02:00
|
|
|
clean_props(This);
|
2011-09-16 13:29:47 +02:00
|
|
|
list_remove(&This->entry);
|
2011-09-05 11:14:14 +02:00
|
|
|
heap_free(This);
|
2011-09-16 13:27:48 +02:00
|
|
|
}
|
2011-09-05 11:14:14 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid,
|
|
|
|
ITypeInfo **ppTInfo)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
|
|
|
|
LPOLESTR *rgszNames, UINT cNames, LCID lcid,
|
|
|
|
DISPID *rgDispId)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
|
|
|
|
lcid, rgDispId);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
|
|
|
|
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
|
|
|
|
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
2011-09-15 14:21:13 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
|
|
|
|
|
2011-09-16 13:29:47 +02:00
|
|
|
if(!This->desc)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2011-09-15 14:21:13 +02:00
|
|
|
if(grfdex & ~(fdexNameEnsure|fdexNameCaseInsensitive)) {
|
|
|
|
FIXME("unsupported flags %x\n", grfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
return vbdisp_get_id(This, bstrName, VBDISP_ANY, FALSE, pid);
|
2011-09-05 11:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
|
|
|
|
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
2011-09-15 14:21:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
|
|
|
|
2011-09-16 13:29:47 +02:00
|
|
|
if(!This->desc)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2011-09-15 14:21:33 +02:00
|
|
|
if(pvarRes)
|
|
|
|
V_VT(pvarRes) = VT_EMPTY;
|
|
|
|
|
|
|
|
if(id < 0)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
if(is_func_id(This, id)) {
|
|
|
|
function_t *func;
|
|
|
|
|
|
|
|
switch(wFlags) {
|
|
|
|
case DISPATCH_METHOD:
|
|
|
|
case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
|
|
|
|
func = This->desc->funcs[id].entries[VBDISP_CALLGET];
|
|
|
|
if(!func) {
|
|
|
|
FIXME("no invoke/getter\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:21:58 +02:00
|
|
|
return exec_script(This->desc->ctx, func, (IDispatch*)&This->IDispatchEx_iface, pdp, pvarRes);
|
2011-09-16 13:28:18 +02:00
|
|
|
case DISPATCH_PROPERTYPUT: {
|
|
|
|
VARIANT *put_val;
|
|
|
|
DISPPARAMS dp = {NULL, NULL, 1, 0};
|
|
|
|
|
|
|
|
if(arg_cnt(pdp)) {
|
|
|
|
FIXME("arguments not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
put_val = get_propput_arg(pdp);
|
|
|
|
if(!put_val) {
|
|
|
|
WARN("no value to set\n");
|
|
|
|
return DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dp.rgvarg = put_val;
|
|
|
|
func = This->desc->funcs[id].entries[V_VT(put_val) == VT_DISPATCH ? VBDISP_SET : VBDISP_LET];
|
|
|
|
if(!func) {
|
|
|
|
FIXME("no letter/setter\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exec_script(This->desc->ctx, func, (IDispatch*)&This->IDispatchEx_iface, &dp, NULL);
|
|
|
|
}
|
2011-09-15 14:21:33 +02:00
|
|
|
default:
|
|
|
|
FIXME("flags %x\n", wFlags);
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:27:48 +02:00
|
|
|
if(id < This->desc->prop_cnt + This->desc->func_cnt)
|
|
|
|
return invoke_variant_prop(This, This->props+(id-This->desc->func_cnt), wFlags, pdp, pvarRes);
|
|
|
|
|
2011-09-19 14:08:38 +02:00
|
|
|
if(This->desc->builtin_prop_cnt) {
|
|
|
|
unsigned min = 0, max = This->desc->builtin_prop_cnt-1, i;
|
|
|
|
|
|
|
|
while(min <= max) {
|
|
|
|
i = (min+max)/2;
|
|
|
|
if(This->desc->builtin_props[i].id == id)
|
|
|
|
return invoke_builtin(This, This->desc->builtin_props+i, wFlags, pdp, pvarRes);
|
|
|
|
if(This->desc->builtin_props[i].id < id)
|
|
|
|
min = i+1;
|
|
|
|
else
|
|
|
|
max = i-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 11:14:14 +02:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x)\n", This, id);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x %p)\n", This, id, pbstrName);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
|
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%p)\n", This, ppunk);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IDispatchExVtbl DispatchExVtbl = {
|
|
|
|
DispatchEx_QueryInterface,
|
|
|
|
DispatchEx_AddRef,
|
|
|
|
DispatchEx_Release,
|
|
|
|
DispatchEx_GetTypeInfoCount,
|
|
|
|
DispatchEx_GetTypeInfo,
|
|
|
|
DispatchEx_GetIDsOfNames,
|
|
|
|
DispatchEx_Invoke,
|
|
|
|
DispatchEx_GetDispID,
|
|
|
|
DispatchEx_InvokeEx,
|
|
|
|
DispatchEx_DeleteMemberByName,
|
|
|
|
DispatchEx_DeleteMemberByDispID,
|
|
|
|
DispatchEx_GetMemberProperties,
|
|
|
|
DispatchEx_GetMemberName,
|
|
|
|
DispatchEx_GetNextDispID,
|
|
|
|
DispatchEx_GetNameSpaceParent
|
|
|
|
};
|
|
|
|
|
2011-09-15 14:21:58 +02:00
|
|
|
static inline vbdisp_t *unsafe_impl_from_IDispatch(IDispatch *iface)
|
|
|
|
{
|
|
|
|
return iface->lpVtbl == (IDispatchVtbl*)&DispatchExVtbl
|
|
|
|
? CONTAINING_RECORD(iface, vbdisp_t, IDispatchEx_iface)
|
|
|
|
: NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:18:43 +02:00
|
|
|
HRESULT create_vbdisp(const class_desc_t *desc, vbdisp_t **ret)
|
2011-09-05 11:14:14 +02:00
|
|
|
{
|
|
|
|
vbdisp_t *vbdisp;
|
|
|
|
|
2011-09-16 19:36:52 +02:00
|
|
|
vbdisp = heap_alloc_zero( FIELD_OFFSET( vbdisp_t, props[desc->prop_cnt] ));
|
2011-09-05 11:14:14 +02:00
|
|
|
if(!vbdisp)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
vbdisp->IDispatchEx_iface.lpVtbl = &DispatchExVtbl;
|
|
|
|
vbdisp->ref = 1;
|
2011-09-15 14:18:43 +02:00
|
|
|
vbdisp->desc = desc;
|
2011-09-05 11:14:14 +02:00
|
|
|
|
2011-09-16 13:29:25 +02:00
|
|
|
if(desc->class_initialize_id) {
|
|
|
|
DISPPARAMS dp = {0};
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = exec_script(desc->ctx, desc->funcs[desc->class_initialize_id].entries[VBDISP_CALLGET],
|
|
|
|
(IDispatch*)&vbdisp->IDispatchEx_iface, &dp, NULL);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatchEx_Release(&vbdisp->IDispatchEx_iface);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:29:47 +02:00
|
|
|
list_add_tail(&desc->ctx->objects, &vbdisp->entry);
|
2011-09-05 11:14:14 +02:00
|
|
|
*ret = vbdisp;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:29:47 +02:00
|
|
|
void collect_objects(script_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
vbdisp_t *iter, *iter2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &ctx->objects, vbdisp_t, entry)
|
|
|
|
run_terminator(iter);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &ctx->objects, vbdisp_t, entry) {
|
2011-09-19 14:08:15 +02:00
|
|
|
IDispatchEx_AddRef(&iter->IDispatchEx_iface);
|
2011-09-16 13:29:47 +02:00
|
|
|
clean_props(iter);
|
|
|
|
iter->desc = NULL;
|
2011-09-19 14:08:15 +02:00
|
|
|
IDispatchEx_Release(&iter->IDispatchEx_iface);
|
2011-09-16 13:29:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:28:18 +02:00
|
|
|
HRESULT disp_get_id(IDispatch *disp, BSTR name, vbdisp_invoke_type_t invoke_type, BOOL search_private, DISPID *id)
|
2011-09-08 14:54:37 +02:00
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
2011-09-15 14:21:58 +02:00
|
|
|
vbdisp_t *vbdisp;
|
2011-09-08 14:54:37 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2011-09-15 14:21:58 +02:00
|
|
|
vbdisp = unsafe_impl_from_IDispatch(disp);
|
|
|
|
if(vbdisp)
|
2011-09-16 13:28:18 +02:00
|
|
|
return vbdisp_get_id(vbdisp, name, invoke_type, search_private, id);
|
2011-09-08 14:54:37 +02:00
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
TRACE("unsing IDispatch\n");
|
|
|
|
return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseInsensitive, id);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT disp_call(script_ctx_t *ctx, IDispatch *disp, DISPID id, DISPPARAMS *dp, VARIANT *retv)
|
|
|
|
{
|
|
|
|
const WORD flags = DISPATCH_METHOD|(retv ? DISPATCH_PROPERTYGET : 0);
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
EXCEPINFO ei;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
if(retv)
|
|
|
|
V_VT(retv) = VT_EMPTY;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
UINT err = 0;
|
|
|
|
|
|
|
|
TRACE("using IDispatch\n");
|
|
|
|
return IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, retv, &ei, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, retv, &ei, NULL /* CALLER_FIXME */);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
return hres;
|
|
|
|
}
|
2011-09-12 12:33:03 +02:00
|
|
|
|
|
|
|
HRESULT disp_propput(script_ctx_t *ctx, IDispatch *disp, DISPID id, VARIANT *val)
|
|
|
|
{
|
|
|
|
DISPID propput_dispid = DISPID_PROPERTYPUT;
|
|
|
|
DISPPARAMS dp = {val, &propput_dispid, 1, 1};
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
EXCEPINFO ei = {0};
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL /* FIXME! */);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
ULONG err = 0;
|
|
|
|
|
|
|
|
TRACE("using IDispatch\n");
|
|
|
|
hres = IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|