winmm: Add a WARNing when winejoystick.drv is missing.
[wine.git] / dlls / vbscript / vbscript.h
blob98a5cb154b79730ad4807d1e868c23fe23e38661
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"
28 #include "activdbg.h"
30 #include "vbscript_classes.h"
32 #include "wine/heap.h"
33 #include "wine/list.h"
34 #include "wine/unicode.h"
36 typedef struct {
37 void **blocks;
38 DWORD block_cnt;
39 DWORD last_block;
40 DWORD offset;
41 BOOL mark;
42 struct list custom_blocks;
43 } heap_pool_t;
45 void heap_pool_init(heap_pool_t*) DECLSPEC_HIDDEN;
46 void *heap_pool_alloc(heap_pool_t*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
47 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
48 void heap_pool_clear(heap_pool_t*) DECLSPEC_HIDDEN;
49 void heap_pool_free(heap_pool_t*) DECLSPEC_HIDDEN;
50 heap_pool_t *heap_pool_mark(heap_pool_t*) DECLSPEC_HIDDEN;
52 typedef struct _function_t function_t;
53 typedef struct _vbscode_t vbscode_t;
54 typedef struct _script_ctx_t script_ctx_t;
55 typedef struct _vbdisp_t vbdisp_t;
57 typedef struct named_item_t {
58 IDispatch *disp;
59 DWORD flags;
60 LPWSTR name;
62 struct list entry;
63 } named_item_t;
65 typedef enum {
66 VBDISP_CALLGET,
67 VBDISP_LET,
68 VBDISP_SET,
69 VBDISP_ANY
70 } vbdisp_invoke_type_t;
72 typedef struct {
73 unsigned dim_cnt;
74 SAFEARRAYBOUND *bounds;
75 } array_desc_t;
77 typedef struct {
78 BOOL is_public;
79 BOOL is_array;
80 const WCHAR *name;
81 } vbdisp_prop_desc_t;
83 typedef struct {
84 const WCHAR *name;
85 BOOL is_public;
86 BOOL is_array;
87 function_t *entries[VBDISP_ANY];
88 } vbdisp_funcprop_desc_t;
90 #define BP_GET 1
91 #define BP_GETPUT 2
93 typedef struct {
94 DISPID id;
95 HRESULT (*proc)(vbdisp_t*,VARIANT*,unsigned,VARIANT*);
96 DWORD flags;
97 unsigned min_args;
98 UINT_PTR max_args;
99 } builtin_prop_t;
101 typedef struct _class_desc_t {
102 const WCHAR *name;
103 script_ctx_t *ctx;
105 unsigned class_initialize_id;
106 unsigned class_terminate_id;
107 unsigned func_cnt;
108 vbdisp_funcprop_desc_t *funcs;
110 unsigned prop_cnt;
111 vbdisp_prop_desc_t *props;
113 unsigned array_cnt;
114 array_desc_t *array_descs;
116 unsigned builtin_prop_cnt;
117 const builtin_prop_t *builtin_props;
118 ITypeInfo *typeinfo;
119 function_t *value_func;
121 struct _class_desc_t *next;
122 } class_desc_t;
124 struct _vbdisp_t {
125 IDispatchEx IDispatchEx_iface;
127 LONG ref;
128 BOOL terminator_ran;
129 struct list entry;
131 const class_desc_t *desc;
132 SAFEARRAY **arrays;
133 VARIANT props[1];
136 typedef struct _ident_map_t ident_map_t;
138 typedef struct {
139 IDispatchEx IDispatchEx_iface;
140 LONG ref;
142 ident_map_t *ident_map;
143 unsigned ident_map_cnt;
144 unsigned ident_map_size;
146 script_ctx_t *ctx;
147 } ScriptDisp;
149 HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**) DECLSPEC_HIDDEN;
150 HRESULT disp_get_id(IDispatch*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
151 HRESULT vbdisp_get_id(vbdisp_t*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
152 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
153 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*) DECLSPEC_HIDDEN;
154 HRESULT get_disp_value(script_ctx_t*,IDispatch*,VARIANT*) DECLSPEC_HIDDEN;
155 void collect_objects(script_ctx_t*) DECLSPEC_HIDDEN;
156 HRESULT create_procedure_disp(script_ctx_t*,vbscode_t*,IDispatch**) DECLSPEC_HIDDEN;
157 HRESULT create_script_disp(script_ctx_t*,ScriptDisp**) DECLSPEC_HIDDEN;
159 HRESULT to_int(VARIANT*,int*) DECLSPEC_HIDDEN;
161 static inline unsigned arg_cnt(const DISPPARAMS *dp)
163 return dp->cArgs - dp->cNamedArgs;
166 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
168 return dp->rgvarg + dp->cArgs-i-1;
171 typedef struct _dynamic_var_t {
172 struct _dynamic_var_t *next;
173 VARIANT v;
174 const WCHAR *name;
175 BOOL is_const;
176 } dynamic_var_t;
178 struct _script_ctx_t {
179 IActiveScriptSite *site;
180 LCID lcid;
182 IInternetHostSecurityManager *secmgr;
183 DWORD safeopt;
185 IDispatch *host_global;
187 ScriptDisp *script_obj;
189 class_desc_t global_desc;
190 vbdisp_t *global_obj;
192 class_desc_t err_desc;
193 vbdisp_t *err_obj;
195 HRESULT err_number;
197 dynamic_var_t *global_vars;
198 function_t *global_funcs;
199 class_desc_t *classes;
200 class_desc_t *procs;
202 heap_pool_t heap;
204 struct list objects;
205 struct list code_list;
206 struct list named_items;
209 HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
210 HRESULT init_err(script_ctx_t*) DECLSPEC_HIDDEN;
212 IUnknown *create_ax_site(script_ctx_t*) DECLSPEC_HIDDEN;
214 typedef enum {
215 ARG_NONE = 0,
216 ARG_STR,
217 ARG_BSTR,
218 ARG_INT,
219 ARG_UINT,
220 ARG_ADDR,
221 ARG_DOUBLE
222 } instr_arg_type_t;
224 #define OP_LIST \
225 X(add, 1, 0, 0) \
226 X(and, 1, 0, 0) \
227 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
228 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
229 X(bool, 1, ARG_INT, 0) \
230 X(catch, 1, ARG_ADDR, ARG_UINT) \
231 X(case, 0, ARG_ADDR, 0) \
232 X(concat, 1, 0, 0) \
233 X(const, 1, ARG_BSTR, 0) \
234 X(dim, 1, ARG_BSTR, ARG_UINT) \
235 X(div, 1, 0, 0) \
236 X(double, 1, ARG_DOUBLE, 0) \
237 X(empty, 1, 0, 0) \
238 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
239 X(equal, 1, 0, 0) \
240 X(hres, 1, ARG_UINT, 0) \
241 X(errmode, 1, ARG_INT, 0) \
242 X(eqv, 1, 0, 0) \
243 X(exp, 1, 0, 0) \
244 X(gt, 1, 0, 0) \
245 X(gteq, 1, 0, 0) \
246 X(icall, 1, ARG_BSTR, ARG_UINT) \
247 X(icallv, 1, ARG_BSTR, ARG_UINT) \
248 X(idiv, 1, 0, 0) \
249 X(imp, 1, 0, 0) \
250 X(incc, 1, ARG_BSTR, 0) \
251 X(is, 1, 0, 0) \
252 X(jmp, 0, ARG_ADDR, 0) \
253 X(jmp_false, 0, ARG_ADDR, 0) \
254 X(jmp_true, 0, ARG_ADDR, 0) \
255 X(long, 1, ARG_INT, 0) \
256 X(lt, 1, 0, 0) \
257 X(lteq, 1, 0, 0) \
258 X(mcall, 1, ARG_BSTR, ARG_UINT) \
259 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
260 X(me, 1, 0, 0) \
261 X(mod, 1, 0, 0) \
262 X(mul, 1, 0, 0) \
263 X(neg, 1, 0, 0) \
264 X(nequal, 1, 0, 0) \
265 X(new, 1, ARG_STR, 0) \
266 X(newenum, 1, 0, 0) \
267 X(not, 1, 0, 0) \
268 X(nothing, 1, 0, 0) \
269 X(null, 1, 0, 0) \
270 X(or, 1, 0, 0) \
271 X(pop, 1, ARG_UINT, 0) \
272 X(ret, 0, 0, 0) \
273 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
274 X(set_member, 1, ARG_BSTR, ARG_UINT) \
275 X(short, 1, ARG_INT, 0) \
276 X(step, 0, ARG_ADDR, ARG_BSTR) \
277 X(stop, 1, 0, 0) \
278 X(string, 1, ARG_STR, 0) \
279 X(sub, 1, 0, 0) \
280 X(val, 1, 0, 0) \
281 X(xor, 1, 0, 0)
283 typedef enum {
284 #define X(x,n,a,b) OP_##x,
285 OP_LIST
286 #undef X
287 OP_LAST
288 } vbsop_t;
290 typedef union {
291 const WCHAR *str;
292 BSTR bstr;
293 unsigned uint;
294 LONG lng;
295 double *dbl;
296 } instr_arg_t;
298 typedef struct {
299 vbsop_t op;
300 instr_arg_t arg1;
301 instr_arg_t arg2;
302 } instr_t;
304 typedef struct {
305 const WCHAR *name;
306 BOOL by_ref;
307 } arg_desc_t;
309 typedef enum {
310 FUNC_GLOBAL,
311 FUNC_FUNCTION,
312 FUNC_SUB,
313 FUNC_PROPGET,
314 FUNC_PROPLET,
315 FUNC_PROPSET,
316 FUNC_DEFGET
317 } function_type_t;
319 typedef struct {
320 const WCHAR *name;
321 } var_desc_t;
323 struct _function_t {
324 function_type_t type;
325 const WCHAR *name;
326 BOOL is_public;
327 arg_desc_t *args;
328 unsigned arg_cnt;
329 var_desc_t *vars;
330 unsigned var_cnt;
331 array_desc_t *array_descs;
332 unsigned array_cnt;
333 unsigned code_off;
334 vbscode_t *code_ctx;
335 function_t *next;
338 struct _vbscode_t {
339 instr_t *instrs;
340 WCHAR *source;
342 BOOL option_explicit;
344 BOOL pending_exec;
345 function_t main_code;
346 IDispatch *context;
348 BSTR *bstr_pool;
349 unsigned bstr_pool_size;
350 unsigned bstr_cnt;
351 heap_pool_t heap;
353 struct list entry;
356 void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
357 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
358 HRESULT exec_script(script_ctx_t*,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
359 void release_dynamic_vars(dynamic_var_t*) DECLSPEC_HIDDEN;
360 IDispatch *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned) DECLSPEC_HIDDEN;
362 typedef struct {
363 UINT16 len;
364 WCHAR buf[7];
365 } string_constant_t;
367 #define TID_LIST \
368 XDIID(ErrObj) \
369 XDIID(GlobalObj)
371 typedef enum {
372 #define XDIID(iface) iface ## _tid,
373 TID_LIST
374 #undef XDIID
375 LAST_tid
376 } tid_t;
378 HRESULT get_typeinfo(tid_t,ITypeInfo**) DECLSPEC_HIDDEN;
379 void release_regexp_typelib(void) DECLSPEC_HIDDEN;
381 #ifndef INT32_MIN
382 #define INT32_MIN (-2147483647-1)
383 #endif
385 #ifndef INT32_MAX
386 #define INT32_MAX (2147483647)
387 #endif
389 static inline BOOL is_int32(double d)
391 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
394 HRESULT create_regexp(IDispatch**) DECLSPEC_HIDDEN;
396 HRESULT map_hres(HRESULT) DECLSPEC_HIDDEN;
398 HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev) DECLSPEC_HIDDEN;
400 #define FACILITY_VBS 0xa
401 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
403 #define VBSE_ILLEGAL_FUNC_CALL 5
404 #define VBSE_OVERFLOW 6
405 #define VBSE_OUT_OF_MEMORY 7
406 #define VBSE_OUT_OF_BOUNDS 9
407 #define VBSE_ARRAY_LOCKED 10
408 #define VBSE_TYPE_MISMATCH 13
409 #define VBSE_FILE_NOT_FOUND 53
410 #define VBSE_IO_ERROR 57
411 #define VBSE_FILE_ALREADY_EXISTS 58
412 #define VBSE_DISK_FULL 61
413 #define VBSE_TOO_MANY_FILES 67
414 #define VBSE_PERMISSION_DENIED 70
415 #define VBSE_PATH_FILE_ACCESS 75
416 #define VBSE_PATH_NOT_FOUND 76
417 #define VBSE_ILLEGAL_NULL_USE 94
418 #define VBSE_OLE_NOT_SUPPORTED 430
419 #define VBSE_OLE_NO_PROP_OR_METHOD 438
420 #define VBSE_ACTION_NOT_SUPPORTED 445
421 #define VBSE_NAMED_ARGS_NOT_SUPPORTED 446
422 #define VBSE_LOCALE_SETTING_NOT_SUPPORTED 447
423 #define VBSE_NAMED_PARAM_NOT_FOUND 448
424 #define VBSE_INVALID_TYPELIB_VARIABLE 458
425 #define VBSE_FUNC_ARITY_MISMATCH 450
426 #define VBSE_PARAMETER_NOT_OPTIONAL 449
427 #define VBSE_NOT_ENUM 451
428 #define VBSE_INVALID_DLL_FUNCTION_NAME 453
429 #define VBSE_CANT_CREATE_TMP_FILE 322
430 #define VBSE_OLE_FILE_NOT_FOUND 432
431 #define VBSE_CANT_CREATE_OBJECT 429
432 #define VBSE_SERVER_NOT_FOUND 462
434 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
435 HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
437 static inline LPWSTR heap_strdupW(LPCWSTR str)
439 LPWSTR ret = NULL;
441 if(str) {
442 DWORD size;
444 size = (strlenW(str)+1)*sizeof(WCHAR);
445 ret = heap_alloc(size);
446 if(ret)
447 memcpy(ret, str, size);
450 return ret;
453 #define VBSCRIPT_BUILD_VERSION 16978
454 #define VBSCRIPT_MAJOR_VERSION 5
455 #define VBSCRIPT_MINOR_VERSION 8