2008-04-17 02:31:43 +02:00
|
|
|
/*
|
2009-09-06 18:51:39 +02:00
|
|
|
* Copyright 2008-2009 Jacek Caban for CodeWeavers
|
2008-04-17 02:31:43 +02:00
|
|
|
*
|
|
|
|
* 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 <stdarg.h>
|
2012-03-13 11:46:32 +01:00
|
|
|
#include <assert.h>
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2012-12-04 15:06:37 +01:00
|
|
|
#define NONAMELESSUNION
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2017-04-13 16:04:41 +02:00
|
|
|
#include "mscoree.h"
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
2012-12-04 15:06:37 +01:00
|
|
|
#define MAX_ARGS 16
|
|
|
|
|
2011-11-17 09:52:21 +01:00
|
|
|
static CRITICAL_SECTION cs_dispex_static_data;
|
|
|
|
static CRITICAL_SECTION_DEBUG cs_dispex_static_data_dbg =
|
|
|
|
{
|
|
|
|
0, 0, &cs_dispex_static_data,
|
|
|
|
{ &cs_dispex_static_data_dbg.ProcessLocksList, &cs_dispex_static_data_dbg.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": dispex_static_data") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION cs_dispex_static_data = { &cs_dispex_static_data_dbg, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
2009-10-02 13:51:48 +02:00
|
|
|
static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};
|
|
|
|
|
2008-04-19 12:55:24 +02:00
|
|
|
typedef struct {
|
|
|
|
DISPID id;
|
|
|
|
BSTR name;
|
|
|
|
tid_t tid;
|
2017-11-24 15:09:13 +01:00
|
|
|
dispex_hook_invoke_t hook;
|
2012-12-04 15:06:37 +01:00
|
|
|
SHORT call_vtbl_off;
|
2012-03-13 11:46:32 +01:00
|
|
|
SHORT put_vtbl_off;
|
|
|
|
SHORT get_vtbl_off;
|
|
|
|
SHORT func_disp_idx;
|
2012-12-04 15:06:37 +01:00
|
|
|
USHORT argc;
|
2012-03-13 11:46:32 +01:00
|
|
|
VARTYPE prop_vt;
|
2012-12-04 15:06:37 +01:00
|
|
|
VARTYPE *arg_types;
|
2008-04-19 12:55:24 +02:00
|
|
|
} func_info_t;
|
|
|
|
|
|
|
|
struct dispex_data_t {
|
2017-08-21 21:35:57 +02:00
|
|
|
dispex_static_data_t *desc;
|
2018-02-08 20:53:21 +01:00
|
|
|
compat_mode_t compat_mode;
|
2016-07-05 22:46:33 +02:00
|
|
|
|
2008-04-19 12:55:24 +02:00
|
|
|
DWORD func_cnt;
|
2016-07-05 22:46:11 +02:00
|
|
|
DWORD func_size;
|
2008-04-19 12:55:24 +02:00
|
|
|
func_info_t *funcs;
|
|
|
|
func_info_t **name_table;
|
2009-08-31 20:46:41 +02:00
|
|
|
DWORD func_disp_cnt;
|
2008-04-19 12:55:24 +02:00
|
|
|
|
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
2008-06-18 00:10:26 +02:00
|
|
|
typedef struct {
|
|
|
|
VARIANT var;
|
|
|
|
LPWSTR name;
|
2010-03-24 20:34:17 +01:00
|
|
|
DWORD flags;
|
2008-06-18 00:10:26 +02:00
|
|
|
} dynamic_prop_t;
|
|
|
|
|
2010-03-24 20:34:17 +01:00
|
|
|
#define DYNPROP_DELETED 0x01
|
|
|
|
|
2009-08-31 20:46:41 +02:00
|
|
|
typedef struct {
|
|
|
|
DispatchEx dispex;
|
2010-12-31 11:10:43 +01:00
|
|
|
IUnknown IUnknown_iface;
|
2012-09-24 14:10:05 +02:00
|
|
|
LONG ref;
|
2009-08-31 20:46:41 +02:00
|
|
|
DispatchEx *obj;
|
|
|
|
func_info_t *info;
|
|
|
|
} func_disp_t;
|
|
|
|
|
2012-09-24 14:10:05 +02:00
|
|
|
typedef struct {
|
|
|
|
func_disp_t *func_obj;
|
2014-11-28 16:18:53 +01:00
|
|
|
VARIANT val;
|
2012-09-24 14:10:05 +02:00
|
|
|
} func_obj_entry_t;
|
|
|
|
|
2008-06-18 00:10:26 +02:00
|
|
|
struct dispex_dynamic_data_t {
|
|
|
|
DWORD buf_size;
|
|
|
|
DWORD prop_cnt;
|
|
|
|
dynamic_prop_t *props;
|
2012-09-24 14:10:05 +02:00
|
|
|
func_obj_entry_t *func_disps;
|
2008-06-18 00:10:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DISPID_DYNPROP_0 0x50000000
|
|
|
|
#define DISPID_DYNPROP_MAX 0x5fffffff
|
|
|
|
|
2009-10-19 20:39:41 +02:00
|
|
|
#define FDEX_VERSION_MASK 0xf0000000
|
|
|
|
|
2008-04-17 02:32:18 +02:00
|
|
|
static ITypeLib *typelib;
|
|
|
|
static ITypeInfo *typeinfos[LAST_tid];
|
2008-04-19 12:55:24 +02:00
|
|
|
static struct list dispex_data_list = LIST_INIT(dispex_data_list);
|
2008-04-17 02:32:18 +02:00
|
|
|
|
|
|
|
static REFIID tid_ids[] = {
|
2010-11-08 12:49:07 +01:00
|
|
|
#define XIID(iface) &IID_ ## iface,
|
|
|
|
#define XDIID(iface) &DIID_ ## iface,
|
|
|
|
TID_LIST
|
|
|
|
#undef XIID
|
|
|
|
#undef XDIID
|
2008-04-17 02:32:18 +02:00
|
|
|
};
|
|
|
|
|
2011-07-15 13:09:44 +02:00
|
|
|
static HRESULT load_typelib(void)
|
2008-04-17 02:32:18 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
2011-07-15 13:09:44 +02:00
|
|
|
ITypeLib *tl;
|
2008-04-17 02:32:18 +02:00
|
|
|
|
2011-07-15 13:09:44 +02:00
|
|
|
hres = LoadRegTypeLib(&LIBID_MSHTML, 4, 0, LOCALE_SYSTEM_DEFAULT, &tl);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("LoadRegTypeLib failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-04-17 02:32:18 +02:00
|
|
|
|
2011-07-15 13:09:44 +02:00
|
|
|
if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
|
|
|
|
ITypeLib_Release(tl);
|
|
|
|
return hres;
|
|
|
|
}
|
2008-04-17 02:32:18 +02:00
|
|
|
|
2011-07-15 13:09:44 +02:00
|
|
|
static HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if (!typelib)
|
|
|
|
hres = load_typelib();
|
|
|
|
if (!typelib)
|
|
|
|
return hres;
|
2008-04-17 02:32:18 +02:00
|
|
|
|
|
|
|
if(!typeinfos[tid]) {
|
2011-03-09 10:07:39 +01:00
|
|
|
ITypeInfo *ti;
|
2008-04-17 02:32:18 +02:00
|
|
|
|
2011-03-09 10:07:39 +01:00
|
|
|
hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
|
2008-04-17 02:32:18 +02:00
|
|
|
if(FAILED(hres)) {
|
2014-05-09 13:08:48 +02:00
|
|
|
ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_mshtml_guid(tid_ids[tid]), hres);
|
2008-04-17 02:32:18 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-03-09 10:07:39 +01:00
|
|
|
if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
|
|
|
|
ITypeInfo_Release(ti);
|
2008-04-17 02:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*typeinfo = typeinfos[tid];
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_typelib(void)
|
|
|
|
{
|
2008-04-19 12:55:24 +02:00
|
|
|
dispex_data_t *iter;
|
2008-04-17 02:32:18 +02:00
|
|
|
unsigned i;
|
|
|
|
|
2008-04-19 12:55:24 +02:00
|
|
|
while(!list_empty(&dispex_data_list)) {
|
|
|
|
iter = LIST_ENTRY(list_head(&dispex_data_list), dispex_data_t, entry);
|
|
|
|
list_remove(&iter->entry);
|
|
|
|
|
|
|
|
for(i=0; i < iter->func_cnt; i++)
|
|
|
|
SysFreeString(iter->funcs[i].name);
|
|
|
|
|
|
|
|
heap_free(iter->funcs);
|
|
|
|
heap_free(iter->name_table);
|
|
|
|
heap_free(iter);
|
|
|
|
}
|
|
|
|
|
2008-04-17 02:32:18 +02:00
|
|
|
if(!typelib)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
|
|
|
|
if(typeinfos[i])
|
|
|
|
ITypeInfo_Release(typeinfos[i]);
|
|
|
|
|
|
|
|
ITypeLib_Release(typelib);
|
2011-11-17 09:52:21 +01:00
|
|
|
DeleteCriticalSection(&cs_dispex_static_data);
|
2008-04-17 02:32:18 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:23:50 +02:00
|
|
|
HRESULT get_class_typeinfo(const CLSID *clsid, ITypeInfo **typeinfo)
|
2011-07-15 13:09:44 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if (!typelib)
|
|
|
|
hres = load_typelib();
|
|
|
|
if (!typelib)
|
|
|
|
return hres;
|
|
|
|
|
2017-04-20 16:23:50 +02:00
|
|
|
hres = ITypeLib_GetTypeInfoOfGuid(typelib, clsid, typeinfo);
|
2011-07-15 13:09:44 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
ERR("GetTypeInfoOfGuid failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-12-04 15:06:37 +01:00
|
|
|
/* Not all argument types are supported yet */
|
|
|
|
#define BUILTIN_ARG_TYPES_SWITCH \
|
|
|
|
CASE_VT(VT_I2, INT16, V_I2); \
|
2017-11-01 16:43:42 +01:00
|
|
|
CASE_VT(VT_UI2, UINT16, V_UI2); \
|
2012-12-04 15:06:37 +01:00
|
|
|
CASE_VT(VT_I4, INT32, V_I4); \
|
2018-02-07 16:25:51 +01:00
|
|
|
CASE_VT(VT_UI4, UINT32, V_UI4); \
|
2012-12-04 15:06:37 +01:00
|
|
|
CASE_VT(VT_R4, float, V_R4); \
|
|
|
|
CASE_VT(VT_BSTR, BSTR, V_BSTR); \
|
|
|
|
CASE_VT(VT_BOOL, VARIANT_BOOL, V_BOOL)
|
|
|
|
|
|
|
|
/* List all types used by IDispatchEx-based properties */
|
|
|
|
#define BUILTIN_TYPES_SWITCH \
|
|
|
|
BUILTIN_ARG_TYPES_SWITCH; \
|
|
|
|
CASE_VT(VT_VARIANT, VARIANT, *); \
|
|
|
|
CASE_VT(VT_PTR, void*, V_BYREF); \
|
|
|
|
CASE_VT(VT_UNKNOWN, IUnknown*, V_UNKNOWN); \
|
2017-12-05 18:24:46 +01:00
|
|
|
CASE_VT(VT_DISPATCH, IDispatch*, V_DISPATCH); \
|
|
|
|
CASE_VT(VT_UI8, ULONGLONG, V_UI8)
|
2012-12-04 15:06:37 +01:00
|
|
|
|
|
|
|
static BOOL is_arg_type_supported(VARTYPE vt)
|
|
|
|
{
|
|
|
|
switch(vt) {
|
|
|
|
#define CASE_VT(x,a,b) case x: return TRUE
|
|
|
|
BUILTIN_ARG_TYPES_SWITCH;
|
|
|
|
#undef CASE_VT
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
static void add_func_info(dispex_data_t *data, tid_t tid, const FUNCDESC *desc, ITypeInfo *dti,
|
|
|
|
dispex_hook_invoke_t hook)
|
2008-04-19 12:55:24 +02:00
|
|
|
{
|
2012-03-13 11:46:32 +01:00
|
|
|
func_info_t *info;
|
2016-07-07 12:50:03 +02:00
|
|
|
BSTR name;
|
2008-04-19 12:55:24 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-07 12:50:03 +02:00
|
|
|
hres = ITypeInfo_GetDocumentation(dti, desc->memid, &name, NULL, NULL, NULL);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2014-12-14 17:54:00 +01:00
|
|
|
for(info = data->funcs; info < data->funcs+data->func_cnt; info++) {
|
2016-07-07 12:50:03 +02:00
|
|
|
if(info->id == desc->memid || !strcmpW(info->name, name)) {
|
|
|
|
if(info->tid != tid) {
|
|
|
|
SysFreeString(name);
|
2014-12-14 17:54:00 +01:00
|
|
|
return; /* Duplicated in other interface */
|
2016-07-07 12:50:03 +02:00
|
|
|
}
|
2014-12-14 17:54:00 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(info == data->funcs+data->func_cnt) {
|
2016-07-05 22:46:11 +02:00
|
|
|
if(data->func_cnt == data->func_size)
|
|
|
|
data->funcs = heap_realloc_zero(data->funcs, (data->func_size <<= 1)*sizeof(func_info_t));
|
2012-03-13 11:46:32 +01:00
|
|
|
info = data->funcs+data->func_cnt;
|
2016-02-24 15:21:24 +01:00
|
|
|
|
2012-03-13 11:46:32 +01:00
|
|
|
data->func_cnt++;
|
|
|
|
|
|
|
|
info->id = desc->memid;
|
2016-07-07 12:50:03 +02:00
|
|
|
info->name = name;
|
2012-03-13 11:46:32 +01:00
|
|
|
info->tid = tid;
|
|
|
|
info->func_disp_idx = -1;
|
|
|
|
info->prop_vt = VT_EMPTY;
|
2017-11-24 15:09:13 +01:00
|
|
|
info->hook = hook;
|
2016-07-07 12:50:03 +02:00
|
|
|
}else {
|
|
|
|
SysFreeString(name);
|
2012-03-13 11:46:32 +01:00
|
|
|
}
|
2008-04-19 12:55:24 +02:00
|
|
|
|
2012-03-13 11:46:32 +01:00
|
|
|
if(desc->invkind & DISPATCH_METHOD) {
|
2012-12-04 15:06:37 +01:00
|
|
|
unsigned i;
|
|
|
|
|
2012-03-13 11:46:32 +01:00
|
|
|
info->func_disp_idx = data->func_disp_cnt++;
|
2012-12-04 15:06:37 +01:00
|
|
|
info->argc = desc->cParams;
|
|
|
|
|
|
|
|
assert(info->argc < MAX_ARGS);
|
|
|
|
assert(desc->funckind == FUNC_DISPATCH);
|
|
|
|
|
|
|
|
info->arg_types = heap_alloc(sizeof(*info->arg_types) * info->argc);
|
|
|
|
if(!info->arg_types)
|
|
|
|
return; /* FIXME: real error instead of fallback */
|
|
|
|
|
|
|
|
for(i=0; i < info->argc; i++)
|
|
|
|
info->arg_types[i] = desc->lprgelemdescParam[i].tdesc.vt;
|
|
|
|
|
|
|
|
info->prop_vt = desc->elemdescFunc.tdesc.vt;
|
|
|
|
if(info->prop_vt != VT_VOID && !is_arg_type_supported(info->prop_vt)) {
|
2013-05-09 10:22:06 +02:00
|
|
|
TRACE("%s: return type %d\n", debugstr_w(info->name), info->prop_vt);
|
2012-12-04 15:06:37 +01:00
|
|
|
return; /* Fallback to ITypeInfo::Invoke */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(desc->cParamsOpt) {
|
|
|
|
TRACE("%s: optional params\n", debugstr_w(info->name));
|
|
|
|
return; /* Fallback to ITypeInfo::Invoke */
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i < info->argc; i++) {
|
|
|
|
if(!is_arg_type_supported(info->arg_types[i])) {
|
|
|
|
return; /* Fallback to ITypeInfo for unsupported arg types */
|
|
|
|
}
|
|
|
|
|
|
|
|
if(desc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT) {
|
|
|
|
TRACE("%s param %d: default value\n", debugstr_w(info->name), i);
|
|
|
|
return; /* Fallback to ITypeInfo::Invoke */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(info->argc <= MAX_ARGS);
|
|
|
|
assert(desc->callconv == CC_STDCALL);
|
|
|
|
|
|
|
|
info->call_vtbl_off = desc->oVft/sizeof(void*);
|
2012-03-13 11:46:32 +01:00
|
|
|
}else if(desc->invkind & (DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYGET)) {
|
|
|
|
VARTYPE vt = VT_EMPTY;
|
2008-04-19 12:55:24 +02:00
|
|
|
|
2012-03-13 11:46:32 +01:00
|
|
|
if(desc->invkind & DISPATCH_PROPERTYGET) {
|
|
|
|
vt = desc->elemdescFunc.tdesc.vt;
|
|
|
|
info->get_vtbl_off = desc->oVft/sizeof(void*);
|
|
|
|
}
|
|
|
|
if(desc->invkind & DISPATCH_PROPERTYPUT) {
|
|
|
|
assert(desc->cParams == 1);
|
|
|
|
vt = desc->lprgelemdescParam->tdesc.vt;
|
|
|
|
info->put_vtbl_off = desc->oVft/sizeof(void*);
|
|
|
|
}
|
2008-04-19 12:55:24 +02:00
|
|
|
|
2012-03-13 11:46:32 +01:00
|
|
|
assert(info->prop_vt == VT_EMPTY || vt == info->prop_vt);
|
|
|
|
info->prop_vt = vt;
|
|
|
|
}
|
2008-04-19 12:55:24 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
static HRESULT process_interface(dispex_data_t *data, tid_t tid, ITypeInfo *disp_typeinfo, const dispex_hook_t *hooks)
|
2016-02-24 15:21:24 +01:00
|
|
|
{
|
|
|
|
unsigned i = 7; /* skip IDispatch functions */
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
FUNCDESC *funcdesc;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = get_typeinfo(tid, &typeinfo);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
while(1) {
|
2017-11-24 15:09:13 +01:00
|
|
|
const dispex_hook_t *hook = NULL;
|
|
|
|
|
2016-02-24 15:21:24 +01:00
|
|
|
hres = ITypeInfo_GetFuncDesc(typeinfo, i++, &funcdesc);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
if(hooks) {
|
|
|
|
for(hook = hooks; hook->dispid != DISPID_UNKNOWN; hook++) {
|
|
|
|
if(hook->dispid == funcdesc->memid)
|
2017-05-09 17:32:33 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-11-24 15:09:13 +01:00
|
|
|
if(hook->dispid == DISPID_UNKNOWN)
|
|
|
|
hook = NULL;
|
2017-05-09 17:32:33 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
if(!hook || hook->invoke) {
|
2017-05-09 17:32:33 +02:00
|
|
|
TRACE("adding...\n");
|
2017-11-24 15:09:13 +01:00
|
|
|
add_func_info(data, tid, funcdesc, disp_typeinfo ? disp_typeinfo : typeinfo,
|
|
|
|
hook ? hook->invoke : NULL);
|
2017-05-09 17:32:33 +02:00
|
|
|
}
|
2016-02-24 15:21:24 +01:00
|
|
|
|
|
|
|
ITypeInfo_ReleaseFuncDesc(typeinfo, funcdesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
void dispex_info_add_interface(dispex_data_t *info, tid_t tid, const dispex_hook_t *hooks)
|
2016-07-05 22:48:20 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
hres = process_interface(info, tid, NULL, hooks);
|
2016-07-05 22:48:20 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
ERR("process_interface failed: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
2008-04-19 12:55:24 +02:00
|
|
|
static int dispid_cmp(const void *p1, const void *p2)
|
|
|
|
{
|
2010-03-27 14:58:41 +01:00
|
|
|
return ((const func_info_t*)p1)->id - ((const func_info_t*)p2)->id;
|
2008-04-19 12:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int func_name_cmp(const void *p1, const void *p2)
|
|
|
|
{
|
2010-03-27 14:58:41 +01:00
|
|
|
return strcmpiW((*(func_info_t* const*)p1)->name, (*(func_info_t* const*)p2)->name);
|
2008-04-19 12:55:24 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 21:35:57 +02:00
|
|
|
static dispex_data_t *preprocess_dispex_data(dispex_static_data_t *desc, compat_mode_t compat_mode)
|
2008-04-19 12:55:24 +02:00
|
|
|
{
|
2016-02-24 15:21:24 +01:00
|
|
|
const tid_t *tid;
|
2008-04-19 12:55:24 +02:00
|
|
|
dispex_data_t *data;
|
2016-07-05 22:46:11 +02:00
|
|
|
DWORD i;
|
2016-02-24 15:21:24 +01:00
|
|
|
ITypeInfo *dti;
|
2008-04-19 12:55:24 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-05 22:46:23 +02:00
|
|
|
if(desc->disp_tid) {
|
|
|
|
hres = get_typeinfo(desc->disp_tid, &dti);
|
2009-10-02 13:51:48 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("Could not get disp type info: %08x\n", hres);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-19 12:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data = heap_alloc(sizeof(dispex_data_t));
|
2015-01-11 23:40:19 +01:00
|
|
|
if (!data) {
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-05 22:46:33 +02:00
|
|
|
data->desc = desc;
|
2018-02-08 20:53:21 +01:00
|
|
|
data->compat_mode = compat_mode;
|
2008-04-19 12:55:24 +02:00
|
|
|
data->func_cnt = 0;
|
2009-08-31 20:46:41 +02:00
|
|
|
data->func_disp_cnt = 0;
|
2016-07-05 22:46:11 +02:00
|
|
|
data->func_size = 16;
|
|
|
|
data->funcs = heap_alloc_zero(data->func_size*sizeof(func_info_t));
|
2015-01-11 23:40:19 +01:00
|
|
|
if (!data->funcs) {
|
|
|
|
heap_free (data);
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-19 12:55:24 +02:00
|
|
|
list_add_tail(&dispex_data_list, &data->entry);
|
|
|
|
|
2016-07-05 22:48:20 +02:00
|
|
|
if(desc->init_info)
|
2016-07-07 12:49:45 +02:00
|
|
|
desc->init_info(data, compat_mode);
|
2016-07-05 22:48:20 +02:00
|
|
|
|
2016-07-05 22:46:23 +02:00
|
|
|
for(tid = desc->iface_tids; *tid; tid++) {
|
2017-05-09 17:32:33 +02:00
|
|
|
hres = process_interface(data, *tid, dti, NULL);
|
2008-04-19 12:55:24 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!data->func_cnt) {
|
|
|
|
heap_free(data->funcs);
|
2011-07-29 14:31:22 +02:00
|
|
|
data->name_table = NULL;
|
2008-04-19 12:55:24 +02:00
|
|
|
data->funcs = NULL;
|
2016-07-05 22:46:11 +02:00
|
|
|
data->func_size = 0;
|
2011-07-29 14:31:22 +02:00
|
|
|
return data;
|
2008-04-19 12:55:24 +02:00
|
|
|
}
|
|
|
|
|
2011-07-29 14:31:22 +02:00
|
|
|
|
|
|
|
data->funcs = heap_realloc(data->funcs, data->func_cnt * sizeof(func_info_t));
|
2008-04-19 12:55:24 +02:00
|
|
|
qsort(data->funcs, data->func_cnt, sizeof(func_info_t), dispid_cmp);
|
|
|
|
|
2011-07-29 14:31:22 +02:00
|
|
|
data->name_table = heap_alloc(data->func_cnt * sizeof(func_info_t*));
|
|
|
|
for(i=0; i < data->func_cnt; i++)
|
|
|
|
data->name_table[i] = data->funcs+i;
|
|
|
|
qsort(data->name_table, data->func_cnt, sizeof(func_info_t*), func_name_cmp);
|
2008-04-19 12:55:24 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-11-23 19:28:43 +01:00
|
|
|
static int id_cmp(const void *p1, const void *p2)
|
|
|
|
{
|
2010-03-27 14:58:41 +01:00
|
|
|
return *(const DISPID*)p1 - *(const DISPID*)p2;
|
2009-11-23 19:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT get_dispids(tid_t tid, DWORD *ret_size, DISPID **ret)
|
|
|
|
{
|
|
|
|
unsigned i, func_cnt;
|
|
|
|
FUNCDESC *funcdesc;
|
|
|
|
ITypeInfo *ti;
|
|
|
|
TYPEATTR *attr;
|
|
|
|
DISPID *ids;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = get_typeinfo(tid, &ti);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = ITypeInfo_GetTypeAttr(ti, &attr);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
ITypeInfo_Release(ti);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
func_cnt = attr->cFuncs;
|
|
|
|
ITypeInfo_ReleaseTypeAttr(ti, attr);
|
|
|
|
|
|
|
|
ids = heap_alloc(func_cnt*sizeof(DISPID));
|
|
|
|
if(!ids) {
|
|
|
|
ITypeInfo_Release(ti);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i < func_cnt; i++) {
|
|
|
|
hres = ITypeInfo_GetFuncDesc(ti, i, &funcdesc);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
|
|
|
|
ids[i] = funcdesc->memid;
|
|
|
|
ITypeInfo_ReleaseFuncDesc(ti, funcdesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ITypeInfo_Release(ti);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(ids);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(ids, func_cnt, sizeof(DISPID), id_cmp);
|
|
|
|
|
|
|
|
*ret_size = func_cnt;
|
|
|
|
*ret = ids;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-29 01:38:09 +02:00
|
|
|
static inline BOOL is_custom_dispid(DISPID id)
|
|
|
|
{
|
|
|
|
return MSHTML_DISPID_CUSTOM_MIN <= id && id <= MSHTML_DISPID_CUSTOM_MAX;
|
|
|
|
}
|
|
|
|
|
2008-06-18 00:10:26 +02:00
|
|
|
static inline BOOL is_dynamic_dispid(DISPID id)
|
|
|
|
{
|
|
|
|
return DISPID_DYNPROP_0 <= id && id <= DISPID_DYNPROP_MAX;
|
|
|
|
}
|
|
|
|
|
2012-07-24 15:55:54 +02:00
|
|
|
dispex_prop_type_t get_dispid_type(DISPID id)
|
|
|
|
{
|
|
|
|
if(is_dynamic_dispid(id))
|
|
|
|
return DISPEXPROP_DYNAMIC;
|
|
|
|
if(is_custom_dispid(id))
|
|
|
|
return DISPEXPROP_CUSTOM;
|
|
|
|
return DISPEXPROP_BUILTIN;
|
|
|
|
}
|
|
|
|
|
2011-03-02 13:34:58 +01:00
|
|
|
static HRESULT variant_copy(VARIANT *dest, VARIANT *src)
|
|
|
|
{
|
|
|
|
if(V_VT(src) == VT_BSTR && !V_BSTR(src)) {
|
|
|
|
V_VT(dest) = VT_BSTR;
|
|
|
|
V_BSTR(dest) = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VariantCopy(dest, src);
|
|
|
|
}
|
|
|
|
|
2011-08-23 11:33:18 +02:00
|
|
|
static inline dispex_dynamic_data_t *get_dynamic_data(DispatchEx *This)
|
2009-08-31 20:46:03 +02:00
|
|
|
{
|
2011-08-23 11:33:18 +02:00
|
|
|
if(This->dynamic_data)
|
|
|
|
return This->dynamic_data;
|
|
|
|
|
|
|
|
This->dynamic_data = heap_alloc_zero(sizeof(dispex_dynamic_data_t));
|
|
|
|
if(!This->dynamic_data)
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-05 22:46:33 +02:00
|
|
|
if(This->info->desc->vtbl && This->info->desc->vtbl->populate_props)
|
|
|
|
This->info->desc->vtbl->populate_props(This);
|
2011-08-23 11:33:18 +02:00
|
|
|
|
|
|
|
return This->dynamic_data;
|
2009-08-31 20:46:03 +02:00
|
|
|
}
|
|
|
|
|
2009-11-01 19:20:53 +01:00
|
|
|
static HRESULT get_dynamic_prop(DispatchEx *This, const WCHAR *name, DWORD flags, dynamic_prop_t **ret)
|
2008-10-09 22:30:51 +02:00
|
|
|
{
|
2009-11-01 19:20:53 +01:00
|
|
|
const BOOL alloc = flags & fdexNameEnsure;
|
|
|
|
dispex_dynamic_data_t *data;
|
2010-03-24 20:34:17 +01:00
|
|
|
dynamic_prop_t *prop;
|
2008-10-09 22:30:51 +02:00
|
|
|
|
2011-08-23 11:33:18 +02:00
|
|
|
data = get_dynamic_data(This);
|
|
|
|
if(!data)
|
|
|
|
return E_OUTOFMEMORY;
|
2008-10-09 22:30:51 +02:00
|
|
|
|
2010-03-24 20:34:17 +01:00
|
|
|
for(prop = data->props; prop < data->props+data->prop_cnt; prop++) {
|
|
|
|
if(flags & fdexNameCaseInsensitive ? !strcmpiW(prop->name, name) : !strcmpW(prop->name, name)) {
|
|
|
|
if(prop->flags & DYNPROP_DELETED) {
|
|
|
|
if(!alloc)
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
prop->flags &= ~DYNPROP_DELETED;
|
|
|
|
}
|
|
|
|
*ret = prop;
|
2009-08-31 20:46:03 +02:00
|
|
|
return S_OK;
|
2008-10-09 22:30:51 +02:00
|
|
|
}
|
2009-08-31 20:46:03 +02:00
|
|
|
}
|
2008-10-09 22:30:51 +02:00
|
|
|
|
2009-11-01 19:21:19 +01:00
|
|
|
if(!alloc)
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
2009-08-31 20:46:03 +02:00
|
|
|
TRACE("creating dynamic prop %s\n", debugstr_w(name));
|
2008-10-09 22:30:51 +02:00
|
|
|
|
2009-08-31 20:46:03 +02:00
|
|
|
if(!data->buf_size) {
|
|
|
|
data->props = heap_alloc(sizeof(dynamic_prop_t)*4);
|
|
|
|
if(!data->props)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
data->buf_size = 4;
|
|
|
|
}else if(data->buf_size == data->prop_cnt) {
|
|
|
|
dynamic_prop_t *new_props;
|
2008-10-09 22:30:51 +02:00
|
|
|
|
2009-08-31 20:46:03 +02:00
|
|
|
new_props = heap_realloc(data->props, sizeof(dynamic_prop_t)*(data->buf_size<<1));
|
|
|
|
if(!new_props)
|
|
|
|
return E_OUTOFMEMORY;
|
2008-10-09 22:30:51 +02:00
|
|
|
|
2009-08-31 20:46:03 +02:00
|
|
|
data->props = new_props;
|
|
|
|
data->buf_size <<= 1;
|
2008-10-09 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
2010-03-24 20:34:17 +01:00
|
|
|
prop = data->props + data->prop_cnt;
|
2009-08-31 20:46:03 +02:00
|
|
|
|
2010-03-24 20:34:17 +01:00
|
|
|
prop->name = heap_strdupW(name);
|
|
|
|
if(!prop->name)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
VariantInit(&prop->var);
|
|
|
|
prop->flags = 0;
|
|
|
|
data->prop_cnt++;
|
|
|
|
*ret = prop;
|
2009-08-31 20:46:03 +02:00
|
|
|
return S_OK;
|
2008-10-09 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT dispex_get_dprop_ref(DispatchEx *This, const WCHAR *name, BOOL alloc, VARIANT **ret)
|
|
|
|
{
|
|
|
|
dynamic_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-11-01 19:20:53 +01:00
|
|
|
hres = get_dynamic_prop(This, name, alloc ? fdexNameEnsure : 0, &prop);
|
2008-10-09 22:30:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*ret = &prop->var;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 12:10:48 +02:00
|
|
|
HRESULT dispex_get_dynid(DispatchEx *This, const WCHAR *name, DISPID *id)
|
|
|
|
{
|
|
|
|
dynamic_prop_t *prop;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = get_dynamic_prop(This, name, fdexNameEnsure, &prop);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*id = DISPID_DYNPROP_0 + (prop - This->dynamic_data->props);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-31 20:43:44 +02:00
|
|
|
static HRESULT dispex_value(DispatchEx *This, LCID lcid, WORD flags, DISPPARAMS *params,
|
|
|
|
VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
|
|
|
|
{
|
2016-07-05 22:46:33 +02:00
|
|
|
if(This->info->desc->vtbl && This->info->desc->vtbl->value)
|
|
|
|
return This->info->desc->vtbl->value(This, lcid, flags, params, res, ei, caller);
|
2009-08-31 20:43:44 +02:00
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_PROPERTYGET:
|
|
|
|
V_VT(res) = VT_BSTR;
|
|
|
|
V_BSTR(res) = SysAllocString(objectW);
|
|
|
|
if(!V_BSTR(res))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-31 20:45:42 +02:00
|
|
|
static HRESULT typeinfo_invoke(DispatchEx *This, func_info_t *func, WORD flags, DISPPARAMS *dp, VARIANT *res,
|
|
|
|
EXCEPINFO *ei)
|
|
|
|
{
|
2016-01-11 20:49:24 +01:00
|
|
|
DISPPARAMS params = {dp->rgvarg+dp->cNamedArgs, NULL, dp->cArgs-dp->cNamedArgs, 0};
|
2009-08-31 20:45:42 +02:00
|
|
|
ITypeInfo *ti;
|
|
|
|
IUnknown *unk;
|
|
|
|
UINT argerr=0;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = get_typeinfo(func->tid, &ti);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("Could not get type info: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(This->outer, tid_ids[func->tid], (void**)&unk);
|
|
|
|
if(FAILED(hres)) {
|
2014-05-09 13:08:48 +02:00
|
|
|
ERR("Could not get iface %s: %08x\n", debugstr_mshtml_guid(tid_ids[func->tid]), hres);
|
2009-08-31 20:45:42 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2016-01-11 20:49:24 +01:00
|
|
|
hres = ITypeInfo_Invoke(ti, unk, func->id, flags, ¶ms, res, ei, &argerr);
|
2009-08-31 20:45:42 +02:00
|
|
|
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-12-31 11:10:43 +01:00
|
|
|
static inline func_disp_t *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, func_disp_t, IUnknown_iface);
|
|
|
|
}
|
2009-08-31 20:46:41 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI Function_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-31 11:10:43 +01:00
|
|
|
func_disp_t *This = impl_from_IUnknown(iface);
|
2009-08-31 20:46:41 +02:00
|
|
|
|
2015-01-20 16:24:27 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
|
|
|
|
|
2009-08-31 20:46:41 +02:00
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
2010-12-31 11:10:43 +01:00
|
|
|
*ppv = &This->IUnknown_iface;
|
2009-08-31 20:46:41 +02:00
|
|
|
}else if(dispex_query_interface(&This->dispex, riid, ppv)) {
|
|
|
|
return *ppv ? S_OK : E_NOINTERFACE;
|
|
|
|
}else {
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Function_AddRef(IUnknown *iface)
|
|
|
|
{
|
2010-12-31 11:10:43 +01:00
|
|
|
func_disp_t *This = impl_from_IUnknown(iface);
|
2012-09-24 14:10:05 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
2009-08-31 20:46:41 +02:00
|
|
|
|
2012-09-24 14:10:05 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2009-08-31 20:46:41 +02:00
|
|
|
|
2012-09-24 14:10:05 +02:00
|
|
|
return ref;
|
2009-08-31 20:46:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Function_Release(IUnknown *iface)
|
|
|
|
{
|
2010-12-31 11:10:43 +01:00
|
|
|
func_disp_t *This = impl_from_IUnknown(iface);
|
2012-09-24 14:10:05 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2009-08-31 20:46:41 +02:00
|
|
|
|
2012-09-24 14:10:05 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2009-08-31 20:46:41 +02:00
|
|
|
|
2012-09-24 14:10:05 +02:00
|
|
|
if(!ref) {
|
|
|
|
assert(!This->obj);
|
|
|
|
release_dispex(&This->dispex);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2009-08-31 20:46:41 +02:00
|
|
|
}
|
|
|
|
|
2010-12-27 18:34:39 +01:00
|
|
|
static const IUnknownVtbl FunctionUnkVtbl = {
|
|
|
|
Function_QueryInterface,
|
|
|
|
Function_AddRef,
|
|
|
|
Function_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline func_disp_t *impl_from_DispatchEx(DispatchEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, func_disp_t, dispex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT function_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *params,
|
2009-08-31 20:46:41 +02:00
|
|
|
VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
|
|
|
|
{
|
2010-12-27 18:34:39 +01:00
|
|
|
func_disp_t *This = impl_from_DispatchEx(dispex);
|
2009-08-31 20:46:41 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(flags) {
|
2009-10-13 20:50:28 +02:00
|
|
|
case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
|
|
|
|
if(!res)
|
|
|
|
return E_INVALIDARG;
|
2011-10-04 23:48:41 +02:00
|
|
|
/* fall through */
|
2009-08-31 20:46:41 +02:00
|
|
|
case DISPATCH_METHOD:
|
2012-09-24 14:10:05 +02:00
|
|
|
if(!This->obj)
|
|
|
|
return E_UNEXPECTED;
|
2009-08-31 20:46:41 +02:00
|
|
|
hres = typeinfo_invoke(This->obj, This->info, flags, params, res, ei);
|
|
|
|
break;
|
2014-06-02 15:45:13 +02:00
|
|
|
case DISPATCH_PROPERTYGET: {
|
|
|
|
unsigned name_len;
|
|
|
|
WCHAR *ptr;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
static const WCHAR func_prefixW[] =
|
|
|
|
{'\n','f','u','n','c','t','i','o','n',' '};
|
|
|
|
static const WCHAR func_suffixW[] =
|
|
|
|
{'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
|
|
|
|
|
|
|
|
/* FIXME: This probably should be more generic. Also we should try to get IID_IActiveScriptSite and SID_GetCaller. */
|
|
|
|
if(!caller)
|
|
|
|
return E_ACCESSDENIED;
|
|
|
|
|
|
|
|
name_len = SysStringLen(This->info->name);
|
|
|
|
ptr = str = SysAllocStringLen(NULL, name_len + (sizeof(func_prefixW)+sizeof(func_suffixW))/sizeof(WCHAR));
|
|
|
|
if(!str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
memcpy(ptr, func_prefixW, sizeof(func_prefixW));
|
|
|
|
ptr += sizeof(func_prefixW)/sizeof(WCHAR);
|
|
|
|
|
|
|
|
memcpy(ptr, This->info->name, name_len*sizeof(WCHAR));
|
|
|
|
ptr += name_len;
|
|
|
|
|
|
|
|
memcpy(ptr, func_suffixW, sizeof(func_suffixW));
|
|
|
|
|
|
|
|
V_VT(res) = VT_BSTR;
|
|
|
|
V_BSTR(res) = str;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-08-31 20:46:41 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unimplemented flags %x\n", flags);
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const dispex_static_data_vtbl_t function_dispex_vtbl = {
|
|
|
|
function_value,
|
|
|
|
NULL,
|
2011-08-23 11:33:18 +02:00
|
|
|
NULL,
|
2009-08-31 20:46:41 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-10-02 13:51:48 +02:00
|
|
|
static const tid_t function_iface_tids[] = {0};
|
|
|
|
|
2009-08-31 20:46:41 +02:00
|
|
|
static dispex_static_data_t function_dispex = {
|
|
|
|
&function_dispex_vtbl,
|
2009-10-02 13:51:48 +02:00
|
|
|
NULL_tid,
|
|
|
|
function_iface_tids
|
2009-08-31 20:46:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static func_disp_t *create_func_disp(DispatchEx *obj, func_info_t *info)
|
|
|
|
{
|
|
|
|
func_disp_t *ret;
|
|
|
|
|
|
|
|
ret = heap_alloc_zero(sizeof(func_disp_t));
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-31 11:10:43 +01:00
|
|
|
ret->IUnknown_iface.lpVtbl = &FunctionUnkVtbl;
|
|
|
|
init_dispex(&ret->dispex, &ret->IUnknown_iface, &function_dispex);
|
2012-09-24 14:10:05 +02:00
|
|
|
ret->ref = 1;
|
2009-08-31 20:46:41 +02:00
|
|
|
ret->obj = obj;
|
|
|
|
ret->info = info;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:46:26 +02:00
|
|
|
static HRESULT invoke_disp_value(DispatchEx *This, IDispatch *func_disp, LCID lcid, WORD flags, DISPPARAMS *dp,
|
|
|
|
VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
DISPID named_arg = DISPID_THIS;
|
|
|
|
DISPPARAMS new_dp = {NULL, &named_arg, 0, 1};
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(dp->cNamedArgs) {
|
|
|
|
FIXME("named args not supported\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_dp.rgvarg = heap_alloc((dp->cArgs+1)*sizeof(VARIANTARG));
|
|
|
|
if(!new_dp.rgvarg)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
new_dp.cArgs = dp->cArgs+1;
|
|
|
|
memcpy(new_dp.rgvarg+1, dp->rgvarg, dp->cArgs*sizeof(VARIANTARG));
|
|
|
|
|
|
|
|
V_VT(new_dp.rgvarg) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(new_dp.rgvarg) = (IDispatch*)&This->IDispatchEx_iface;
|
|
|
|
|
|
|
|
hres = IDispatch_QueryInterface(func_disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
TRACE(">>>\n");
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IDispatchEx_InvokeEx(dispex, DISPID_VALUE, lcid, flags, &new_dp, res, ei, caller);
|
|
|
|
IDispatchEx_Release(dispex);
|
|
|
|
}else {
|
|
|
|
ULONG err = 0;
|
|
|
|
hres = IDispatch_Invoke(func_disp, DISPID_VALUE, &IID_NULL, lcid, flags, &new_dp, res, ei, &err);
|
|
|
|
}
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
TRACE("<<< %s\n", debugstr_variant(res));
|
|
|
|
else
|
|
|
|
WARN("<<< %08x\n", hres);
|
|
|
|
|
|
|
|
heap_free(new_dp.rgvarg);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-09-24 14:10:05 +02:00
|
|
|
static HRESULT get_func_obj_entry(DispatchEx *This, func_info_t *func, func_obj_entry_t **ret)
|
|
|
|
{
|
|
|
|
dispex_dynamic_data_t *dynamic_data;
|
2014-11-28 16:18:53 +01:00
|
|
|
func_obj_entry_t *entry;
|
2012-09-24 14:10:05 +02:00
|
|
|
|
|
|
|
dynamic_data = get_dynamic_data(This);
|
|
|
|
if(!dynamic_data)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if(!dynamic_data->func_disps) {
|
2016-07-05 22:46:33 +02:00
|
|
|
dynamic_data->func_disps = heap_alloc_zero(This->info->func_disp_cnt * sizeof(*dynamic_data->func_disps));
|
2012-09-24 14:10:05 +02:00
|
|
|
if(!dynamic_data->func_disps)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
entry = dynamic_data->func_disps + func->func_disp_idx;
|
|
|
|
if(!entry->func_obj) {
|
|
|
|
entry->func_obj = create_func_disp(This, func);
|
|
|
|
if(!entry->func_obj)
|
2012-09-24 14:10:05 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
IDispatchEx_AddRef(&entry->func_obj->dispex.IDispatchEx_iface);
|
|
|
|
V_VT(&entry->val) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&entry->val) = (IDispatch*)&entry->func_obj->dispex.IDispatchEx_iface;
|
2012-09-24 14:10:05 +02:00
|
|
|
}
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
*ret = entry;
|
2012-09-24 14:10:05 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-06 18:51:39 +02:00
|
|
|
static HRESULT get_builtin_func(dispex_data_t *data, DISPID id, func_info_t **ret)
|
|
|
|
{
|
|
|
|
int min, max, n;
|
|
|
|
|
|
|
|
min = 0;
|
|
|
|
max = data->func_cnt-1;
|
|
|
|
|
|
|
|
while(min <= max) {
|
|
|
|
n = (min+max)/2;
|
|
|
|
|
2009-10-02 13:51:48 +02:00
|
|
|
if(data->funcs[n].id == id) {
|
|
|
|
*ret = data->funcs+n;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2009-09-06 18:51:39 +02:00
|
|
|
|
|
|
|
if(data->funcs[n].id < id)
|
|
|
|
min = n+1;
|
|
|
|
else
|
|
|
|
max = n-1;
|
|
|
|
}
|
|
|
|
|
2009-10-02 13:51:48 +02:00
|
|
|
WARN("invalid id %x\n", id);
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
2009-09-06 18:51:39 +02:00
|
|
|
}
|
|
|
|
|
2010-03-24 19:59:38 +01:00
|
|
|
static HRESULT get_builtin_id(DispatchEx *This, BSTR name, DWORD grfdex, DISPID *ret)
|
|
|
|
{
|
|
|
|
int min, max, n, c;
|
|
|
|
|
|
|
|
min = 0;
|
2016-07-05 22:46:46 +02:00
|
|
|
max = This->info->func_cnt-1;
|
2010-03-24 19:59:38 +01:00
|
|
|
|
|
|
|
while(min <= max) {
|
|
|
|
n = (min+max)/2;
|
|
|
|
|
2016-07-05 22:46:46 +02:00
|
|
|
c = strcmpiW(This->info->name_table[n]->name, name);
|
2010-03-24 19:59:38 +01:00
|
|
|
if(!c) {
|
2016-07-05 22:46:46 +02:00
|
|
|
if((grfdex & fdexNameCaseSensitive) && strcmpW(This->info->name_table[n]->name, name))
|
2010-03-24 19:59:38 +01:00
|
|
|
break;
|
|
|
|
|
2016-07-05 22:46:46 +02:00
|
|
|
*ret = This->info->name_table[n]->id;
|
2010-03-24 19:59:38 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c > 0)
|
|
|
|
max = n-1;
|
|
|
|
else
|
|
|
|
min = n+1;
|
|
|
|
}
|
|
|
|
|
2016-07-05 22:46:33 +02:00
|
|
|
if(This->info->desc->vtbl && This->info->desc->vtbl->get_dispid) {
|
2010-03-24 19:59:38 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-05 22:46:33 +02:00
|
|
|
hres = This->info->desc->vtbl->get_dispid(This, name, grfdex, ret);
|
2010-03-24 19:59:38 +01:00
|
|
|
if(hres != DISP_E_UNKNOWNNAME)
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2012-03-13 11:47:10 +01:00
|
|
|
static HRESULT change_type(VARIANT *dst, VARIANT *src, VARTYPE vt, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
V_VT(dst) = VT_EMPTY;
|
|
|
|
|
|
|
|
if(caller) {
|
|
|
|
IVariantChangeType *change_type = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IServiceProvider_QueryService(caller, &SID_VariantConversion, &IID_IVariantChangeType, (void**)&change_type);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IVariantChangeType_ChangeType(change_type, dst, src, LOCALE_NEUTRAL, vt);
|
|
|
|
IVariantChangeType_Release(change_type);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 14:10:33 +02:00
|
|
|
switch(vt) {
|
|
|
|
case VT_BOOL:
|
|
|
|
if(V_VT(src) == VT_BSTR) {
|
|
|
|
V_VT(dst) = VT_BOOL;
|
2017-11-02 16:48:02 +01:00
|
|
|
V_BOOL(dst) = variant_bool(V_BSTR(src) && *V_BSTR(src));
|
2012-09-24 14:10:33 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-13 11:47:10 +01:00
|
|
|
return VariantChangeType(dst, src, 0, vt);
|
|
|
|
}
|
|
|
|
|
2012-03-13 11:46:42 +01:00
|
|
|
static HRESULT builtin_propget(DispatchEx *This, func_info_t *func, DISPPARAMS *dp, VARIANT *res)
|
|
|
|
{
|
|
|
|
IUnknown *iface;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2012-07-13 14:46:41 +02:00
|
|
|
if(dp && dp->cArgs) {
|
2012-03-13 11:46:42 +01:00
|
|
|
FIXME("cArgs %d\n", dp->cArgs);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(func->get_vtbl_off);
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(This->outer, tid_ids[func->tid], (void**)&iface);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
switch(func->prop_vt) {
|
|
|
|
#define CASE_VT(vt,type,access) \
|
|
|
|
case vt: { \
|
|
|
|
type val; \
|
|
|
|
hres = ((HRESULT (WINAPI*)(IUnknown*,type*))((void**)iface->lpVtbl)[func->get_vtbl_off])(iface,&val); \
|
|
|
|
if(SUCCEEDED(hres)) \
|
|
|
|
access(res) = val; \
|
|
|
|
} \
|
|
|
|
break
|
|
|
|
BUILTIN_TYPES_SWITCH;
|
|
|
|
#undef CASE_VT
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled vt %d\n", func->prop_vt);
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
IUnknown_Release(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-16 18:26:47 +01:00
|
|
|
if(func->prop_vt != VT_VARIANT)
|
|
|
|
V_VT(res) = func->prop_vt == VT_PTR ? VT_DISPATCH : func->prop_vt;
|
2012-03-13 11:46:42 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-13 11:47:10 +01:00
|
|
|
static HRESULT builtin_propput(DispatchEx *This, func_info_t *func, DISPPARAMS *dp, IServiceProvider *caller)
|
2012-03-13 11:46:55 +01:00
|
|
|
{
|
|
|
|
VARIANT *v, tmpv;
|
|
|
|
IUnknown *iface;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(dp->cArgs != 1 || (dp->cNamedArgs == 1 && *dp->rgdispidNamedArgs != DISPID_PROPERTYPUT)
|
|
|
|
|| dp->cNamedArgs > 1) {
|
|
|
|
FIXME("invalid args\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!func->put_vtbl_off) {
|
|
|
|
FIXME("No setter\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = dp->rgvarg;
|
|
|
|
if(func->prop_vt != VT_VARIANT && V_VT(v) != func->prop_vt) {
|
2012-03-13 11:47:10 +01:00
|
|
|
hres = change_type(&tmpv, v, func->prop_vt, caller);
|
2012-03-13 11:46:55 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
v = &tmpv;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(This->outer, tid_ids[func->tid], (void**)&iface);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
switch(func->prop_vt) {
|
|
|
|
#define CASE_VT(vt,type,access) \
|
|
|
|
case vt: \
|
|
|
|
hres = ((HRESULT (WINAPI*)(IUnknown*,type))((void**)iface->lpVtbl)[func->put_vtbl_off])(iface,access(v)); \
|
|
|
|
break
|
|
|
|
BUILTIN_TYPES_SWITCH;
|
|
|
|
#undef CASE_VT
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented vt %d\n", func->prop_vt);
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_Release(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(v == &tmpv)
|
|
|
|
VariantClear(v);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-12-04 15:06:37 +01:00
|
|
|
static HRESULT invoke_builtin_function(DispatchEx *This, func_info_t *func, DISPPARAMS *dp, VARIANT *res, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
VARIANT arg_buf[MAX_ARGS], *arg_ptrs[MAX_ARGS], *arg, retv, ret_ref, vhres;
|
|
|
|
unsigned i, nconv = 0;
|
|
|
|
IUnknown *iface;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(dp->cNamedArgs) {
|
|
|
|
FIXME("Named arguments not supported\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dp->cArgs != func->argc) {
|
|
|
|
FIXME("Invalid argument count (expected %u, got %u)\n", func->argc, dp->cArgs);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(This->outer, tid_ids[func->tid], (void**)&iface);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
for(i=0; i < func->argc; i++) {
|
|
|
|
arg = dp->rgvarg+dp->cArgs-i-1;
|
|
|
|
if(func->arg_types[i] == V_VT(arg)) {
|
|
|
|
arg_ptrs[i] = arg;
|
|
|
|
}else {
|
|
|
|
hres = change_type(arg_buf+nconv, arg, func->arg_types[i], caller);
|
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
|
|
|
arg_ptrs[i] = arg_buf + nconv++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
if(func->prop_vt == VT_VOID) {
|
|
|
|
V_VT(&retv) = VT_EMPTY;
|
|
|
|
}else {
|
|
|
|
V_VT(&retv) = func->prop_vt;
|
|
|
|
arg_ptrs[func->argc] = &ret_ref;
|
|
|
|
V_VT(&ret_ref) = VT_BYREF|func->prop_vt;
|
|
|
|
|
|
|
|
switch(func->prop_vt) {
|
|
|
|
#define CASE_VT(vt,type,access) \
|
|
|
|
case vt: \
|
|
|
|
V_BYREF(&ret_ref) = &access(&retv); \
|
|
|
|
break
|
|
|
|
BUILTIN_TYPES_SWITCH;
|
|
|
|
#undef CASE_VT
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(&vhres) = VT_ERROR;
|
2013-02-12 14:36:48 +01:00
|
|
|
hres = DispCallFunc(iface, func->call_vtbl_off*sizeof(void*), CC_STDCALL, VT_ERROR,
|
2012-12-04 15:06:37 +01:00
|
|
|
func->argc + (func->prop_vt == VT_VOID ? 0 : 1), func->arg_types, arg_ptrs, &vhres);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(nconv--)
|
|
|
|
VariantClear(arg_buf+nconv);
|
|
|
|
IUnknown_Release(iface);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(FAILED(V_ERROR(&vhres)))
|
|
|
|
return V_ERROR(&vhres);
|
|
|
|
|
|
|
|
if(res)
|
|
|
|
*res = retv;
|
|
|
|
else
|
|
|
|
VariantClear(&retv);
|
|
|
|
return V_ERROR(&vhres);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT function_invoke(DispatchEx *This, func_info_t *func, WORD flags, DISPPARAMS *dp, VARIANT *res,
|
|
|
|
EXCEPINFO *ei, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
|
|
|
|
if(!res)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
/* fall through */
|
|
|
|
case DISPATCH_METHOD:
|
|
|
|
if(This->dynamic_data && This->dynamic_data->func_disps
|
|
|
|
&& This->dynamic_data->func_disps[func->func_disp_idx].func_obj) {
|
|
|
|
func_obj_entry_t *entry = This->dynamic_data->func_disps + func->func_disp_idx;
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
if(V_VT(&entry->val) != VT_DISPATCH) {
|
|
|
|
FIXME("calling %s not supported\n", debugstr_variant(&entry->val));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((IDispatch*)&entry->func_obj->dispex.IDispatchEx_iface != V_DISPATCH(&entry->val)) {
|
|
|
|
if(!V_DISPATCH(&entry->val)) {
|
2012-12-04 15:06:37 +01:00
|
|
|
FIXME("Calling null\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
hres = invoke_disp_value(This, V_DISPATCH(&entry->val), 0, flags, dp, res, ei, NULL);
|
2012-12-04 15:06:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(func->call_vtbl_off)
|
|
|
|
hres = invoke_builtin_function(This, func, dp, res, caller);
|
|
|
|
else
|
|
|
|
hres = typeinfo_invoke(This, func, flags, dp, res, ei);
|
|
|
|
break;
|
|
|
|
case DISPATCH_PROPERTYGET: {
|
|
|
|
func_obj_entry_t *entry;
|
|
|
|
|
|
|
|
if(func->id == DISPID_VALUE) {
|
|
|
|
BSTR ret;
|
|
|
|
|
|
|
|
ret = SysAllocString(objectW);
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
V_VT(res) = VT_BSTR;
|
|
|
|
V_BSTR(res) = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = get_func_obj_entry(This, func, &entry);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
V_VT(res) = VT_EMPTY;
|
|
|
|
return VariantCopy(res, &entry->val);
|
2012-12-04 15:06:37 +01:00
|
|
|
}
|
|
|
|
case DISPATCH_PROPERTYPUT: {
|
|
|
|
func_obj_entry_t *entry;
|
|
|
|
|
|
|
|
if(dp->cArgs != 1 || (dp->cNamedArgs == 1 && *dp->rgdispidNamedArgs != DISPID_PROPERTYPUT)
|
|
|
|
|| dp->cNamedArgs > 1) {
|
|
|
|
FIXME("invalid args\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
/*
|
|
|
|
* NOTE: Although we have IDispatchEx tests showing, that it's not allowed to set
|
|
|
|
* function property using InvokeEx, it's possible to do that from jscript.
|
|
|
|
* Native probably uses some undocumented interface in this case, but it should
|
|
|
|
* be fine for us to allow IDispatchEx handle that.
|
|
|
|
*/
|
2012-12-04 15:06:37 +01:00
|
|
|
hres = get_func_obj_entry(This, func, &entry);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2014-11-28 16:18:53 +01:00
|
|
|
return VariantCopy(&entry->val, dp->rgvarg);
|
2012-12-04 15:06:37 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented flags %x\n", flags);
|
|
|
|
hres = E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-03-24 20:00:08 +01:00
|
|
|
static HRESULT invoke_builtin_prop(DispatchEx *This, DISPID id, LCID lcid, WORD flags, DISPPARAMS *dp,
|
|
|
|
VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
|
|
|
|
{
|
|
|
|
func_info_t *func;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-05 22:46:46 +02:00
|
|
|
hres = get_builtin_func(This->info, id, &func);
|
2010-03-24 20:00:08 +01:00
|
|
|
if(id == DISPID_VALUE && hres == DISP_E_UNKNOWNNAME)
|
|
|
|
return dispex_value(This, lcid, flags, dp, res, ei, caller);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2017-11-24 15:09:13 +01:00
|
|
|
if(func->hook) {
|
|
|
|
hres = func->hook(This, lcid, flags, dp, res, ei, caller);
|
|
|
|
if(hres != S_FALSE)
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-03-13 11:46:42 +01:00
|
|
|
if(func->func_disp_idx != -1)
|
2012-12-04 15:06:37 +01:00
|
|
|
return function_invoke(This, func, flags, dp, res, ei, caller);
|
2012-03-13 11:46:42 +01:00
|
|
|
|
|
|
|
switch(flags) {
|
2012-03-13 11:46:55 +01:00
|
|
|
case DISPATCH_PROPERTYPUT:
|
|
|
|
if(res)
|
|
|
|
V_VT(res) = VT_EMPTY;
|
2012-03-13 11:47:10 +01:00
|
|
|
hres = builtin_propput(This, func, dp, caller);
|
2012-03-13 11:46:55 +01:00
|
|
|
break;
|
2012-03-13 11:46:42 +01:00
|
|
|
case DISPATCH_PROPERTYGET:
|
|
|
|
hres = builtin_propget(This, func, dp, res);
|
|
|
|
break;
|
|
|
|
default:
|
2012-07-13 14:46:41 +02:00
|
|
|
if(!func->get_vtbl_off) {
|
|
|
|
hres = typeinfo_invoke(This, func, flags, dp, res, ei);
|
|
|
|
}else {
|
|
|
|
VARIANT v;
|
|
|
|
|
|
|
|
hres = builtin_propget(This, func, NULL, &v);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2013-04-01 11:50:29 +02:00
|
|
|
if(flags != (DISPATCH_PROPERTYGET|DISPATCH_METHOD) || dp->cArgs) {
|
2012-09-10 10:35:05 +02:00
|
|
|
if(V_VT(&v) != VT_DISPATCH) {
|
2014-09-17 18:33:47 +02:00
|
|
|
FIXME("Not a function %s flags %08x\n", debugstr_variant(&v), flags);
|
2012-09-10 10:35:05 +02:00
|
|
|
VariantClear(&v);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-08-13 11:03:13 +02:00
|
|
|
hres = invoke_disp_value(This, V_DISPATCH(&v), lcid, flags, dp, res, ei, caller);
|
|
|
|
IDispatch_Release(V_DISPATCH(&v));
|
|
|
|
}else if(res) {
|
|
|
|
*res = v;
|
|
|
|
}else {
|
2013-04-01 11:50:29 +02:00
|
|
|
VariantClear(&v);
|
2012-08-13 11:03:13 +02:00
|
|
|
}
|
2012-07-13 14:46:41 +02:00
|
|
|
}
|
2012-03-13 11:46:42 +01:00
|
|
|
}
|
2010-03-24 20:00:08 +01:00
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2014-11-28 16:19:04 +01:00
|
|
|
HRESULT remove_attribute(DispatchEx *This, DISPID id, VARIANT_BOOL *success)
|
2010-03-24 20:34:17 +01:00
|
|
|
{
|
2014-11-28 16:19:04 +01:00
|
|
|
switch(get_dispid_type(id)) {
|
|
|
|
case DISPEXPROP_CUSTOM:
|
|
|
|
FIXME("DISPEXPROP_CUSTOM not supported\n");
|
|
|
|
return E_NOTIMPL;
|
2010-03-24 20:34:17 +01:00
|
|
|
|
2014-11-28 16:19:04 +01:00
|
|
|
case DISPEXPROP_DYNAMIC: {
|
|
|
|
DWORD idx = id - DISPID_DYNPROP_0;
|
|
|
|
dynamic_prop_t *prop;
|
|
|
|
|
|
|
|
prop = This->dynamic_data->props+idx;
|
|
|
|
VariantClear(&prop->var);
|
|
|
|
prop->flags |= DYNPROP_DELETED;
|
|
|
|
*success = VARIANT_TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case DISPEXPROP_BUILTIN: {
|
2010-03-24 20:34:17 +01:00
|
|
|
VARIANT var;
|
2014-11-28 16:19:04 +01:00
|
|
|
DISPPARAMS dp = {&var,NULL,1,0};
|
|
|
|
func_info_t *func;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2016-07-05 22:46:46 +02:00
|
|
|
hres = get_builtin_func(This->info, id, &func);
|
2014-11-28 16:19:04 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
/* For builtin functions, we set their value to the original function. */
|
|
|
|
if(func->func_disp_idx != -1) {
|
|
|
|
func_obj_entry_t *entry;
|
|
|
|
|
|
|
|
if(!This->dynamic_data || !This->dynamic_data->func_disps
|
|
|
|
|| !This->dynamic_data->func_disps[func->func_disp_idx].func_obj) {
|
|
|
|
*success = VARIANT_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = This->dynamic_data->func_disps + func->func_disp_idx;
|
|
|
|
if(V_VT(&entry->val) == VT_DISPATCH
|
|
|
|
&& V_DISPATCH(&entry->val) == (IDispatch*)&entry->func_obj->dispex.IDispatchEx_iface) {
|
|
|
|
*success = VARIANT_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantClear(&entry->val);
|
|
|
|
V_VT(&entry->val) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&entry->val) = (IDispatch*)&entry->func_obj->dispex.IDispatchEx_iface;
|
|
|
|
IDispatch_AddRef(V_DISPATCH(&entry->val));
|
|
|
|
*success = VARIANT_TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2010-03-24 20:34:17 +01:00
|
|
|
|
|
|
|
V_VT(&var) = VT_EMPTY;
|
2014-11-28 16:19:04 +01:00
|
|
|
hres = builtin_propput(This, func, &dp, NULL);
|
2010-03-24 20:34:17 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*success = VARIANT_TRUE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2014-11-28 16:19:04 +01:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return E_FAIL;
|
2010-03-24 20:34:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 23:25:55 +02:00
|
|
|
compat_mode_t dispex_compat_mode(DispatchEx *dispex)
|
|
|
|
{
|
2018-02-08 20:53:21 +01:00
|
|
|
return dispex->info != dispex->info->desc->delayed_init_info
|
|
|
|
? dispex->info->compat_mode
|
|
|
|
: dispex->info->desc->vtbl->get_compat_mode(dispex);
|
2017-09-21 23:25:55 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 21:35:57 +02:00
|
|
|
static dispex_data_t *ensure_dispex_info(dispex_static_data_t *desc, compat_mode_t compat_mode)
|
|
|
|
{
|
|
|
|
if(!desc->info_cache[compat_mode]) {
|
|
|
|
EnterCriticalSection(&cs_dispex_static_data);
|
|
|
|
if(!desc->info_cache[compat_mode])
|
|
|
|
desc->info_cache[compat_mode] = preprocess_dispex_data(desc, compat_mode);
|
|
|
|
LeaveCriticalSection(&cs_dispex_static_data);
|
|
|
|
}
|
|
|
|
return desc->info_cache[compat_mode];
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL ensure_real_info(DispatchEx *dispex)
|
|
|
|
{
|
|
|
|
if(dispex->info != dispex->info->desc->delayed_init_info)
|
|
|
|
return TRUE;
|
|
|
|
|
2017-09-21 23:25:55 +02:00
|
|
|
dispex->info = ensure_dispex_info(dispex->info->desc, dispex_compat_mode(dispex));
|
2017-08-21 21:35:57 +02:00
|
|
|
return dispex->info != NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-31 11:07:33 +01:00
|
|
|
static inline DispatchEx *impl_from_IDispatchEx(IDispatchEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, DispatchEx, IDispatchEx_iface);
|
|
|
|
}
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
return IUnknown_QueryInterface(This->outer, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
return IUnknown_AddRef(This->outer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
return IUnknown_Release(This->outer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-17 02:31:43 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
|
|
|
|
LCID lcid, ITypeInfo **ppTInfo)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-19 12:55:24 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
|
|
|
|
|
2016-07-05 22:46:33 +02:00
|
|
|
hres = get_typeinfo(This->info->desc->disp_tid, ppTInfo);
|
2008-04-19 12:55:24 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
ITypeInfo_AddRef(*ppTInfo);
|
|
|
|
return S_OK;
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
|
|
|
|
LPOLESTR *rgszNames, UINT cNames,
|
|
|
|
LCID lcid, DISPID *rgDispId)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-18 22:00:22 +02:00
|
|
|
UINT i;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
|
2008-04-17 02:31:43 +02:00
|
|
|
lcid, rgDispId);
|
2008-04-18 22:00:22 +02:00
|
|
|
|
|
|
|
for(i=0; i < cNames; i++) {
|
2010-12-31 11:07:33 +01:00
|
|
|
hres = IDispatchEx_GetDispID(&This->IDispatchEx_iface, rgszNames[i], 0, rgDispId+i);
|
2008-04-18 22:00:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
|
|
|
|
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
|
|
|
|
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-18 22:00:00 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
2008-04-17 02:31:43 +02:00
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2008-04-18 22:00:00 +02:00
|
|
|
|
2010-12-31 11:07:33 +01:00
|
|
|
return IDispatchEx_InvokeEx(&This->IDispatchEx_iface, dispIdMember, lcid, wFlags, pDispParams,
|
|
|
|
pVarResult, pExcepInfo, NULL);
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-10-09 22:30:51 +02:00
|
|
|
dynamic_prop_t *dprop;
|
|
|
|
HRESULT hres;
|
2008-04-19 12:55:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
|
|
|
|
|
2009-11-01 19:20:53 +01:00
|
|
|
if(grfdex & ~(fdexNameCaseSensitive|fdexNameCaseInsensitive|fdexNameEnsure|fdexNameImplicit|FDEX_VERSION_MASK))
|
2008-04-19 12:55:24 +02:00
|
|
|
FIXME("Unsupported grfdex %x\n", grfdex);
|
|
|
|
|
2017-08-21 21:35:57 +02:00
|
|
|
if(!ensure_real_info(This))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-03-24 19:59:38 +01:00
|
|
|
hres = get_builtin_id(This, bstrName, grfdex, pid);
|
|
|
|
if(hres != DISP_E_UNKNOWNNAME)
|
|
|
|
return hres;
|
2008-04-29 01:38:09 +02:00
|
|
|
|
2009-11-01 19:20:53 +01:00
|
|
|
hres = get_dynamic_prop(This, bstrName, grfdex, &dprop);
|
2008-10-09 22:30:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2008-06-18 00:10:26 +02:00
|
|
|
|
2008-10-09 22:30:51 +02:00
|
|
|
*pid = DISPID_DYNPROP_0 + (dprop - This->dynamic_data->props);
|
|
|
|
return S_OK;
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
|
|
|
|
VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-18 21:59:46 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
|
|
|
|
2017-08-21 21:35:57 +02:00
|
|
|
if(!ensure_real_info(This))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2014-11-28 16:18:18 +01:00
|
|
|
if(wFlags == (DISPATCH_PROPERTYPUT|DISPATCH_PROPERTYPUTREF))
|
|
|
|
wFlags = DISPATCH_PROPERTYPUT;
|
|
|
|
|
2012-07-24 15:56:05 +02:00
|
|
|
switch(get_dispid_type(id)) {
|
|
|
|
case DISPEXPROP_CUSTOM:
|
2016-07-05 22:46:33 +02:00
|
|
|
if(!This->info->desc->vtbl || !This->info->desc->vtbl->invoke)
|
2012-07-24 15:56:05 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
2016-07-05 22:46:33 +02:00
|
|
|
return This->info->desc->vtbl->invoke(This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
2008-04-29 01:38:09 +02:00
|
|
|
|
2012-07-24 15:56:05 +02:00
|
|
|
case DISPEXPROP_DYNAMIC: {
|
2008-06-18 00:10:26 +02:00
|
|
|
DWORD idx = id - DISPID_DYNPROP_0;
|
2010-03-24 20:34:17 +01:00
|
|
|
dynamic_prop_t *prop;
|
2008-06-18 00:10:26 +02:00
|
|
|
|
2011-08-23 11:33:28 +02:00
|
|
|
if(!get_dynamic_data(This) || This->dynamic_data->prop_cnt <= idx)
|
2008-06-18 00:10:26 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
2010-03-24 20:34:17 +01:00
|
|
|
prop = This->dynamic_data->props+idx;
|
2008-06-18 00:10:26 +02:00
|
|
|
|
|
|
|
switch(wFlags) {
|
2009-10-13 20:50:28 +02:00
|
|
|
case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
|
|
|
|
if(!pvarRes)
|
|
|
|
return E_INVALIDARG;
|
2011-10-04 23:48:41 +02:00
|
|
|
/* fall through */
|
2012-07-13 14:46:26 +02:00
|
|
|
case DISPATCH_METHOD:
|
2010-03-24 20:34:17 +01:00
|
|
|
if(V_VT(&prop->var) != VT_DISPATCH) {
|
|
|
|
FIXME("invoke %s\n", debugstr_variant(&prop->var));
|
2008-10-06 16:53:01 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:46:26 +02:00
|
|
|
return invoke_disp_value(This, V_DISPATCH(&prop->var), lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
2009-10-13 20:50:02 +02:00
|
|
|
case DISPATCH_PROPERTYGET:
|
2010-03-24 20:34:17 +01:00
|
|
|
if(prop->flags & DYNPROP_DELETED)
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
2011-12-12 14:49:33 +01:00
|
|
|
V_VT(pvarRes) = VT_EMPTY;
|
2011-03-02 13:34:58 +01:00
|
|
|
return variant_copy(pvarRes, &prop->var);
|
2009-10-13 20:50:02 +02:00
|
|
|
case DISPATCH_PROPERTYPUT:
|
2009-11-01 19:20:28 +01:00
|
|
|
if(pdp->cArgs != 1 || (pdp->cNamedArgs == 1 && *pdp->rgdispidNamedArgs != DISPID_PROPERTYPUT)
|
|
|
|
|| pdp->cNamedArgs > 1) {
|
|
|
|
FIXME("invalid args\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("put %s\n", debugstr_variant(pdp->rgvarg));
|
2010-03-24 20:34:17 +01:00
|
|
|
VariantClear(&prop->var);
|
2011-03-02 13:34:58 +01:00
|
|
|
hres = variant_copy(&prop->var, pdp->rgvarg);
|
2010-03-24 20:34:17 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
prop->flags &= ~DYNPROP_DELETED;
|
|
|
|
return S_OK;
|
2008-06-18 00:10:26 +02:00
|
|
|
default:
|
|
|
|
FIXME("unhandled wFlags %x\n", wFlags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
}
|
2012-07-24 15:56:05 +02:00
|
|
|
case DISPEXPROP_BUILTIN:
|
|
|
|
if(wFlags == DISPATCH_CONSTRUCT) {
|
|
|
|
if(id == DISPID_VALUE) {
|
2016-07-05 22:46:33 +02:00
|
|
|
if(This->info->desc->vtbl && This->info->desc->vtbl->value) {
|
|
|
|
return This->info->desc->vtbl->value(This, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
2012-07-24 15:56:05 +02:00
|
|
|
}
|
|
|
|
FIXME("DISPATCH_CONSTRUCT flag but missing value function\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
FIXME("DISPATCH_CONSTRUCT flag without DISPID_VALUE\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-06-18 00:10:26 +02:00
|
|
|
|
2012-07-24 15:56:05 +02:00
|
|
|
return invoke_builtin_prop(This, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2010-02-11 01:20:26 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s %x)\n", This, debugstr_w(bstrName), grfdex);
|
|
|
|
|
|
|
|
/* Not implemented by IE */
|
2008-04-17 02:31:43 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2011-08-23 11:33:10 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%x)\n", This, id);
|
|
|
|
|
|
|
|
/* Not implemented by IE */
|
2008-04-17 02:31:43 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-17 02:31:43 +02:00
|
|
|
FIXME("(%p)->(%x %x %p)\n", This, id, grfdexFetch, pgrfdex);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2009-09-06 18:52:49 +02:00
|
|
|
func_info_t *func;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %p)\n", This, id, pbstrName);
|
|
|
|
|
2017-08-21 21:35:57 +02:00
|
|
|
if(!ensure_real_info(This))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-09-06 18:52:49 +02:00
|
|
|
if(is_dynamic_dispid(id)) {
|
|
|
|
DWORD idx = id - DISPID_DYNPROP_0;
|
|
|
|
|
2011-08-23 11:33:28 +02:00
|
|
|
if(!get_dynamic_data(This) || This->dynamic_data->prop_cnt <= idx)
|
2009-09-06 18:52:49 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
|
|
|
*pbstrName = SysAllocString(This->dynamic_data->props[idx].name);
|
|
|
|
if(!*pbstrName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-05 22:46:46 +02:00
|
|
|
hres = get_builtin_func(This->info, id, &func);
|
2009-09-06 18:52:49 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
*pbstrName = SysAllocString(func->name);
|
|
|
|
if(!*pbstrName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
return S_OK;
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
2016-05-04 15:21:49 +02:00
|
|
|
static HRESULT next_dynamic_id(DispatchEx *dispex, DWORD idx, DISPID *ret_id)
|
|
|
|
{
|
|
|
|
while(idx < dispex->dynamic_data->prop_cnt && dispex->dynamic_data->props[idx].flags & DYNPROP_DELETED)
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
if(idx == dispex->dynamic_data->prop_cnt) {
|
|
|
|
*ret_id = DISPID_STARTENUM;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret_id = DISPID_DYNPROP_0+idx;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-17 02:31:43 +02:00
|
|
|
static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2009-09-06 18:52:21 +02:00
|
|
|
func_info_t *func;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %x %p)\n", This, grfdex, id, pid);
|
|
|
|
|
2017-08-21 21:35:57 +02:00
|
|
|
if(!ensure_real_info(This))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-09-06 18:52:21 +02:00
|
|
|
if(is_dynamic_dispid(id)) {
|
|
|
|
DWORD idx = id - DISPID_DYNPROP_0;
|
|
|
|
|
2011-08-23 11:33:28 +02:00
|
|
|
if(!get_dynamic_data(This) || This->dynamic_data->prop_cnt <= idx)
|
2009-09-06 18:52:21 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
2016-05-04 15:21:49 +02:00
|
|
|
return next_dynamic_id(This, idx+1, pid);
|
2009-09-06 18:52:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(id == DISPID_STARTENUM) {
|
2016-07-05 22:46:46 +02:00
|
|
|
func = This->info->funcs;
|
2009-09-06 18:52:21 +02:00
|
|
|
}else {
|
2016-07-05 22:46:46 +02:00
|
|
|
hres = get_builtin_func(This->info, id, &func);
|
2009-09-06 18:52:21 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
func++;
|
|
|
|
}
|
|
|
|
|
2016-07-05 22:46:46 +02:00
|
|
|
while(func < This->info->funcs + This->info->func_cnt) {
|
2009-09-06 18:52:21 +02:00
|
|
|
/* FIXME: Skip hidden properties */
|
|
|
|
if(func->func_disp_idx == -1) {
|
|
|
|
*pid = func->id;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
func++;
|
|
|
|
}
|
|
|
|
|
2016-05-04 15:21:49 +02:00
|
|
|
if(get_dynamic_data(This) && This->dynamic_data->prop_cnt)
|
|
|
|
return next_dynamic_id(This, 0, pid);
|
2009-09-06 18:52:21 +02:00
|
|
|
|
|
|
|
*pid = DISPID_STARTENUM;
|
|
|
|
return S_FALSE;
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
|
|
|
|
{
|
2010-12-31 11:07:33 +01:00
|
|
|
DispatchEx *This = impl_from_IDispatchEx(iface);
|
2008-04-17 02:31:43 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2008-06-30 21:38:23 +02:00
|
|
|
BOOL dispex_query_interface(DispatchEx *This, REFIID riid, void **ppv)
|
|
|
|
{
|
2015-01-20 16:24:27 +01:00
|
|
|
if(IsEqualGUID(&IID_IDispatch, riid))
|
2010-12-31 11:07:33 +01:00
|
|
|
*ppv = &This->IDispatchEx_iface;
|
2015-01-20 16:24:27 +01:00
|
|
|
else if(IsEqualGUID(&IID_IDispatchEx, riid))
|
2010-12-31 11:07:33 +01:00
|
|
|
*ppv = &This->IDispatchEx_iface;
|
2015-01-20 16:24:27 +01:00
|
|
|
else if(IsEqualGUID(&IID_IDispatchJS, riid))
|
2008-09-30 17:46:30 +02:00
|
|
|
*ppv = NULL;
|
2015-01-20 16:24:27 +01:00
|
|
|
else if(IsEqualGUID(&IID_UndocumentedScriptIface, riid))
|
2008-06-30 21:38:55 +02:00
|
|
|
*ppv = NULL;
|
2017-04-13 16:04:41 +02:00
|
|
|
else if(IsEqualGUID(&IID_IMarshal, riid))
|
|
|
|
*ppv = NULL;
|
|
|
|
else if(IsEqualGUID(&IID_IManagedObject, riid))
|
|
|
|
*ppv = NULL;
|
2015-01-20 16:24:27 +01:00
|
|
|
else
|
2008-06-30 21:38:23 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if(*ppv)
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-07-19 11:28:54 +02:00
|
|
|
void dispex_traverse(DispatchEx *This, nsCycleCollectionTraversalCallback *cb)
|
|
|
|
{
|
|
|
|
dynamic_prop_t *prop;
|
|
|
|
|
|
|
|
if(!This->dynamic_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(prop = This->dynamic_data->props; prop < This->dynamic_data->props + This->dynamic_data->prop_cnt; prop++) {
|
|
|
|
if(V_VT(&prop->var) == VT_DISPATCH)
|
|
|
|
note_cc_edge((nsISupports*)V_DISPATCH(&prop->var), "dispex_data", cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Traverse func_disps */
|
|
|
|
}
|
|
|
|
|
|
|
|
void dispex_unlink(DispatchEx *This)
|
|
|
|
{
|
|
|
|
dynamic_prop_t *prop;
|
|
|
|
|
|
|
|
if(!This->dynamic_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(prop = This->dynamic_data->props; prop < This->dynamic_data->props + This->dynamic_data->prop_cnt; prop++) {
|
|
|
|
if(V_VT(&prop->var) == VT_DISPATCH) {
|
|
|
|
V_VT(&prop->var) = VT_EMPTY;
|
|
|
|
IDispatch_Release(V_DISPATCH(&prop->var));
|
|
|
|
}else {
|
|
|
|
VariantClear(&prop->var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-18 16:38:51 +02:00
|
|
|
const void *dispex_get_vtbl(DispatchEx *dispex)
|
2016-07-05 22:46:01 +02:00
|
|
|
{
|
2016-07-05 22:46:33 +02:00
|
|
|
return dispex->info->desc->vtbl;
|
2016-07-05 22:46:01 +02:00
|
|
|
}
|
|
|
|
|
2009-08-31 20:47:55 +02:00
|
|
|
void release_dispex(DispatchEx *This)
|
|
|
|
{
|
|
|
|
dynamic_prop_t *prop;
|
|
|
|
|
|
|
|
if(!This->dynamic_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(prop = This->dynamic_data->props; prop < This->dynamic_data->props + This->dynamic_data->prop_cnt; prop++) {
|
|
|
|
VariantClear(&prop->var);
|
|
|
|
heap_free(prop->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(This->dynamic_data->props);
|
|
|
|
|
|
|
|
if(This->dynamic_data->func_disps) {
|
2012-09-24 14:10:05 +02:00
|
|
|
func_obj_entry_t *iter;
|
2009-08-31 20:47:55 +02:00
|
|
|
|
2016-07-05 22:46:33 +02:00
|
|
|
for(iter = This->dynamic_data->func_disps; iter < This->dynamic_data->func_disps + This->info->func_disp_cnt; iter++) {
|
2012-09-24 14:10:05 +02:00
|
|
|
if(iter->func_obj) {
|
|
|
|
iter->func_obj->obj = NULL;
|
|
|
|
IDispatchEx_Release(&iter->func_obj->dispex.IDispatchEx_iface);
|
2009-08-31 20:47:55 +02:00
|
|
|
}
|
2014-11-28 16:18:53 +01:00
|
|
|
VariantClear(&iter->val);
|
2009-08-31 20:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(This->dynamic_data->func_disps);
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(This->dynamic_data);
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:49:45 +02:00
|
|
|
void init_dispex_with_compat_mode(DispatchEx *dispex, IUnknown *outer, dispex_static_data_t *data, compat_mode_t compat_mode)
|
2008-04-17 02:31:43 +02:00
|
|
|
{
|
2016-07-07 12:49:45 +02:00
|
|
|
assert(compat_mode < COMPAT_MODE_CNT);
|
|
|
|
|
2010-12-31 11:07:33 +01:00
|
|
|
dispex->IDispatchEx_iface.lpVtbl = &DispatchExVtbl;
|
2008-04-17 02:31:43 +02:00
|
|
|
dispex->outer = outer;
|
2009-08-31 20:47:55 +02:00
|
|
|
dispex->dynamic_data = NULL;
|
2017-08-21 21:35:57 +02:00
|
|
|
|
|
|
|
if(data->vtbl && data->vtbl->get_compat_mode) {
|
|
|
|
/* delayed init */
|
|
|
|
if(!data->delayed_init_info) {
|
|
|
|
EnterCriticalSection(&cs_dispex_static_data);
|
|
|
|
if(!data->delayed_init_info) {
|
|
|
|
dispex_data_t *info = heap_alloc_zero(sizeof(*data->delayed_init_info));
|
|
|
|
if(info) {
|
|
|
|
info->desc = data;
|
|
|
|
data->delayed_init_info = info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&cs_dispex_static_data);
|
|
|
|
}
|
|
|
|
dispex->info = data->delayed_init_info;
|
|
|
|
}else {
|
|
|
|
dispex->info = ensure_dispex_info(data, compat_mode);
|
|
|
|
}
|
2008-04-17 02:31:43 +02:00
|
|
|
}
|