include: Add constants for CryptProtectMemory/CryptUnprotectMemory.
[wine.git] / dlls / vbscript / vbscript.h
blobcd122d3db1a3e6c63d20382dd06caa15affc210e
1 /*
2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "ole2.h"
26 #include "dispex.h"
27 #include "activscp.h"
29 #include "vbscript_classes.h"
31 #include "wine/list.h"
32 #include "wine/unicode.h"
34 typedef struct {
35 void **blocks;
36 DWORD block_cnt;
37 DWORD last_block;
38 DWORD offset;
39 BOOL mark;
40 struct list custom_blocks;
41 } heap_pool_t;
43 void heap_pool_init(heap_pool_t*) DECLSPEC_HIDDEN;
44 void *heap_pool_alloc(heap_pool_t*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
45 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
46 void heap_pool_clear(heap_pool_t*) DECLSPEC_HIDDEN;
47 void heap_pool_free(heap_pool_t*) DECLSPEC_HIDDEN;
48 heap_pool_t *heap_pool_mark(heap_pool_t*) DECLSPEC_HIDDEN;
50 typedef struct _function_t function_t;
51 typedef struct _vbscode_t vbscode_t;
52 typedef struct _script_ctx_t script_ctx_t;
53 typedef struct _vbdisp_t vbdisp_t;
55 typedef struct named_item_t {
56 IDispatch *disp;
57 DWORD flags;
58 LPWSTR name;
60 struct list entry;
61 } named_item_t;
63 typedef enum {
64 VBDISP_CALLGET,
65 VBDISP_LET,
66 VBDISP_SET,
67 VBDISP_ANY
68 } vbdisp_invoke_type_t;
70 typedef struct {
71 unsigned dim_cnt;
72 SAFEARRAYBOUND *bounds;
73 } array_desc_t;
75 typedef struct {
76 BOOL is_public;
77 BOOL is_array;
78 const WCHAR *name;
79 } vbdisp_prop_desc_t;
81 typedef struct {
82 const WCHAR *name;
83 BOOL is_public;
84 BOOL is_array;
85 function_t *entries[VBDISP_ANY];
86 } vbdisp_funcprop_desc_t;
88 #define BP_GET 1
89 #define BP_GETPUT 2
91 typedef struct {
92 DISPID id;
93 HRESULT (*proc)(vbdisp_t*,VARIANT*,unsigned,VARIANT*);
94 DWORD flags;
95 unsigned min_args;
96 UINT_PTR max_args;
97 } builtin_prop_t;
99 typedef struct _class_desc_t {
100 const WCHAR *name;
101 script_ctx_t *ctx;
103 unsigned class_initialize_id;
104 unsigned class_terminate_id;
105 unsigned func_cnt;
106 vbdisp_funcprop_desc_t *funcs;
108 unsigned prop_cnt;
109 vbdisp_prop_desc_t *props;
111 unsigned array_cnt;
112 array_desc_t *array_descs;
114 unsigned builtin_prop_cnt;
115 const builtin_prop_t *builtin_props;
116 ITypeInfo *typeinfo;
117 function_t *value_func;
119 struct _class_desc_t *next;
120 } class_desc_t;
122 struct _vbdisp_t {
123 IDispatchEx IDispatchEx_iface;
125 LONG ref;
126 BOOL terminator_ran;
127 struct list entry;
129 const class_desc_t *desc;
130 SAFEARRAY **arrays;
131 VARIANT props[1];
134 typedef struct _ident_map_t ident_map_t;
136 typedef struct {
137 IDispatchEx IDispatchEx_iface;
138 LONG ref;
140 ident_map_t *ident_map;
141 unsigned ident_map_cnt;
142 unsigned ident_map_size;
144 script_ctx_t *ctx;
145 } ScriptDisp;
147 HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**) DECLSPEC_HIDDEN;
148 HRESULT disp_get_id(IDispatch*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
149 HRESULT vbdisp_get_id(vbdisp_t*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
150 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
151 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*) DECLSPEC_HIDDEN;
152 HRESULT get_disp_value(script_ctx_t*,IDispatch*,VARIANT*) DECLSPEC_HIDDEN;
153 void collect_objects(script_ctx_t*) DECLSPEC_HIDDEN;
154 HRESULT create_procedure_disp(script_ctx_t*,vbscode_t*,IDispatch**) DECLSPEC_HIDDEN;
155 HRESULT create_script_disp(script_ctx_t*,ScriptDisp**) DECLSPEC_HIDDEN;
157 HRESULT to_int(VARIANT*,int*) DECLSPEC_HIDDEN;
159 static inline unsigned arg_cnt(const DISPPARAMS *dp)
161 return dp->cArgs - dp->cNamedArgs;
164 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
166 return dp->rgvarg + dp->cArgs-i-1;
169 typedef struct _dynamic_var_t {
170 struct _dynamic_var_t *next;
171 VARIANT v;
172 const WCHAR *name;
173 BOOL is_const;
174 } dynamic_var_t;
176 struct _script_ctx_t {
177 IActiveScriptSite *site;
178 LCID lcid;
180 IInternetHostSecurityManager *secmgr;
181 DWORD safeopt;
183 IDispatch *host_global;
185 ScriptDisp *script_obj;
187 class_desc_t global_desc;
188 vbdisp_t *global_obj;
190 class_desc_t err_desc;
191 vbdisp_t *err_obj;
193 HRESULT err_number;
195 dynamic_var_t *global_vars;
196 function_t *global_funcs;
197 class_desc_t *classes;
198 class_desc_t *procs;
200 heap_pool_t heap;
202 struct list objects;
203 struct list code_list;
204 struct list named_items;
207 HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
208 HRESULT init_err(script_ctx_t*) DECLSPEC_HIDDEN;
210 IUnknown *create_ax_site(script_ctx_t*) DECLSPEC_HIDDEN;
212 typedef enum {
213 ARG_NONE = 0,
214 ARG_STR,
215 ARG_BSTR,
216 ARG_INT,
217 ARG_UINT,
218 ARG_ADDR,
219 ARG_DOUBLE
220 } instr_arg_type_t;
222 #define OP_LIST \
223 X(add, 1, 0, 0) \
224 X(and, 1, 0, 0) \
225 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
226 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
227 X(bool, 1, ARG_INT, 0) \
228 X(catch, 1, ARG_ADDR, ARG_UINT) \
229 X(case, 0, ARG_ADDR, 0) \
230 X(concat, 1, 0, 0) \
231 X(const, 1, ARG_BSTR, 0) \
232 X(dim, 1, ARG_BSTR, ARG_UINT) \
233 X(div, 1, 0, 0) \
234 X(double, 1, ARG_DOUBLE, 0) \
235 X(empty, 1, 0, 0) \
236 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
237 X(equal, 1, 0, 0) \
238 X(hres, 1, ARG_UINT, 0) \
239 X(errmode, 1, ARG_INT, 0) \
240 X(eqv, 1, 0, 0) \
241 X(exp, 1, 0, 0) \
242 X(gt, 1, 0, 0) \
243 X(gteq, 1, 0, 0) \
244 X(icall, 1, ARG_BSTR, ARG_UINT) \
245 X(icallv, 1, ARG_BSTR, ARG_UINT) \
246 X(idiv, 1, 0, 0) \
247 X(imp, 1, 0, 0) \
248 X(incc, 1, ARG_BSTR, 0) \
249 X(is, 1, 0, 0) \
250 X(jmp, 0, ARG_ADDR, 0) \
251 X(jmp_false, 0, ARG_ADDR, 0) \
252 X(jmp_true, 0, ARG_ADDR, 0) \
253 X(long, 1, ARG_INT, 0) \
254 X(lt, 1, 0, 0) \
255 X(lteq, 1, 0, 0) \
256 X(mcall, 1, ARG_BSTR, ARG_UINT) \
257 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
258 X(me, 1, 0, 0) \
259 X(mod, 1, 0, 0) \
260 X(mul, 1, 0, 0) \
261 X(neg, 1, 0, 0) \
262 X(nequal, 1, 0, 0) \
263 X(new, 1, ARG_STR, 0) \
264 X(newenum, 1, 0, 0) \
265 X(not, 1, 0, 0) \
266 X(nothing, 1, 0, 0) \
267 X(null, 1, 0, 0) \
268 X(or, 1, 0, 0) \
269 X(pop, 1, ARG_UINT, 0) \
270 X(ret, 0, 0, 0) \
271 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
272 X(set_member, 1, ARG_BSTR, ARG_UINT) \
273 X(short, 1, ARG_INT, 0) \
274 X(step, 0, ARG_ADDR, ARG_BSTR) \
275 X(stop, 1, 0, 0) \
276 X(string, 1, ARG_STR, 0) \
277 X(sub, 1, 0, 0) \
278 X(val, 1, 0, 0) \
279 X(xor, 1, 0, 0)
281 typedef enum {
282 #define X(x,n,a,b) OP_##x,
283 OP_LIST
284 #undef X
285 OP_LAST
286 } vbsop_t;
288 typedef union {
289 const WCHAR *str;
290 BSTR bstr;
291 unsigned uint;
292 LONG lng;
293 double *dbl;
294 } instr_arg_t;
296 typedef struct {
297 vbsop_t op;
298 instr_arg_t arg1;
299 instr_arg_t arg2;
300 } instr_t;
302 typedef struct {
303 const WCHAR *name;
304 BOOL by_ref;
305 } arg_desc_t;
307 typedef enum {
308 FUNC_GLOBAL,
309 FUNC_FUNCTION,
310 FUNC_SUB,
311 FUNC_PROPGET,
312 FUNC_PROPLET,
313 FUNC_PROPSET,
314 FUNC_DEFGET
315 } function_type_t;
317 typedef struct {
318 const WCHAR *name;
319 } var_desc_t;
321 struct _function_t {
322 function_type_t type;
323 const WCHAR *name;
324 BOOL is_public;
325 arg_desc_t *args;
326 unsigned arg_cnt;
327 var_desc_t *vars;
328 unsigned var_cnt;
329 array_desc_t *array_descs;
330 unsigned array_cnt;
331 unsigned code_off;
332 vbscode_t *code_ctx;
333 function_t *next;
336 struct _vbscode_t {
337 instr_t *instrs;
338 WCHAR *source;
340 BOOL option_explicit;
342 BOOL pending_exec;
343 function_t main_code;
345 BSTR *bstr_pool;
346 unsigned bstr_pool_size;
347 unsigned bstr_cnt;
348 heap_pool_t heap;
350 struct list entry;
353 void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
354 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
355 HRESULT exec_script(script_ctx_t*,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
356 void release_dynamic_vars(dynamic_var_t*) DECLSPEC_HIDDEN;
358 typedef struct {
359 UINT16 len;
360 WCHAR buf[7];
361 } string_constant_t;
363 #define TID_LIST \
364 XDIID(ErrObj) \
365 XDIID(GlobalObj)
367 typedef enum {
368 #define XDIID(iface) iface ## _tid,
369 TID_LIST
370 #undef XDIID
371 LAST_tid
372 } tid_t;
374 HRESULT get_typeinfo(tid_t,ITypeInfo**) DECLSPEC_HIDDEN;
375 void release_regexp_typelib(void) DECLSPEC_HIDDEN;
377 #ifndef INT32_MIN
378 #define INT32_MIN (-2147483647-1)
379 #endif
381 #ifndef INT32_MAX
382 #define INT32_MAX (2147483647)
383 #endif
385 static inline BOOL is_int32(double d)
387 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
390 HRESULT create_regexp(IDispatch**) DECLSPEC_HIDDEN;
392 HRESULT map_hres(HRESULT) DECLSPEC_HIDDEN;
394 #define FACILITY_VBS 0xa
395 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
397 #define VBSE_ILLEGAL_FUNC_CALL 5
398 #define VBSE_OVERFLOW 6
399 #define VBSE_OUT_OF_MEMORY 7
400 #define VBSE_OUT_OF_BOUNDS 9
401 #define VBSE_ARRAY_LOCKED 10
402 #define VBSE_TYPE_MISMATCH 13
403 #define VBSE_FILE_NOT_FOUND 53
404 #define VBSE_IO_ERROR 57
405 #define VBSE_FILE_ALREADY_EXISTS 58
406 #define VBSE_DISK_FULL 61
407 #define VBSE_TOO_MANY_FILES 67
408 #define VBSE_PERMISSION_DENIED 70
409 #define VBSE_PATH_FILE_ACCESS 75
410 #define VBSE_PATH_NOT_FOUND 76
411 #define VBSE_ILLEGAL_NULL_USE 94
412 #define VBSE_OLE_NOT_SUPPORTED 430
413 #define VBSE_OLE_NO_PROP_OR_METHOD 438
414 #define VBSE_ACTION_NOT_SUPPORTED 445
415 #define VBSE_NAMED_ARGS_NOT_SUPPORTED 446
416 #define VBSE_LOCALE_SETTING_NOT_SUPPORTED 447
417 #define VBSE_NAMED_PARAM_NOT_FOUND 448
418 #define VBSE_INVALID_TYPELIB_VARIABLE 458
419 #define VBSE_FUNC_ARITY_MISMATCH 450
420 #define VBSE_PARAMETER_NOT_OPTIONAL 449
421 #define VBSE_NOT_ENUM 451
422 #define VBSE_INVALID_DLL_FUNCTION_NAME 453
423 #define VBSE_CANT_CREATE_TMP_FILE 322
424 #define VBSE_OLE_FILE_NOT_FOUND 432
425 #define VBSE_CANT_CREATE_OBJECT 429
426 #define VBSE_SERVER_NOT_FOUND 462
428 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
429 HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
431 static inline void *heap_alloc(size_t len)
433 return HeapAlloc(GetProcessHeap(), 0, len);
436 static inline void *heap_alloc_zero(size_t len)
438 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
441 static inline void *heap_realloc(void *mem, size_t len)
443 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
446 static inline BOOL heap_free(void *mem)
448 return HeapFree(GetProcessHeap(), 0, mem);
451 static inline LPWSTR heap_strdupW(LPCWSTR str)
453 LPWSTR ret = NULL;
455 if(str) {
456 DWORD size;
458 size = (strlenW(str)+1)*sizeof(WCHAR);
459 ret = heap_alloc(size);
460 if(ret)
461 memcpy(ret, str, size);
464 return ret;
467 #define VBSCRIPT_BUILD_VERSION 16978
468 #define VBSCRIPT_MAJOR_VERSION 5
469 #define VBSCRIPT_MINOR_VERSION 8