2008-03-16 20:10:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2008-08-31 23:23:38 +00:00
|
|
|
#include "dispex.h"
|
2008-08-31 23:23:16 +00:00
|
|
|
#include "activscp.h"
|
|
|
|
|
2009-07-20 16:18:00 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2008-09-02 22:25:21 +00:00
|
|
|
#include "wine/unicode.h"
|
2008-09-02 22:26:10 +00:00
|
|
|
#include "wine/list.h"
|
2008-09-02 22:25:21 +00:00
|
|
|
|
2009-07-24 07:35:56 +00:00
|
|
|
#define JSCRIPT_ERROR 0x800A0000
|
|
|
|
|
2008-08-31 23:23:16 +00:00
|
|
|
typedef struct _script_ctx_t script_ctx_t;
|
2008-09-05 00:37:59 +00:00
|
|
|
typedef struct _exec_ctx_t exec_ctx_t;
|
2008-09-07 22:14:38 +00:00
|
|
|
typedef struct _dispex_prop_t dispex_prop_t;
|
2008-09-05 00:37:59 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
EXCEPINFO ei;
|
|
|
|
VARIANT var;
|
|
|
|
} jsexcept_t;
|
2008-08-31 23:23:16 +00:00
|
|
|
|
2008-09-15 18:38:46 +00:00
|
|
|
typedef struct {
|
|
|
|
void **blocks;
|
|
|
|
DWORD block_cnt;
|
|
|
|
DWORD last_block;
|
|
|
|
DWORD offset;
|
|
|
|
BOOL mark;
|
|
|
|
struct list custom_blocks;
|
|
|
|
} jsheap_t;
|
|
|
|
|
|
|
|
void jsheap_init(jsheap_t*);
|
|
|
|
void *jsheap_alloc(jsheap_t*,DWORD);
|
|
|
|
void *jsheap_grow(jsheap_t*,void*,DWORD,DWORD);
|
|
|
|
void jsheap_clear(jsheap_t*);
|
|
|
|
void jsheap_free(jsheap_t*);
|
|
|
|
jsheap_t *jsheap_mark(jsheap_t*);
|
|
|
|
|
2008-09-07 22:14:38 +00:00
|
|
|
typedef struct DispatchEx DispatchEx;
|
|
|
|
|
2009-07-20 16:18:00 +00:00
|
|
|
extern HINSTANCE jscript_hinstance;
|
|
|
|
|
2008-09-07 22:14:38 +00:00
|
|
|
#define PROPF_ARGMASK 0x00ff
|
|
|
|
#define PROPF_METHOD 0x0100
|
|
|
|
#define PROPF_ENUM 0x0200
|
|
|
|
#define PROPF_CONSTR 0x0400
|
|
|
|
|
|
|
|
typedef enum {
|
2008-09-08 23:22:54 +00:00
|
|
|
JSCLASS_NONE,
|
2008-09-10 00:33:57 +00:00
|
|
|
JSCLASS_ARRAY,
|
2008-09-10 00:34:16 +00:00
|
|
|
JSCLASS_BOOLEAN,
|
2008-09-30 15:48:18 +00:00
|
|
|
JSCLASS_DATE,
|
2009-07-15 23:16:15 +00:00
|
|
|
JSCLASS_ERROR,
|
2008-09-08 23:27:01 +00:00
|
|
|
JSCLASS_FUNCTION,
|
2008-09-10 00:33:15 +00:00
|
|
|
JSCLASS_GLOBAL,
|
2008-09-10 00:35:43 +00:00
|
|
|
JSCLASS_MATH,
|
2008-09-10 00:34:33 +00:00
|
|
|
JSCLASS_NUMBER,
|
2008-09-10 00:33:37 +00:00
|
|
|
JSCLASS_OBJECT,
|
2008-09-10 00:34:54 +00:00
|
|
|
JSCLASS_REGEXP,
|
2008-09-10 00:33:37 +00:00
|
|
|
JSCLASS_STRING
|
2008-09-07 22:14:38 +00:00
|
|
|
} jsclass_t;
|
|
|
|
|
|
|
|
typedef HRESULT (*builtin_invoke_t)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const WCHAR *name;
|
|
|
|
builtin_invoke_t invoke;
|
|
|
|
DWORD flags;
|
|
|
|
} builtin_prop_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
jsclass_t class;
|
|
|
|
builtin_prop_t value_prop;
|
|
|
|
DWORD props_cnt;
|
|
|
|
const builtin_prop_t *props;
|
|
|
|
void (*destructor)(DispatchEx*);
|
|
|
|
void (*on_put)(DispatchEx*,const WCHAR*);
|
|
|
|
} builtin_info_t;
|
|
|
|
|
|
|
|
struct DispatchEx {
|
2008-08-31 23:23:38 +00:00
|
|
|
const IDispatchExVtbl *lpIDispatchExVtbl;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
2008-09-07 22:14:38 +00:00
|
|
|
DWORD buf_size;
|
|
|
|
DWORD prop_cnt;
|
|
|
|
dispex_prop_t *props;
|
2008-08-31 23:23:38 +00:00
|
|
|
script_ctx_t *ctx;
|
2008-09-07 22:14:38 +00:00
|
|
|
|
|
|
|
DispatchEx *prototype;
|
|
|
|
|
|
|
|
const builtin_info_t *builtin_info;
|
|
|
|
};
|
2008-08-31 23:23:38 +00:00
|
|
|
|
|
|
|
#define _IDispatchEx_(x) ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
|
|
|
|
|
2008-09-10 00:33:15 +00:00
|
|
|
static inline void jsdisp_release(DispatchEx *jsdisp)
|
|
|
|
{
|
|
|
|
IDispatchEx_Release(_IDispatchEx_(jsdisp));
|
|
|
|
}
|
|
|
|
|
2008-09-07 22:14:38 +00:00
|
|
|
HRESULT create_dispex(script_ctx_t*,const builtin_info_t*,DispatchEx*,DispatchEx**);
|
2008-09-08 23:27:01 +00:00
|
|
|
HRESULT init_dispex(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
|
2008-09-10 00:33:15 +00:00
|
|
|
HRESULT init_dispex_from_constr(DispatchEx*,script_ctx_t*,const builtin_info_t*,DispatchEx*);
|
|
|
|
DispatchEx *iface_to_jsdisp(IUnknown*);
|
|
|
|
|
2008-09-08 23:20:26 +00:00
|
|
|
HRESULT disp_call(IDispatch*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-10 00:33:15 +00:00
|
|
|
HRESULT jsdisp_call_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2009-07-08 08:52:56 +00:00
|
|
|
HRESULT jsdisp_call(DispatchEx*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2009-08-12 10:48:58 +00:00
|
|
|
HRESULT jsdisp_call_name(DispatchEx*,const WCHAR*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-08 23:21:55 +00:00
|
|
|
HRESULT disp_propget(IDispatch*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-08 23:23:21 +00:00
|
|
|
HRESULT disp_propput(IDispatch*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-10-07 17:01:39 +00:00
|
|
|
HRESULT jsdisp_propget(DispatchEx*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-08 23:25:59 +00:00
|
|
|
HRESULT jsdisp_propput_name(DispatchEx*,const WCHAR*,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-10 19:06:43 +00:00
|
|
|
HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-10-20 20:12:42 +00:00
|
|
|
HRESULT jsdisp_propget_name(DispatchEx*,LPCWSTR,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-21 13:36:26 +00:00
|
|
|
HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
|
2008-09-30 15:47:24 +00:00
|
|
|
HRESULT jsdisp_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
|
2009-07-14 00:06:59 +00:00
|
|
|
HRESULT jsdisp_delete_idx(DispatchEx*,DWORD);
|
2008-09-08 23:27:01 +00:00
|
|
|
|
2009-07-03 00:45:12 +00:00
|
|
|
HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_info_t*,DWORD,
|
|
|
|
DispatchEx*,DispatchEx**);
|
|
|
|
HRESULT Function_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t*,IServiceProvider*);
|
|
|
|
|
2009-07-20 16:18:00 +00:00
|
|
|
HRESULT throw_eval_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
|
|
|
|
HRESULT throw_range_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
|
|
|
|
HRESULT throw_reference_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
|
|
|
|
HRESULT throw_syntax_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
|
|
|
|
HRESULT throw_type_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
|
|
|
|
HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
|
|
|
|
|
2008-08-31 23:23:38 +00:00
|
|
|
|
2008-09-10 19:08:09 +00:00
|
|
|
HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2008-09-10 00:35:43 +00:00
|
|
|
HRESULT create_math(script_ctx_t*,DispatchEx**);
|
2008-09-15 18:37:10 +00:00
|
|
|
HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**);
|
2008-09-15 18:38:18 +00:00
|
|
|
HRESULT create_regexp_str(script_ctx_t*,const WCHAR*,DWORD,const WCHAR*,DWORD,DispatchEx**);
|
2008-09-15 18:40:34 +00:00
|
|
|
HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,DispatchEx**);
|
2008-09-16 18:45:29 +00:00
|
|
|
HRESULT create_bool(script_ctx_t*,VARIANT_BOOL,DispatchEx**);
|
2008-09-16 18:45:45 +00:00
|
|
|
HRESULT create_number(script_ctx_t*,VARIANT*,DispatchEx**);
|
2008-09-10 00:35:43 +00:00
|
|
|
|
2009-07-08 08:52:56 +00:00
|
|
|
typedef enum {
|
|
|
|
NO_HINT,
|
|
|
|
HINT_STRING,
|
|
|
|
HINT_NUMBER
|
|
|
|
} hint_t;
|
|
|
|
|
|
|
|
HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*, hint_t);
|
2008-09-08 23:25:40 +00:00
|
|
|
HRESULT to_boolean(VARIANT*,VARIANT_BOOL*);
|
2008-09-10 19:12:45 +00:00
|
|
|
HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
|
2008-09-18 22:43:03 +00:00
|
|
|
HRESULT to_integer(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*);
|
2008-09-17 21:31:02 +00:00
|
|
|
HRESULT to_int32(script_ctx_t*,VARIANT*,jsexcept_t*,INT*);
|
2008-09-18 22:44:11 +00:00
|
|
|
HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*);
|
2008-09-10 19:07:06 +00:00
|
|
|
HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*);
|
2008-09-08 23:27:18 +00:00
|
|
|
HRESULT to_object(exec_ctx_t*,VARIANT*,IDispatch**);
|
2008-09-08 23:25:40 +00:00
|
|
|
|
2008-09-08 23:22:31 +00:00
|
|
|
typedef struct named_item_t {
|
|
|
|
IDispatch *disp;
|
|
|
|
DWORD flags;
|
2008-11-05 00:03:38 +00:00
|
|
|
LPWSTR name;
|
2008-09-08 23:22:31 +00:00
|
|
|
|
|
|
|
struct named_item_t *next;
|
|
|
|
} named_item_t;
|
|
|
|
|
2008-08-31 23:23:16 +00:00
|
|
|
struct _script_ctx_t {
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
SCRIPTSTATE state;
|
2008-09-05 00:37:59 +00:00
|
|
|
exec_ctx_t *exec_ctx;
|
2008-09-08 23:22:31 +00:00
|
|
|
named_item_t *named_items;
|
2008-12-15 21:24:33 +00:00
|
|
|
IActiveScriptSite *site;
|
2008-08-31 23:17:14 +00:00
|
|
|
LCID lcid;
|
2008-08-31 23:23:38 +00:00
|
|
|
|
2008-09-15 18:38:46 +00:00
|
|
|
jsheap_t tmp_heap;
|
|
|
|
|
2008-08-31 23:23:38 +00:00
|
|
|
DispatchEx *script_disp;
|
2008-09-08 23:22:54 +00:00
|
|
|
DispatchEx *global;
|
2008-09-18 22:46:26 +00:00
|
|
|
DispatchEx *function_constr;
|
2008-09-10 00:33:57 +00:00
|
|
|
DispatchEx *array_constr;
|
2008-09-10 00:34:16 +00:00
|
|
|
DispatchEx *bool_constr;
|
2008-09-30 15:48:18 +00:00
|
|
|
DispatchEx *date_constr;
|
2009-07-20 16:17:51 +00:00
|
|
|
DispatchEx *error_constr;
|
|
|
|
DispatchEx *eval_error_constr;
|
|
|
|
DispatchEx *range_error_constr;
|
|
|
|
DispatchEx *reference_error_constr;
|
|
|
|
DispatchEx *syntax_error_constr;
|
|
|
|
DispatchEx *type_error_constr;
|
|
|
|
DispatchEx *uri_error_constr;
|
2008-09-10 00:34:33 +00:00
|
|
|
DispatchEx *number_constr;
|
2008-09-10 00:33:15 +00:00
|
|
|
DispatchEx *object_constr;
|
2008-09-10 00:34:54 +00:00
|
|
|
DispatchEx *regexp_constr;
|
2008-09-10 00:33:37 +00:00
|
|
|
DispatchEx *string_constr;
|
2008-08-31 23:23:16 +00:00
|
|
|
};
|
2008-03-16 20:10:13 +00:00
|
|
|
|
2008-08-31 23:23:38 +00:00
|
|
|
void script_release(script_ctx_t*);
|
|
|
|
|
2008-09-04 21:31:09 +00:00
|
|
|
static inline void script_addref(script_ctx_t *ctx)
|
2008-08-31 23:23:38 +00:00
|
|
|
{
|
|
|
|
ctx->ref++;
|
|
|
|
}
|
|
|
|
|
2008-09-08 23:22:54 +00:00
|
|
|
HRESULT init_global(script_ctx_t*);
|
2009-07-12 17:52:31 +00:00
|
|
|
HRESULT init_function_constr(script_ctx_t*,DispatchEx*);
|
|
|
|
HRESULT create_object_prototype(script_ctx_t*,DispatchEx**);
|
2008-09-08 23:22:54 +00:00
|
|
|
|
2009-08-14 09:55:15 +00:00
|
|
|
HRESULT create_array_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2009-08-14 09:54:51 +00:00
|
|
|
HRESULT create_bool_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2009-08-14 09:53:57 +00:00
|
|
|
HRESULT create_date_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2009-08-14 09:58:10 +00:00
|
|
|
HRESULT init_error_constr(script_ctx_t*,DispatchEx*);
|
2009-08-12 10:48:34 +00:00
|
|
|
HRESULT create_number_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2009-07-12 17:52:31 +00:00
|
|
|
HRESULT create_object_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2009-08-12 10:48:15 +00:00
|
|
|
HRESULT create_regexp_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2009-08-12 10:47:53 +00:00
|
|
|
HRESULT create_string_constr(script_ctx_t*,DispatchEx*,DispatchEx**);
|
2008-09-10 00:33:15 +00:00
|
|
|
|
2008-09-15 18:41:04 +00:00
|
|
|
typedef struct {
|
|
|
|
const WCHAR *str;
|
|
|
|
DWORD len;
|
|
|
|
} match_result_t;
|
|
|
|
|
2008-09-24 22:53:29 +00:00
|
|
|
HRESULT regexp_match_next(DispatchEx*,BOOL,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
|
|
|
|
DWORD*,DWORD*,match_result_t*);
|
2008-09-15 18:41:04 +00:00
|
|
|
HRESULT regexp_match(DispatchEx*,const WCHAR*,DWORD,BOOL,match_result_t**,DWORD*);
|
|
|
|
|
2008-09-15 18:37:10 +00:00
|
|
|
static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
|
|
|
|
{
|
|
|
|
return dp->rgvarg + dp->cArgs-i-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD arg_cnt(const DISPPARAMS *dp)
|
|
|
|
{
|
|
|
|
return dp->cArgs - dp->cNamedArgs;
|
|
|
|
}
|
|
|
|
|
2008-09-21 13:36:26 +00:00
|
|
|
static inline BOOL is_class(DispatchEx *jsdisp, jsclass_t class)
|
|
|
|
{
|
|
|
|
return jsdisp->builtin_info->class == class;
|
|
|
|
}
|
|
|
|
|
2008-09-21 13:38:28 +00:00
|
|
|
static inline BOOL is_num_vt(enum VARENUM vt)
|
|
|
|
{
|
|
|
|
return vt == VT_I4 || vt == VT_R8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DOUBLE num_val(const VARIANT *v)
|
|
|
|
{
|
|
|
|
return V_VT(v) == VT_I4 ? V_I4(v) : V_R8(v);
|
|
|
|
}
|
|
|
|
|
2008-09-18 22:43:03 +00:00
|
|
|
static inline void num_set_val(VARIANT *v, DOUBLE d)
|
|
|
|
{
|
|
|
|
if(d == (DOUBLE)(INT)d) {
|
|
|
|
V_VT(v) = VT_I4;
|
|
|
|
V_I4(v) = d;
|
|
|
|
}else {
|
|
|
|
V_VT(v) = VT_R8;
|
|
|
|
V_R8(v) = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-15 23:49:51 +00:00
|
|
|
static inline void num_set_nan(VARIANT *v)
|
|
|
|
{
|
|
|
|
V_VT(v) = VT_R8;
|
|
|
|
#ifdef NAN
|
|
|
|
V_R8(v) = NAN;
|
|
|
|
#else
|
|
|
|
V_UI8(v) = (ULONGLONG)0x7ff80000<<32;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-06-03 19:11:20 +00:00
|
|
|
static inline DOUBLE ret_nan()
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
num_set_nan(&v);
|
|
|
|
return V_R8(&v);
|
|
|
|
}
|
|
|
|
|
2008-10-16 19:31:18 +00:00
|
|
|
static inline void num_set_inf(VARIANT *v, BOOL positive)
|
|
|
|
{
|
|
|
|
V_VT(v) = VT_R8;
|
|
|
|
#ifdef INFINITY
|
|
|
|
V_R8(v) = positive ? INFINITY : -INFINITY;
|
|
|
|
#else
|
|
|
|
V_UI8(v) = (ULONGLONG)0x7ff00000<<32;
|
|
|
|
if(!positive)
|
|
|
|
V_R8(v) = -V_R8(v);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-08 23:20:26 +00:00
|
|
|
const char *debugstr_variant(const VARIANT*);
|
|
|
|
|
2008-03-16 20:10:13 +00:00
|
|
|
HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
|
|
|
|
|
2008-03-24 20:53:34 +00:00
|
|
|
extern LONG module_ref;
|
|
|
|
|
|
|
|
static inline void lock_module(void)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&module_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unlock_module(void)
|
|
|
|
{
|
|
|
|
InterlockedDecrement(&module_ref);
|
|
|
|
}
|
|
|
|
|
2008-03-16 20:10:13 +00:00
|
|
|
static inline void *heap_alloc(size_t len)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *heap_alloc_zero(size_t len)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
|
|
|
|
}
|
|
|
|
|
2008-09-02 22:26:10 +00:00
|
|
|
static inline void *heap_realloc(void *mem, size_t len)
|
|
|
|
{
|
|
|
|
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
|
|
|
|
}
|
|
|
|
|
2008-03-16 20:10:13 +00:00
|
|
|
static inline BOOL heap_free(void *mem)
|
|
|
|
{
|
|
|
|
return HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
}
|
|
|
|
|
2008-09-07 22:14:58 +00:00
|
|
|
static inline LPWSTR heap_strdupW(LPCWSTR str)
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
|
|
|
|
if(str) {
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
size = (strlenW(str)+1)*sizeof(WCHAR);
|
|
|
|
ret = heap_alloc(size);
|
|
|
|
memcpy(ret, str, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-16 20:10:13 +00:00
|
|
|
#define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
|