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
|
|
|
|
*/
|
|
|
|
|
2011-12-30 17:00:02 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2011-09-05 11:14:14 +02:00
|
|
|
#include "vbscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
|
|
|
|
|
2019-12-06 13:45:52 +01:00
|
|
|
static const GUID GUID_VBScriptTypeInfo = {0xc59c6b12,0xf6c1,0x11cf,{0x88,0x35,0x00,0xa0,0xc9,0x11,0xe8,0xb2}};
|
|
|
|
|
2019-11-06 17:35:16 +01:00
|
|
|
#define DISPID_FUNCTION_MASK 0x20000000
|
2012-07-10 12:17:32 +02:00
|
|
|
#define FDEX_VERSION_MASK 0xf0000000
|
|
|
|
|
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;
|
|
|
|
|
2020-10-13 18:58:21 +02:00
|
|
|
for(i = 0; i < This->desc->func_cnt; i++) {
|
2011-09-16 13:28:18 +02:00
|
|
|
if(invoke_type == VBDISP_ANY) {
|
|
|
|
if(!search_private && !This->desc->funcs[i].is_public)
|
|
|
|
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
|
|
|
|
2020-10-13 18:58:21 +02:00
|
|
|
if(This->desc->funcs[i].name && !wcsicmp(This->desc->funcs[i].name, name)) {
|
2011-09-15 14:21:13 +02:00
|
|
|
*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;
|
|
|
|
|
2019-06-25 08:38:01 +02:00
|
|
|
if(!wcsicmp(This->desc->props[i].name, name)) {
|
2011-09-16 13:27:31 +02:00
|
|
|
*id = i + This->desc->func_cnt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:21:58 +02:00
|
|
|
*id = -1;
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:40:51 +01:00
|
|
|
static HRESULT get_propput_arg(script_ctx_t *ctx, const DISPPARAMS *dp, WORD flags, VARIANT *v, BOOL *is_owned)
|
2011-09-16 13:27:48 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for(i=0; i < dp->cNamedArgs; i++) {
|
|
|
|
if(dp->rgdispidNamedArgs[i] == DISPID_PROPERTYPUT)
|
2015-03-03 14:40:51 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(i == dp->cNamedArgs) {
|
|
|
|
WARN("no value to set\n");
|
|
|
|
return DISP_E_PARAMNOTOPTIONAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*v = dp->rgvarg[i];
|
|
|
|
if(V_VT(v) == (VT_VARIANT|VT_BYREF))
|
|
|
|
*v = *V_VARIANTREF(v);
|
|
|
|
*is_owned = FALSE;
|
|
|
|
|
|
|
|
if(V_VT(v) == VT_DISPATCH) {
|
|
|
|
if(!(flags & DISPATCH_PROPERTYPUTREF)) {
|
|
|
|
HRESULT hres;
|
|
|
|
|
2015-03-05 15:49:02 +01:00
|
|
|
hres = get_disp_value(ctx, V_DISPATCH(v), v);
|
2015-03-03 14:40:51 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*is_owned = TRUE;
|
|
|
|
}
|
2015-03-03 14:40:59 +01:00
|
|
|
}else if(!(flags & DISPATCH_PROPERTYPUT)) {
|
|
|
|
WARN("%s can't be assigned without DISPATCH_PROPERTYPUT flag\n", debugstr_variant(v));
|
|
|
|
return DISP_E_EXCEPTION;
|
2011-09-16 13:27:48 +02:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:40:51 +01:00
|
|
|
return S_OK;
|
2011-09-16 13:27:48 +02:00
|
|
|
}
|
|
|
|
|
2015-03-03 14:40:51 +01:00
|
|
|
static HRESULT invoke_variant_prop(script_ctx_t *ctx, VARIANT *v, WORD flags, DISPPARAMS *dp, VARIANT *res)
|
2011-09-16 13:27:48 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_PROPERTYGET|DISPATCH_METHOD:
|
2012-09-10 10:34:38 +02:00
|
|
|
case DISPATCH_PROPERTYGET:
|
2011-09-16 13:27:48 +02:00
|
|
|
if(dp->cArgs) {
|
|
|
|
WARN("called with arguments\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND; /* That's what tests show */
|
|
|
|
}
|
|
|
|
|
2014-03-08 14:52:44 +01:00
|
|
|
hres = VariantCopyInd(res, v);
|
2011-09-16 13:27:48 +02:00
|
|
|
break;
|
|
|
|
|
2015-03-03 14:40:24 +01:00
|
|
|
case DISPATCH_PROPERTYPUT:
|
|
|
|
case DISPATCH_PROPERTYPUTREF:
|
|
|
|
case DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF: {
|
2015-03-03 14:40:51 +01:00
|
|
|
VARIANT put_val;
|
|
|
|
BOOL own_val;
|
2011-09-16 13:27:48 +02:00
|
|
|
|
2015-03-03 14:40:51 +01:00
|
|
|
hres = get_propput_arg(ctx, dp, flags, &put_val, &own_val);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2011-09-16 13:27:48 +02:00
|
|
|
|
2014-03-07 14:27:12 +01:00
|
|
|
if(arg_cnt(dp)) {
|
|
|
|
FIXME("Arguments not supported\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:27:48 +02:00
|
|
|
if(res)
|
|
|
|
V_VT(res) = VT_EMPTY;
|
|
|
|
|
2015-03-03 14:40:51 +01:00
|
|
|
if(own_val)
|
|
|
|
*v = put_val;
|
|
|
|
else
|
|
|
|
hres = VariantCopyInd(v, &put_val);
|
2011-09-16 13:27:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2019-10-17 22:46:12 +02:00
|
|
|
static HRESULT invoke_vbdisp(vbdisp_t *This, DISPID id, DWORD flags, BOOL extern_caller, DISPPARAMS *params, VARIANT *res)
|
|
|
|
{
|
|
|
|
if(id < 0)
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
if(is_func_id(This, id)) {
|
|
|
|
function_t *func;
|
|
|
|
|
|
|
|
TRACE("%p->%s\n", This, debugstr_w(This->desc->funcs[id].name));
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_PROPERTYGET:
|
|
|
|
func = This->desc->funcs[id].entries[VBDISP_CALLGET];
|
2020-10-13 18:58:06 +02:00
|
|
|
if(!func || func->type != FUNC_PROPGET) {
|
2019-10-17 22:46:12 +02:00
|
|
|
WARN("no getter\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2019-10-17 22:46:17 +02:00
|
|
|
return exec_script(This->desc->ctx, extern_caller, func, This, params, res);
|
2019-10-17 22:46:12 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-10-17 22:46:17 +02:00
|
|
|
return exec_script(This->desc->ctx, extern_caller, func, This, params, res);
|
|
|
|
|
2019-10-17 22:46:12 +02:00
|
|
|
case DISPATCH_PROPERTYPUT:
|
|
|
|
case DISPATCH_PROPERTYPUTREF:
|
|
|
|
case DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF: {
|
|
|
|
DISPPARAMS dp = {NULL, NULL, 1, 0};
|
|
|
|
BOOL needs_release;
|
2020-11-17 21:11:32 +01:00
|
|
|
VARIANT buf[6];
|
2019-10-17 22:46:12 +02:00
|
|
|
HRESULT hres;
|
2020-11-17 21:11:32 +01:00
|
|
|
INT i;
|
|
|
|
|
|
|
|
dp.cArgs = arg_cnt(params) + 1;
|
|
|
|
if(dp.cArgs > ARRAY_SIZE(buf)) {
|
|
|
|
dp.rgvarg = heap_alloc(dp.cArgs*sizeof(VARIANT));
|
|
|
|
if(!dp.rgvarg)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}else {
|
|
|
|
dp.rgvarg = buf;
|
2019-10-17 22:46:12 +02:00
|
|
|
}
|
|
|
|
|
2020-11-17 21:11:32 +01:00
|
|
|
hres = get_propput_arg(This->desc->ctx, params, flags, dp.rgvarg, &needs_release);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
if(dp.rgvarg != buf)
|
|
|
|
heap_free(dp.rgvarg);
|
2019-10-17 22:46:12 +02:00
|
|
|
return hres;
|
2020-11-17 21:11:32 +01:00
|
|
|
}
|
2019-10-17 22:46:12 +02:00
|
|
|
|
2020-11-17 21:11:32 +01:00
|
|
|
func = This->desc->funcs[id].entries[V_VT(dp.rgvarg) == VT_DISPATCH ? VBDISP_SET : VBDISP_LET];
|
2019-10-17 22:46:12 +02:00
|
|
|
if(!func) {
|
|
|
|
FIXME("no letter/setter\n");
|
2020-11-17 21:11:32 +01:00
|
|
|
if(dp.rgvarg != buf)
|
|
|
|
heap_free(dp.rgvarg);
|
2019-10-17 22:46:12 +02:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
2020-11-17 21:11:32 +01:00
|
|
|
for(i=1; i < dp.cArgs; i++) {
|
|
|
|
dp.rgvarg[i]=params->rgvarg[params->cNamedArgs+i-1];
|
|
|
|
}
|
|
|
|
|
2019-10-17 22:46:17 +02:00
|
|
|
hres = exec_script(This->desc->ctx, extern_caller, func, This, &dp, NULL);
|
2019-10-17 22:46:12 +02:00
|
|
|
if(needs_release)
|
2020-11-17 21:11:32 +01:00
|
|
|
VariantClear(dp.rgvarg);
|
|
|
|
if(dp.rgvarg != buf)
|
|
|
|
heap_free(dp.rgvarg);
|
2019-10-17 22:46:12 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("flags %x\n", flags);
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-17 22:46:45 +02:00
|
|
|
if(id >= This->desc->prop_cnt + This->desc->func_cnt)
|
2019-10-17 22:46:12 +02:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
|
|
|
TRACE("%p->%s\n", This, debugstr_w(This->desc->props[id - This->desc->func_cnt].name));
|
|
|
|
return invoke_variant_prop(This->desc->ctx, This->props+(id-This->desc->func_cnt), flags, params, res);
|
|
|
|
}
|
|
|
|
|
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++;
|
2019-10-04 16:30:20 +02:00
|
|
|
exec_script(This->desc->ctx, FALSE, This->desc->funcs[This->desc->class_terminate_id].entries[VBDISP_CALLGET],
|
2014-03-07 14:27:35 +01:00
|
|
|
This, &dp, NULL);
|
2011-09-19 14:08:15 +02:00
|
|
|
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;
|
|
|
|
|
2014-03-07 14:27:12 +01:00
|
|
|
for(i=0; i < This->desc->array_cnt; i++) {
|
|
|
|
if(This->arrays[i]) {
|
|
|
|
SafeArrayDestroy(This->arrays[i]);
|
|
|
|
This->arrays[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2014-03-07 14:27:12 +01:00
|
|
|
heap_free(This->arrays);
|
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,
|
2014-04-29 14:47:58 +02:00
|
|
|
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
2011-09-05 11:14:14 +02:00
|
|
|
{
|
|
|
|
vbdisp_t *This = impl_from_IDispatchEx(iface);
|
2014-04-29 14:47:58 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
2011-09-05 11:14:14 +02:00
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2014-04-29 14:47:58 +02:00
|
|
|
|
|
|
|
return IDispatchEx_InvokeEx(&This->IDispatchEx_iface, dispIdMember, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, NULL);
|
2011-09-05 11:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-07-10 12:17:32 +02:00
|
|
|
grfdex &= ~FDEX_VERSION_MASK;
|
|
|
|
|
2011-09-16 13:29:47 +02:00
|
|
|
if(!This->desc)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2012-08-13 11:03:46 +02:00
|
|
|
/* Tests show that fdexNameCaseSensitive is ignored */
|
|
|
|
|
|
|
|
if(grfdex & ~(fdexNameEnsure|fdexNameCaseInsensitive|fdexNameCaseSensitive)) {
|
2011-09-15 14:21:13 +02:00
|
|
|
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;
|
|
|
|
|
2019-10-17 22:46:12 +02:00
|
|
|
return invoke_vbdisp(This, id, wFlags, TRUE, pdp, pvarRes);
|
2011-09-05 11:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2014-03-07 14:27:12 +01:00
|
|
|
HRESULT hres = S_OK;
|
2011-09-05 11:14:14 +02:00
|
|
|
|
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
|
|
|
|
2012-09-06 11:57:33 +02:00
|
|
|
list_add_tail(&desc->ctx->objects, &vbdisp->entry);
|
|
|
|
|
2014-03-07 14:27:12 +01:00
|
|
|
if(desc->array_cnt) {
|
|
|
|
vbdisp->arrays = heap_alloc_zero(desc->array_cnt * sizeof(*vbdisp->arrays));
|
|
|
|
if(vbdisp->arrays) {
|
|
|
|
unsigned i, j;
|
|
|
|
|
|
|
|
for(i=0; i < desc->array_cnt; i++) {
|
|
|
|
if(!desc->array_descs[i].dim_cnt)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
vbdisp->arrays[i] = SafeArrayCreate(VT_VARIANT, desc->array_descs[i].dim_cnt, desc->array_descs[i].bounds);
|
|
|
|
if(!vbdisp->arrays[i]) {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-09-16 13:29:25 +02:00
|
|
|
|
2014-03-07 14:27:12 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
for(i=0, j=0; i < desc->prop_cnt; i++) {
|
|
|
|
if(desc->props[i].is_array) {
|
|
|
|
V_VT(vbdisp->props+i) = VT_ARRAY|VT_BYREF|VT_VARIANT;
|
|
|
|
V_ARRAYREF(vbdisp->props+i) = vbdisp->arrays + j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
hres = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres) && desc->class_initialize_id) {
|
|
|
|
DISPPARAMS dp = {0};
|
2019-10-04 16:30:20 +02:00
|
|
|
hres = exec_script(desc->ctx, FALSE, desc->funcs[desc->class_initialize_id].entries[VBDISP_CALLGET],
|
2014-03-07 14:27:35 +01:00
|
|
|
vbdisp, &dp, NULL);
|
2014-03-07 14:27:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IDispatchEx_Release(&vbdisp->IDispatchEx_iface);
|
|
|
|
return hres;
|
2011-09-16 13:29:25 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 11:14:14 +02:00
|
|
|
*ret = vbdisp;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:45:44 +01:00
|
|
|
struct typeinfo_func {
|
|
|
|
function_t *func;
|
|
|
|
MEMBERID memid;
|
|
|
|
};
|
|
|
|
|
2019-11-22 12:35:13 +01:00
|
|
|
typedef struct {
|
|
|
|
ITypeInfo ITypeInfo_iface;
|
2019-12-06 13:46:24 +01:00
|
|
|
ITypeComp ITypeComp_iface;
|
2019-11-22 12:35:13 +01:00
|
|
|
LONG ref;
|
2019-12-06 13:45:44 +01:00
|
|
|
|
|
|
|
UINT num_vars;
|
|
|
|
UINT num_funcs;
|
|
|
|
struct typeinfo_func *funcs;
|
|
|
|
|
|
|
|
ScriptDisp *disp;
|
2019-11-22 12:35:13 +01:00
|
|
|
} ScriptTypeInfo;
|
|
|
|
|
2019-12-11 18:19:10 +01:00
|
|
|
static function_t *get_func_from_memid(const ScriptTypeInfo *typeinfo, MEMBERID memid)
|
|
|
|
{
|
|
|
|
UINT a = 0, b = typeinfo->num_funcs;
|
|
|
|
|
|
|
|
if (!(memid & DISPID_FUNCTION_MASK)) return NULL;
|
|
|
|
|
|
|
|
while (a < b)
|
|
|
|
{
|
|
|
|
UINT i = (a + b - 1) / 2;
|
|
|
|
|
|
|
|
if (memid == typeinfo->funcs[i].memid)
|
|
|
|
return typeinfo->funcs[i].func;
|
|
|
|
else if (memid < typeinfo->funcs[i].memid)
|
|
|
|
b = i;
|
|
|
|
else
|
|
|
|
a = i + 1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:35:13 +01:00
|
|
|
static inline ScriptTypeInfo *ScriptTypeInfo_from_ITypeInfo(ITypeInfo *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptTypeInfo, ITypeInfo_iface);
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:46:24 +01:00
|
|
|
static inline ScriptTypeInfo *ScriptTypeInfo_from_ITypeComp(ITypeComp *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptTypeInfo, ITypeComp_iface);
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:35:13 +01:00
|
|
|
static HRESULT WINAPI ScriptTypeInfo_QueryInterface(ITypeInfo *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ITypeInfo, riid))
|
|
|
|
*ppv = &This->ITypeInfo_iface;
|
2019-12-06 13:46:24 +01:00
|
|
|
else if (IsEqualGUID(&IID_ITypeComp, riid))
|
|
|
|
*ppv = &This->ITypeComp_iface;
|
2019-11-22 12:35:13 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeInfo_AddRef(ITypeInfo *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeInfo_Release(ITypeInfo *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2019-12-06 13:45:44 +01:00
|
|
|
UINT i;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
2019-12-06 13:45:44 +01:00
|
|
|
for (i = 0; i < This->num_funcs; i++)
|
|
|
|
release_vbscode(This->funcs[i].func->code_ctx);
|
|
|
|
|
|
|
|
IDispatchEx_Release(&This->disp->IDispatchEx_iface);
|
|
|
|
heap_free(This->funcs);
|
2019-11-22 12:35:13 +01:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetTypeAttr(ITypeInfo *iface, TYPEATTR **ppTypeAttr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-06 13:45:52 +01:00
|
|
|
TYPEATTR *attr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, ppTypeAttr);
|
|
|
|
|
|
|
|
if (!ppTypeAttr) return E_INVALIDARG;
|
|
|
|
|
|
|
|
attr = heap_alloc_zero(sizeof(*attr));
|
|
|
|
if (!attr) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
attr->guid = GUID_VBScriptTypeInfo;
|
|
|
|
attr->lcid = LOCALE_USER_DEFAULT;
|
|
|
|
attr->memidConstructor = MEMBERID_NIL;
|
|
|
|
attr->memidDestructor = MEMBERID_NIL;
|
|
|
|
attr->cbSizeInstance = 4;
|
|
|
|
attr->typekind = TKIND_DISPATCH;
|
|
|
|
attr->cFuncs = This->num_funcs;
|
|
|
|
attr->cVars = This->num_vars;
|
|
|
|
attr->cImplTypes = 1;
|
|
|
|
attr->cbSizeVft = sizeof(IDispatchVtbl);
|
|
|
|
attr->cbAlignment = 4;
|
|
|
|
attr->wTypeFlags = TYPEFLAG_FDISPATCHABLE;
|
|
|
|
attr->wMajorVerNum = VBSCRIPT_MAJOR_VERSION;
|
|
|
|
attr->wMinorVerNum = VBSCRIPT_MINOR_VERSION;
|
|
|
|
|
|
|
|
*ppTypeAttr = attr;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetTypeComp(ITypeInfo *iface, ITypeComp **ppTComp)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-06 13:46:24 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, ppTComp);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:24 +01:00
|
|
|
if (!ppTComp) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppTComp = &This->ITypeComp_iface;
|
|
|
|
ITypeInfo_AddRef(iface);
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetFuncDesc(ITypeInfo *iface, UINT index, FUNCDESC **ppFuncDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-06 13:46:00 +01:00
|
|
|
function_t *func;
|
|
|
|
FUNCDESC *desc;
|
|
|
|
UINT i;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:00 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, ppFuncDesc);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:00 +01:00
|
|
|
if (!ppFuncDesc) return E_INVALIDARG;
|
|
|
|
if (index >= This->num_funcs) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
func = This->funcs[index].func;
|
|
|
|
|
|
|
|
/* Store the parameter array after the FUNCDESC structure */
|
|
|
|
desc = heap_alloc_zero(sizeof(*desc) + sizeof(ELEMDESC) * func->arg_cnt);
|
|
|
|
if (!desc) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
desc->memid = This->funcs[index].memid;
|
|
|
|
desc->funckind = FUNC_DISPATCH;
|
|
|
|
desc->invkind = INVOKE_FUNC;
|
|
|
|
desc->callconv = CC_STDCALL;
|
|
|
|
desc->cParams = func->arg_cnt;
|
|
|
|
desc->elemdescFunc.tdesc.vt = (func->type == FUNC_SUB) ? VT_VOID : VT_VARIANT;
|
|
|
|
|
|
|
|
if (func->arg_cnt) desc->lprgelemdescParam = (ELEMDESC*)(desc + 1);
|
|
|
|
for (i = 0; i < func->arg_cnt; i++)
|
|
|
|
desc->lprgelemdescParam[i].tdesc.vt = VT_VARIANT;
|
|
|
|
|
|
|
|
*ppFuncDesc = desc;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetVarDesc(ITypeInfo *iface, UINT index, VARDESC **ppVarDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-06 13:46:06 +01:00
|
|
|
VARDESC *desc;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:06 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, ppVarDesc);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:06 +01:00
|
|
|
if (!ppVarDesc) return E_INVALIDARG;
|
|
|
|
if (index >= This->num_vars) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
desc = heap_alloc_zero(sizeof(*desc));
|
|
|
|
if (!desc) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
desc->memid = index + 1;
|
|
|
|
desc->varkind = VAR_DISPATCH;
|
|
|
|
desc->elemdescVar.tdesc.vt = VT_VARIANT;
|
|
|
|
|
|
|
|
*ppVarDesc = desc;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetNames(ITypeInfo *iface, MEMBERID memid, BSTR *rgBstrNames,
|
|
|
|
UINT cMaxNames, UINT *pcNames)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:19:10 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
function_t *func;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i = 0;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:10 +01:00
|
|
|
TRACE("(%p)->(%d %p %u %p)\n", This, memid, rgBstrNames, cMaxNames, pcNames);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:10 +01:00
|
|
|
if (!rgBstrNames || !pcNames) return E_INVALIDARG;
|
|
|
|
if (memid <= 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
func = get_func_from_memid(This, memid);
|
|
|
|
if (!func && memid > This->num_vars)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetNames(disp_typeinfo, memid, rgBstrNames, cMaxNames, pcNames);
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcNames = 0;
|
|
|
|
if (!cMaxNames) return S_OK;
|
|
|
|
|
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
UINT num = min(cMaxNames, func->arg_cnt + 1);
|
|
|
|
|
|
|
|
rgBstrNames[0] = SysAllocString(func->name);
|
|
|
|
if (!rgBstrNames[0]) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for (i = 1; i < num; i++)
|
|
|
|
{
|
|
|
|
if (!(rgBstrNames[i] = SysAllocString(func->args[i - 1].name)))
|
|
|
|
{
|
|
|
|
do SysFreeString(rgBstrNames[--i]); while (i);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rgBstrNames[0] = SysAllocString(This->disp->global_vars[memid - 1]->name);
|
|
|
|
if (!rgBstrNames[0]) return E_OUTOFMEMORY;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcNames = i;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetRefTypeOfImplType(ITypeInfo *iface, UINT index, HREFTYPE *pRefType)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-11 18:19:16 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, pRefType);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:16 +01:00
|
|
|
/* We only inherit from IDispatch */
|
|
|
|
if (!pRefType) return E_INVALIDARG;
|
|
|
|
if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
*pRefType = 1;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetImplTypeFlags(ITypeInfo *iface, UINT index, INT *pImplTypeFlags)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-11 18:19:27 +01:00
|
|
|
TRACE("(%p)->(%u %p)\n", This, index, pImplTypeFlags);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:27 +01:00
|
|
|
if (!pImplTypeFlags) return E_INVALIDARG;
|
|
|
|
if (index != 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
*pImplTypeFlags = 0;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetIDsOfNames(ITypeInfo *iface, LPOLESTR *rgszNames, UINT cNames,
|
|
|
|
MEMBERID *pMemId)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-06 13:46:13 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
const WCHAR *name;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
int i, j, arg;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:13 +01:00
|
|
|
TRACE("(%p)->(%p %u %p)\n", This, rgszNames, cNames, pMemId);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-06 13:46:13 +01:00
|
|
|
if (!rgszNames || !cNames || !pMemId) return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (i = 0; i < cNames; i++) pMemId[i] = MEMBERID_NIL;
|
|
|
|
name = rgszNames[0];
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_funcs; i++)
|
|
|
|
{
|
|
|
|
function_t *func = This->funcs[i].func;
|
|
|
|
|
|
|
|
if (wcsicmp(name, func->name)) continue;
|
|
|
|
pMemId[0] = This->funcs[i].memid;
|
|
|
|
|
|
|
|
for (j = 1; j < cNames; j++)
|
|
|
|
{
|
|
|
|
name = rgszNames[j];
|
|
|
|
for (arg = func->arg_cnt; --arg >= 0;)
|
|
|
|
if (!wcsicmp(name, func->args[arg].name))
|
|
|
|
break;
|
|
|
|
if (arg >= 0)
|
|
|
|
pMemId[j] = arg;
|
|
|
|
else
|
|
|
|
hr = DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_vars; i++)
|
|
|
|
{
|
|
|
|
if (wcsicmp(name, This->disp->global_vars[i]->name)) continue;
|
|
|
|
pMemId[0] = i + 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look into the inherited IDispatch */
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetIDsOfNames(disp_typeinfo, rgszNames, cNames, pMemId);
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_Invoke(ITypeInfo *iface, PVOID pvInstance, MEMBERID memid, WORD wFlags,
|
|
|
|
DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:19:33 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
IDispatch *disp;
|
|
|
|
HRESULT hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:33 +01:00
|
|
|
TRACE("(%p)->(%p %d %d %p %p %p %p)\n", This, pvInstance, memid, wFlags,
|
2019-11-22 12:35:13 +01:00
|
|
|
pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
|
2019-12-11 18:19:33 +01:00
|
|
|
if (!pvInstance) return E_INVALIDARG;
|
|
|
|
if (memid <= 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && memid > This->num_vars)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_Invoke(disp_typeinfo, pvInstance, memid, wFlags, pDispParams,
|
|
|
|
pVarResult, pExcepInfo, puArgErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface((IUnknown*)pvInstance, &IID_IDispatch, (void**)&disp);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IDispatch_Invoke(disp, memid, &IID_NULL, LOCALE_USER_DEFAULT, wFlags,
|
|
|
|
pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
IDispatch_Release(disp);
|
|
|
|
|
|
|
|
return hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetDocumentation(ITypeInfo *iface, MEMBERID memid, BSTR *pBstrName,
|
|
|
|
BSTR *pBstrDocString, DWORD *pdwHelpContext, BSTR *pBstrHelpFile)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:19:40 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
function_t *func;
|
|
|
|
HRESULT hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:40 +01:00
|
|
|
TRACE("(%p)->(%d %p %p %p %p)\n", This, memid, pBstrName, pBstrDocString, pdwHelpContext, pBstrHelpFile);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:40 +01:00
|
|
|
if (pBstrDocString) *pBstrDocString = NULL;
|
|
|
|
if (pdwHelpContext) *pdwHelpContext = 0;
|
|
|
|
if (pBstrHelpFile) *pBstrHelpFile = NULL;
|
|
|
|
|
|
|
|
if (memid == MEMBERID_NIL)
|
|
|
|
{
|
|
|
|
if (pBstrName && !(*pBstrName = SysAllocString(L"VBScriptTypeInfo")))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
if (pBstrDocString &&
|
|
|
|
!(*pBstrDocString = SysAllocString(L"Visual Basic Scripting Type Info")))
|
|
|
|
{
|
|
|
|
if (pBstrName) SysFreeString(*pBstrName);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (memid <= 0) return TYPE_E_ELEMENTNOTFOUND;
|
|
|
|
|
|
|
|
func = get_func_from_memid(This, memid);
|
|
|
|
if (!func && memid > This->num_vars)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetDocumentation(disp_typeinfo, memid, pBstrName, pBstrDocString,
|
|
|
|
pdwHelpContext, pBstrHelpFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBstrName)
|
|
|
|
{
|
|
|
|
*pBstrName = SysAllocString(func ? func->name : This->disp->global_vars[memid - 1]->name);
|
|
|
|
if (!*pBstrName) return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetDllEntry(ITypeInfo *iface, MEMBERID memid, INVOKEKIND invKind,
|
|
|
|
BSTR *pBstrDllName, BSTR *pBstrName, WORD *pwOrdinal)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:19:49 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
HRESULT hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:49 +01:00
|
|
|
TRACE("(%p)->(%d %d %p %p %p)\n", This, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:49 +01:00
|
|
|
if (pBstrDllName) *pBstrDllName = NULL;
|
|
|
|
if (pBstrName) *pBstrName = NULL;
|
|
|
|
if (pwOrdinal) *pwOrdinal = 0;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && memid > This->num_vars)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetDllEntry(disp_typeinfo, memid, invKind, pBstrDllName, pBstrName, pwOrdinal);
|
|
|
|
}
|
|
|
|
return TYPE_E_BADMODULEKIND;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetRefTypeInfo(ITypeInfo *iface, HREFTYPE hRefType, ITypeInfo **ppTInfo)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:19:21 +01:00
|
|
|
HRESULT hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:21 +01:00
|
|
|
TRACE("(%p)->(%x %p)\n", This, hRefType, ppTInfo);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:21 +01:00
|
|
|
if (!ppTInfo || (INT)hRefType < 0) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (hRefType & ~3) return E_FAIL;
|
|
|
|
if (hRefType & 1)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(ppTInfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ppTInfo = iface;
|
|
|
|
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_AddressOfMember(ITypeInfo *iface, MEMBERID memid, INVOKEKIND invKind, PVOID *ppv)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:19:56 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
HRESULT hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:56 +01:00
|
|
|
TRACE("(%p)->(%d %d %p)\n", This, memid, invKind, ppv);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:19:56 +01:00
|
|
|
if (!ppv) return E_INVALIDARG;
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && memid > This->num_vars)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_AddressOfMember(disp_typeinfo, memid, invKind, ppv);
|
|
|
|
}
|
|
|
|
return TYPE_E_BADMODULEKIND;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_CreateInstance(ITypeInfo *iface, IUnknown *pUnkOuter, REFIID riid, PVOID *ppvObj)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-11 18:20:01 +01:00
|
|
|
TRACE("(%p)->(%p %s %p)\n", This, pUnkOuter, debugstr_guid(riid), ppvObj);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:20:01 +01:00
|
|
|
if (!ppvObj) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
return TYPE_E_BADMODULEKIND;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetMops(ITypeInfo *iface, MEMBERID memid, BSTR *pBstrMops)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
2019-12-11 18:20:07 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
HRESULT hr;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:20:07 +01:00
|
|
|
TRACE("(%p)->(%d %p)\n", This, memid, pBstrMops);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
2019-12-11 18:20:07 +01:00
|
|
|
if (!pBstrMops) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!get_func_from_memid(This, memid) && memid > This->num_vars)
|
|
|
|
{
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
return ITypeInfo_GetMops(disp_typeinfo, memid, pBstrMops);
|
|
|
|
}
|
|
|
|
|
|
|
|
*pBstrMops = NULL;
|
|
|
|
return S_OK;
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeInfo_GetContainingTypeLib(ITypeInfo *iface, ITypeLib **ppTLib, UINT *pIndex)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%p %p)\n", This, ppTLib, pIndex);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ScriptTypeInfo_ReleaseTypeAttr(ITypeInfo *iface, TYPEATTR *pTypeAttr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-06 13:45:52 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pTypeAttr);
|
|
|
|
|
|
|
|
heap_free(pTypeAttr);
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ScriptTypeInfo_ReleaseFuncDesc(ITypeInfo *iface, FUNCDESC *pFuncDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-06 13:46:00 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pFuncDesc);
|
|
|
|
|
|
|
|
heap_free(pFuncDesc);
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ScriptTypeInfo_ReleaseVarDesc(ITypeInfo *iface, VARDESC *pVarDesc)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeInfo(iface);
|
|
|
|
|
2019-12-06 13:46:06 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, pVarDesc);
|
|
|
|
|
|
|
|
heap_free(pVarDesc);
|
2019-11-22 12:35:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ITypeInfoVtbl ScriptTypeInfoVtbl = {
|
|
|
|
ScriptTypeInfo_QueryInterface,
|
|
|
|
ScriptTypeInfo_AddRef,
|
|
|
|
ScriptTypeInfo_Release,
|
|
|
|
ScriptTypeInfo_GetTypeAttr,
|
|
|
|
ScriptTypeInfo_GetTypeComp,
|
|
|
|
ScriptTypeInfo_GetFuncDesc,
|
|
|
|
ScriptTypeInfo_GetVarDesc,
|
|
|
|
ScriptTypeInfo_GetNames,
|
|
|
|
ScriptTypeInfo_GetRefTypeOfImplType,
|
|
|
|
ScriptTypeInfo_GetImplTypeFlags,
|
|
|
|
ScriptTypeInfo_GetIDsOfNames,
|
|
|
|
ScriptTypeInfo_Invoke,
|
|
|
|
ScriptTypeInfo_GetDocumentation,
|
|
|
|
ScriptTypeInfo_GetDllEntry,
|
|
|
|
ScriptTypeInfo_GetRefTypeInfo,
|
|
|
|
ScriptTypeInfo_AddressOfMember,
|
|
|
|
ScriptTypeInfo_CreateInstance,
|
|
|
|
ScriptTypeInfo_GetMops,
|
|
|
|
ScriptTypeInfo_GetContainingTypeLib,
|
|
|
|
ScriptTypeInfo_ReleaseTypeAttr,
|
|
|
|
ScriptTypeInfo_ReleaseFuncDesc,
|
|
|
|
ScriptTypeInfo_ReleaseVarDesc
|
|
|
|
};
|
|
|
|
|
2019-12-06 13:46:24 +01:00
|
|
|
static HRESULT WINAPI ScriptTypeComp_QueryInterface(ITypeComp *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
|
|
|
return ITypeInfo_QueryInterface(&This->ITypeInfo_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeComp_AddRef(ITypeComp *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
|
|
|
return ITypeInfo_AddRef(&This->ITypeInfo_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptTypeComp_Release(ITypeComp *iface)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
|
|
|
return ITypeInfo_Release(&This->ITypeInfo_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeComp_Bind(ITypeComp *iface, LPOLESTR szName, ULONG lHashVal, WORD wFlags,
|
|
|
|
ITypeInfo **ppTInfo, DESCKIND *pDescKind, BINDPTR *pBindPtr)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
2019-12-09 16:29:24 +01:00
|
|
|
UINT flags = wFlags ? wFlags : ~0;
|
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
ITypeComp *disp_typecomp;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %08x %d %p %p %p)\n", This, debugstr_w(szName), lHashVal,
|
2019-12-06 13:46:24 +01:00
|
|
|
wFlags, ppTInfo, pDescKind, pBindPtr);
|
2019-12-09 16:29:24 +01:00
|
|
|
|
|
|
|
if (!szName || !ppTInfo || !pDescKind || !pBindPtr)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_funcs; i++)
|
|
|
|
{
|
|
|
|
if (wcsicmp(szName, This->funcs[i].func->name)) continue;
|
|
|
|
if (!(flags & INVOKE_FUNC)) return TYPE_E_TYPEMISMATCH;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetFuncDesc(&This->ITypeInfo_iface, i, &pBindPtr->lpfuncdesc);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
*pDescKind = DESCKIND_FUNCDESC;
|
|
|
|
*ppTInfo = &This->ITypeInfo_iface;
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < This->num_vars; i++)
|
|
|
|
{
|
|
|
|
if (wcsicmp(szName, This->disp->global_vars[i]->name)) continue;
|
|
|
|
if (!(flags & INVOKE_PROPERTYGET)) return TYPE_E_TYPEMISMATCH;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetVarDesc(&This->ITypeInfo_iface, i, &pBindPtr->lpvardesc);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
*pDescKind = DESCKIND_VARDESC;
|
|
|
|
*ppTInfo = &This->ITypeInfo_iface;
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look into the inherited IDispatch */
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetTypeComp(disp_typeinfo, &disp_typecomp);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeComp_Bind(disp_typecomp, szName, lHashVal, wFlags, ppTInfo, pDescKind, pBindPtr);
|
|
|
|
ITypeComp_Release(disp_typecomp);
|
|
|
|
return hr;
|
2019-12-06 13:46:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptTypeComp_BindType(ITypeComp *iface, LPOLESTR szName, ULONG lHashVal,
|
|
|
|
ITypeInfo **ppTInfo, ITypeComp **ppTComp)
|
|
|
|
{
|
|
|
|
ScriptTypeInfo *This = ScriptTypeInfo_from_ITypeComp(iface);
|
2019-12-09 16:29:25 +01:00
|
|
|
ITypeInfo *disp_typeinfo;
|
|
|
|
ITypeComp *disp_typecomp;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %08x %p %p)\n", This, debugstr_w(szName), lHashVal, ppTInfo, ppTComp);
|
|
|
|
|
|
|
|
if (!szName || !ppTInfo || !ppTComp)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* Look into the inherited IDispatch */
|
|
|
|
hr = get_dispatch_typeinfo(&disp_typeinfo);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeInfo_GetTypeComp(disp_typeinfo, &disp_typecomp);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = ITypeComp_BindType(disp_typecomp, szName, lHashVal, ppTInfo, ppTComp);
|
|
|
|
ITypeComp_Release(disp_typecomp);
|
|
|
|
return hr;
|
2019-12-06 13:46:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ITypeCompVtbl ScriptTypeCompVtbl = {
|
|
|
|
ScriptTypeComp_QueryInterface,
|
|
|
|
ScriptTypeComp_AddRef,
|
|
|
|
ScriptTypeComp_Release,
|
|
|
|
ScriptTypeComp_Bind,
|
|
|
|
ScriptTypeComp_BindType
|
|
|
|
};
|
|
|
|
|
2012-09-07 15:09:34 +02:00
|
|
|
static inline ScriptDisp *ScriptDisp_from_IDispatchEx(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ScriptDisp, IDispatchEx_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_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 ScriptDisp_AddRef(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ScriptDisp_Release(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2019-12-06 13:45:21 +01:00
|
|
|
unsigned i;
|
2012-09-07 15:09:34 +02:00
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref) {
|
|
|
|
assert(!This->ctx);
|
2019-12-06 13:45:21 +01:00
|
|
|
|
|
|
|
for (i = 0; i < This->global_vars_cnt; i++)
|
|
|
|
release_dynamic_var(This->global_vars[i]);
|
|
|
|
|
|
|
|
heap_pool_free(&This->heap);
|
|
|
|
heap_free(This->global_vars);
|
|
|
|
heap_free(This->global_funcs);
|
2012-09-07 15:09:34 +02:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:35:13 +01:00
|
|
|
static HRESULT WINAPI ScriptDisp_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid, ITypeInfo **ret)
|
2012-09-07 15:09:34 +02:00
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
2019-11-22 12:35:13 +01:00
|
|
|
ScriptTypeInfo *type_info;
|
2019-12-06 13:45:44 +01:00
|
|
|
UINT num_funcs = 0;
|
|
|
|
unsigned i, j;
|
2019-11-22 12:35:13 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ret);
|
|
|
|
|
|
|
|
if(iTInfo)
|
|
|
|
return DISP_E_BADINDEX;
|
|
|
|
|
|
|
|
if(!(type_info = heap_alloc(sizeof(*type_info))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-12-06 13:45:44 +01:00
|
|
|
for(i = 0; i < This->global_funcs_cnt; i++)
|
|
|
|
if(This->global_funcs[i]->is_public)
|
|
|
|
num_funcs++;
|
|
|
|
|
2019-11-22 12:35:13 +01:00
|
|
|
type_info->ITypeInfo_iface.lpVtbl = &ScriptTypeInfoVtbl;
|
2019-12-06 13:46:24 +01:00
|
|
|
type_info->ITypeComp_iface.lpVtbl = &ScriptTypeCompVtbl;
|
2019-11-22 12:35:13 +01:00
|
|
|
type_info->ref = 1;
|
2019-12-06 13:45:44 +01:00
|
|
|
type_info->num_funcs = num_funcs;
|
|
|
|
type_info->num_vars = This->global_vars_cnt;
|
|
|
|
type_info->disp = This;
|
|
|
|
|
|
|
|
type_info->funcs = heap_alloc(sizeof(*type_info->funcs) * num_funcs);
|
|
|
|
if(!type_info->funcs)
|
|
|
|
{
|
|
|
|
heap_free(type_info);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j = 0, i = 0; i < This->global_funcs_cnt; i++)
|
|
|
|
{
|
|
|
|
if(!This->global_funcs[i]->is_public) continue;
|
|
|
|
|
|
|
|
type_info->funcs[j].memid = i + 1 + DISPID_FUNCTION_MASK;
|
|
|
|
type_info->funcs[j].func = This->global_funcs[i];
|
|
|
|
grab_vbscode(This->global_funcs[i]->code_ctx);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDispatchEx_AddRef(&This->IDispatchEx_iface);
|
2019-11-22 12:35:13 +01:00
|
|
|
|
|
|
|
*ret = &type_info->ITypeInfo_iface;
|
|
|
|
return S_OK;
|
2012-09-07 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
|
2012-09-18 12:26:03 +02:00
|
|
|
LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
|
2012-09-07 15:09:34 +02:00
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
2012-09-18 12:26:03 +02:00
|
|
|
UINT i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
|
2012-09-07 15:09:34 +02:00
|
|
|
lcid, rgDispId);
|
2012-09-18 12:26:03 +02:00
|
|
|
|
2021-08-04 17:51:47 +02:00
|
|
|
if(cNames == 0)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[0], 0, rgDispId);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
/* DISPIDs for parameters don't seem to be supported */
|
|
|
|
if(cNames > 1) {
|
|
|
|
for(i = 1; i < cNames; i++)
|
|
|
|
rgDispId[i] = DISPID_UNKNOWN;
|
|
|
|
hres = DISP_E_UNKNOWNNAME;
|
2012-09-18 12:26:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 17:51:47 +02:00
|
|
|
return hres;
|
2012-09-07 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 12:26:16 +02:00
|
|
|
static HRESULT WINAPI ScriptDisp_Invoke(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
|
|
|
|
WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
2012-09-07 15:09:34 +02:00
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
2012-09-18 12:26:16 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
2012-09-07 15:09:34 +02:00
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2012-09-18 12:26:16 +02:00
|
|
|
|
|
|
|
return IDispatchEx_InvokeEx(&This->IDispatchEx_iface, dispIdMember, lcid, wFlags,
|
|
|
|
pDispParams, pVarResult, pExcepInfo, NULL);
|
2012-09-07 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
2019-11-04 17:37:24 +01:00
|
|
|
unsigned i;
|
2012-09-07 15:09:59 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
|
|
|
|
|
|
|
|
if(!This->ctx)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2019-12-06 13:45:21 +01:00
|
|
|
for(i = 0; i < This->global_vars_cnt; i++) {
|
|
|
|
if(!wcsicmp(This->global_vars[i]->name, bstrName)) {
|
2019-11-06 17:35:16 +01:00
|
|
|
*pid = i + 1;
|
2012-09-07 15:09:59 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 13:45:21 +01:00
|
|
|
for(i = 0; i < This->global_funcs_cnt; i++) {
|
|
|
|
if(!wcsicmp(This->global_funcs[i]->name, bstrName)) {
|
2019-11-06 17:35:16 +01:00
|
|
|
*pid = i + 1 + DISPID_FUNCTION_MASK;
|
2012-09-07 15:09:59 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pid = -1;
|
2012-09-07 15:09:34 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
|
|
|
|
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
2012-09-07 15:10:17 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2012-09-07 15:09:34 +02:00
|
|
|
TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
2012-09-07 15:10:17 +02:00
|
|
|
|
2020-02-13 19:49:52 +01:00
|
|
|
if (!This->ctx)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
2019-11-06 17:35:16 +01:00
|
|
|
if (id & DISPID_FUNCTION_MASK)
|
|
|
|
{
|
|
|
|
id &= ~DISPID_FUNCTION_MASK;
|
2019-12-06 13:45:21 +01:00
|
|
|
if (id > This->global_funcs_cnt)
|
2019-11-06 17:35:16 +01:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
2012-09-07 15:10:17 +02:00
|
|
|
|
2019-11-06 17:35:16 +01:00
|
|
|
switch (wFlags)
|
|
|
|
{
|
|
|
|
case DISPATCH_METHOD:
|
|
|
|
case DISPATCH_METHOD | DISPATCH_PROPERTYGET:
|
2019-12-06 13:45:21 +01:00
|
|
|
hres = exec_script(This->ctx, TRUE, This->global_funcs[id - 1], NULL, pdp, pvarRes);
|
2019-11-06 17:35:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported flags %x\n", wFlags);
|
|
|
|
hres = E_NOTIMPL;
|
2012-09-07 15:10:17 +02:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:35:16 +01:00
|
|
|
return hres;
|
2012-09-07 15:10:17 +02:00
|
|
|
}
|
|
|
|
|
2019-12-06 13:45:21 +01:00
|
|
|
if (id > This->global_vars_cnt)
|
2019-11-06 17:35:16 +01:00
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
|
2019-12-06 13:45:21 +01:00
|
|
|
if (This->global_vars[id - 1]->is_const)
|
2019-11-06 17:35:16 +01:00
|
|
|
{
|
|
|
|
FIXME("const not supported\n");
|
|
|
|
return E_NOTIMPL;
|
2012-09-18 12:26:30 +02:00
|
|
|
}
|
2012-09-07 15:10:17 +02:00
|
|
|
|
2019-12-06 13:45:21 +01:00
|
|
|
return invoke_variant_prop(This->ctx, &This->global_vars[id - 1]->v, wFlags, pdp, pvarRes);
|
2012-09-07 15:09:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x)\n", This, id);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x %p)\n", This, id, pbstrName);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ScriptDisp_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
|
|
|
|
{
|
|
|
|
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
|
|
|
FIXME("(%p)->(%p)\n", This, ppunk);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IDispatchExVtbl ScriptDispVtbl = {
|
|
|
|
ScriptDisp_QueryInterface,
|
|
|
|
ScriptDisp_AddRef,
|
|
|
|
ScriptDisp_Release,
|
|
|
|
ScriptDisp_GetTypeInfoCount,
|
|
|
|
ScriptDisp_GetTypeInfo,
|
|
|
|
ScriptDisp_GetIDsOfNames,
|
|
|
|
ScriptDisp_Invoke,
|
|
|
|
ScriptDisp_GetDispID,
|
|
|
|
ScriptDisp_InvokeEx,
|
|
|
|
ScriptDisp_DeleteMemberByName,
|
|
|
|
ScriptDisp_DeleteMemberByDispID,
|
|
|
|
ScriptDisp_GetMemberProperties,
|
|
|
|
ScriptDisp_GetMemberName,
|
|
|
|
ScriptDisp_GetNextDispID,
|
|
|
|
ScriptDisp_GetNameSpaceParent
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT create_script_disp(script_ctx_t *ctx, ScriptDisp **ret)
|
|
|
|
{
|
|
|
|
ScriptDisp *script_disp;
|
|
|
|
|
2012-09-07 15:09:59 +02:00
|
|
|
script_disp = heap_alloc_zero(sizeof(*script_disp));
|
2012-09-07 15:09:34 +02:00
|
|
|
if(!script_disp)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
script_disp->IDispatchEx_iface.lpVtbl = &ScriptDispVtbl;
|
|
|
|
script_disp->ref = 1;
|
|
|
|
script_disp->ctx = ctx;
|
2019-12-06 13:45:21 +01:00
|
|
|
heap_pool_init(&script_disp->heap);
|
2012-09-07 15:09:34 +02:00
|
|
|
|
|
|
|
*ret = script_disp;
|
|
|
|
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);
|
|
|
|
|
2011-10-14 13:51:15 +02:00
|
|
|
while(!list_empty(&ctx->objects)) {
|
|
|
|
iter = LIST_ENTRY(list_head(&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-10-14 13:51:15 +02:00
|
|
|
list_remove(&iter->entry);
|
|
|
|
list_init(&iter->entry);
|
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)) {
|
2012-04-17 22:09:01 +02:00
|
|
|
TRACE("using IDispatch\n");
|
2011-09-08 14:54:37 +02:00
|
|
|
return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseInsensitive, id);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2014-03-27 14:44:12 +01:00
|
|
|
#define RPC_E_SERVER_UNAVAILABLE 0x800706ba
|
|
|
|
|
|
|
|
HRESULT map_hres(HRESULT hres)
|
|
|
|
{
|
|
|
|
if(SUCCEEDED(hres) || HRESULT_FACILITY(hres) == FACILITY_VBS)
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
switch(hres) {
|
|
|
|
case E_NOTIMPL: return MAKE_VBSERROR(VBSE_ACTION_NOT_SUPPORTED);
|
|
|
|
case E_NOINTERFACE: return MAKE_VBSERROR(VBSE_OLE_NOT_SUPPORTED);
|
|
|
|
case DISP_E_UNKNOWNINTERFACE: return MAKE_VBSERROR(VBSE_OLE_NO_PROP_OR_METHOD);
|
|
|
|
case DISP_E_MEMBERNOTFOUND: return MAKE_VBSERROR(VBSE_OLE_NO_PROP_OR_METHOD);
|
|
|
|
case DISP_E_PARAMNOTFOUND: return MAKE_VBSERROR(VBSE_NAMED_PARAM_NOT_FOUND);
|
|
|
|
case DISP_E_TYPEMISMATCH: return MAKE_VBSERROR(VBSE_TYPE_MISMATCH);
|
|
|
|
case DISP_E_UNKNOWNNAME: return MAKE_VBSERROR(VBSE_OLE_NO_PROP_OR_METHOD);
|
|
|
|
case DISP_E_NONAMEDARGS: return MAKE_VBSERROR(VBSE_NAMED_ARGS_NOT_SUPPORTED);
|
|
|
|
case DISP_E_BADVARTYPE: return MAKE_VBSERROR(VBSE_INVALID_TYPELIB_VARIABLE);
|
|
|
|
case DISP_E_OVERFLOW: return MAKE_VBSERROR(VBSE_OVERFLOW);
|
|
|
|
case DISP_E_BADINDEX: return MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS);
|
|
|
|
case DISP_E_UNKNOWNLCID: return MAKE_VBSERROR(VBSE_LOCALE_SETTING_NOT_SUPPORTED);
|
|
|
|
case DISP_E_ARRAYISLOCKED: return MAKE_VBSERROR(VBSE_ARRAY_LOCKED);
|
|
|
|
case DISP_E_BADPARAMCOUNT: return MAKE_VBSERROR(VBSE_FUNC_ARITY_MISMATCH);
|
|
|
|
case DISP_E_PARAMNOTOPTIONAL: return MAKE_VBSERROR(VBSE_PARAMETER_NOT_OPTIONAL);
|
|
|
|
case DISP_E_NOTACOLLECTION: return MAKE_VBSERROR(VBSE_NOT_ENUM);
|
|
|
|
case TYPE_E_DLLFUNCTIONNOTFOUND: return MAKE_VBSERROR(VBSE_INVALID_DLL_FUNCTION_NAME);
|
|
|
|
case TYPE_E_TYPEMISMATCH: return MAKE_VBSERROR(VBSE_TYPE_MISMATCH);
|
|
|
|
case TYPE_E_OUTOFBOUNDS: return MAKE_VBSERROR(VBSE_OUT_OF_BOUNDS);
|
|
|
|
case TYPE_E_IOERROR: return MAKE_VBSERROR(VBSE_IO_ERROR);
|
|
|
|
case TYPE_E_CANTCREATETMPFILE: return MAKE_VBSERROR(VBSE_CANT_CREATE_TMP_FILE);
|
|
|
|
case STG_E_FILENOTFOUND: return MAKE_VBSERROR(VBSE_OLE_FILE_NOT_FOUND);
|
|
|
|
case STG_E_PATHNOTFOUND: return MAKE_VBSERROR(VBSE_PATH_NOT_FOUND);
|
|
|
|
case STG_E_TOOMANYOPENFILES: return MAKE_VBSERROR(VBSE_TOO_MANY_FILES);
|
|
|
|
case STG_E_ACCESSDENIED: return MAKE_VBSERROR(VBSE_PERMISSION_DENIED);
|
|
|
|
case STG_E_INSUFFICIENTMEMORY: return MAKE_VBSERROR(VBSE_OUT_OF_MEMORY);
|
|
|
|
case STG_E_NOMOREFILES: return MAKE_VBSERROR(VBSE_TOO_MANY_FILES);
|
|
|
|
case STG_E_DISKISWRITEPROTECTED: return MAKE_VBSERROR(VBSE_PERMISSION_DENIED);
|
|
|
|
case STG_E_WRITEFAULT: return MAKE_VBSERROR(VBSE_IO_ERROR);
|
|
|
|
case STG_E_READFAULT: return MAKE_VBSERROR(VBSE_IO_ERROR);
|
|
|
|
case STG_E_SHAREVIOLATION: return MAKE_VBSERROR(VBSE_PATH_FILE_ACCESS);
|
|
|
|
case STG_E_LOCKVIOLATION: return MAKE_VBSERROR(VBSE_PERMISSION_DENIED);
|
|
|
|
case STG_E_FILEALREADYEXISTS: return MAKE_VBSERROR(VBSE_FILE_ALREADY_EXISTS);
|
|
|
|
case STG_E_MEDIUMFULL: return MAKE_VBSERROR(VBSE_DISK_FULL);
|
|
|
|
case STG_E_INVALIDNAME: return MAKE_VBSERROR(VBSE_FILE_NOT_FOUND);
|
|
|
|
case STG_E_INUSE: return MAKE_VBSERROR(VBSE_PERMISSION_DENIED);
|
|
|
|
case STG_E_NOTCURRENT: return MAKE_VBSERROR(VBSE_PERMISSION_DENIED);
|
|
|
|
case STG_E_CANTSAVE: return MAKE_VBSERROR(VBSE_IO_ERROR);
|
|
|
|
case REGDB_E_CLASSNOTREG: return MAKE_VBSERROR(VBSE_CANT_CREATE_OBJECT);
|
|
|
|
case MK_E_UNAVAILABLE: return MAKE_VBSERROR(VBSE_CANT_CREATE_OBJECT);
|
|
|
|
case MK_E_INVALIDEXTENSION: return MAKE_VBSERROR(VBSE_OLE_FILE_NOT_FOUND);
|
|
|
|
case MK_E_CANTOPENFILE: return MAKE_VBSERROR(VBSE_OLE_FILE_NOT_FOUND);
|
|
|
|
case CO_E_CLASSSTRING: return MAKE_VBSERROR(VBSE_CANT_CREATE_OBJECT);
|
|
|
|
case CO_E_APPNOTFOUND: return MAKE_VBSERROR(VBSE_CANT_CREATE_OBJECT);
|
|
|
|
case CO_E_APPDIDNTREG: return MAKE_VBSERROR(VBSE_CANT_CREATE_OBJECT);
|
|
|
|
case E_ACCESSDENIED: return MAKE_VBSERROR(VBSE_PERMISSION_DENIED);
|
|
|
|
case E_OUTOFMEMORY: return MAKE_VBSERROR(VBSE_OUT_OF_MEMORY);
|
|
|
|
case E_INVALIDARG: return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
|
|
|
|
case RPC_E_SERVER_UNAVAILABLE: return MAKE_VBSERROR(VBSE_SERVER_NOT_FOUND);
|
|
|
|
case CO_E_SERVER_EXEC_FAILURE: return MAKE_VBSERROR(VBSE_CANT_CREATE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:54:37 +02:00
|
|
|
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;
|
2019-10-17 22:46:17 +02:00
|
|
|
vbdisp_t *vbdisp;
|
2011-09-08 14:54:37 +02:00
|
|
|
EXCEPINFO ei;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
memset(&ei, 0, sizeof(ei));
|
|
|
|
if(retv)
|
|
|
|
V_VT(retv) = VT_EMPTY;
|
|
|
|
|
2019-10-17 22:46:17 +02:00
|
|
|
vbdisp = unsafe_impl_from_IDispatch(disp);
|
|
|
|
if(vbdisp && vbdisp->desc && vbdisp->desc->ctx == ctx)
|
|
|
|
return invoke_vbdisp(vbdisp, id, flags, FALSE, dp, retv);
|
|
|
|
|
2011-09-08 14:54:37 +02:00
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
2019-10-31 19:16:29 +01:00
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, retv, &ei, NULL /* CALLER_FIXME */);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
2011-09-08 14:54:37 +02:00
|
|
|
UINT err = 0;
|
|
|
|
|
|
|
|
TRACE("using IDispatch\n");
|
2019-10-31 19:16:29 +01:00
|
|
|
hres = IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, retv, &ei, &err);
|
2011-09-08 14:54:37 +02:00
|
|
|
}
|
|
|
|
|
2019-10-31 19:16:29 +01:00
|
|
|
if(hres == DISP_E_EXCEPTION) {
|
|
|
|
clear_ei(&ctx->ei);
|
|
|
|
ctx->ei = ei;
|
|
|
|
hres = SCRIPT_E_RECORDED;
|
|
|
|
}
|
2011-09-08 14:54:37 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2011-09-12 12:33:03 +02:00
|
|
|
|
2015-03-05 15:49:02 +01:00
|
|
|
HRESULT get_disp_value(script_ctx_t *ctx, IDispatch *disp, VARIANT *v)
|
|
|
|
{
|
|
|
|
DISPPARAMS dp = {NULL};
|
2019-10-18 16:20:09 +02:00
|
|
|
if(!disp)
|
|
|
|
return MAKE_VBSERROR(VBSE_OBJECT_VARIABLE_NOT_SET);
|
2015-03-05 15:49:02 +01:00
|
|
|
return disp_call(ctx, disp, DISPID_VALUE, &dp, v);
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:40:36 +01:00
|
|
|
HRESULT disp_propput(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD flags, DISPPARAMS *dp)
|
2011-09-12 12:33:03 +02:00
|
|
|
{
|
|
|
|
IDispatchEx *dispex;
|
2019-10-17 22:46:17 +02:00
|
|
|
vbdisp_t *vbdisp;
|
2011-09-12 12:33:03 +02:00
|
|
|
EXCEPINFO ei = {0};
|
|
|
|
HRESULT hres;
|
|
|
|
|
2019-10-17 22:46:17 +02:00
|
|
|
vbdisp = unsafe_impl_from_IDispatch(disp);
|
|
|
|
if(vbdisp && vbdisp->desc && vbdisp->desc->ctx == ctx)
|
|
|
|
return invoke_vbdisp(vbdisp, id, flags, FALSE, dp, NULL);
|
|
|
|
|
2011-09-12 12:33:03 +02:00
|
|
|
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = IDispatchEx_InvokeEx(dispex, id, ctx->lcid, flags, dp, NULL, &ei, NULL /* FIXME! */);
|
2011-09-12 12:33:03 +02:00
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
ULONG err = 0;
|
|
|
|
|
|
|
|
TRACE("using IDispatch\n");
|
2015-03-03 14:40:36 +01:00
|
|
|
hres = IDispatch_Invoke(disp, id, &IID_NULL, ctx->lcid, flags, dp, NULL, &ei, &err);
|
2011-09-12 12:33:03 +02:00
|
|
|
}
|
|
|
|
|
2019-10-31 19:16:29 +01:00
|
|
|
if(hres == DISP_E_EXCEPTION) {
|
|
|
|
clear_ei(&ctx->ei);
|
|
|
|
ctx->ei = ei;
|
|
|
|
hres = SCRIPT_E_RECORDED;
|
|
|
|
}
|
2011-09-12 12:33:03 +02:00
|
|
|
return hres;
|
|
|
|
}
|