d2d1: Implement d2d_bitmap_brush_GetTransform().
[wine.git] / dlls / vbscript / global.c
blobbbbe22c9005610c900a6fbe10479f8f1cdd471eb
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 <assert.h>
20 #include <math.h>
22 #include "vbscript.h"
23 #include "vbscript_defs.h"
25 #include "mshtmhst.h"
26 #include "objsafe.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
32 #define VB_E_CANNOT_CREATE_OBJ 0x800a01ad
33 #define VB_E_MK_PARSE_ERROR 0x800a01b0
35 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
36 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
37 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
39 static const WCHAR emptyW[] = {0};
40 static const WCHAR vbscriptW[] = {'V','B','S','c','r','i','p','t',0};
42 static IInternetHostSecurityManager *get_sec_mgr(script_ctx_t *ctx)
44 IInternetHostSecurityManager *secmgr;
45 IServiceProvider *sp;
46 HRESULT hres;
48 if(!ctx->site)
49 return NULL;
51 if(ctx->secmgr)
52 return ctx->secmgr;
54 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
55 if(FAILED(hres))
56 return NULL;
58 hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager, &IID_IInternetHostSecurityManager,
59 (void**)&secmgr);
60 IServiceProvider_Release(sp);
61 if(FAILED(hres))
62 return NULL;
64 return ctx->secmgr = secmgr;
67 static HRESULT return_string(VARIANT *res, const WCHAR *str)
69 BSTR ret;
71 if(!res)
72 return S_OK;
74 ret = SysAllocString(str);
75 if(!ret)
76 return E_OUTOFMEMORY;
78 V_VT(res) = VT_BSTR;
79 V_BSTR(res) = ret;
80 return S_OK;
83 static HRESULT return_bstr(VARIANT *res, BSTR str)
85 if(res) {
86 V_VT(res) = VT_BSTR;
87 V_BSTR(res) = str;
88 }else {
89 SysFreeString(str);
91 return S_OK;
94 static HRESULT return_bool(VARIANT *res, BOOL val)
96 if(res) {
97 V_VT(res) = VT_BOOL;
98 V_BOOL(res) = val ? VARIANT_TRUE : VARIANT_FALSE;
100 return S_OK;
103 static HRESULT return_short(VARIANT *res, short val)
105 if(res) {
106 V_VT(res) = VT_I2;
107 V_I2(res) = val;
110 return S_OK;
113 static HRESULT return_int(VARIANT *res, int val)
115 if(res) {
116 V_VT(res) = VT_I4;
117 V_I4(res) = val;
120 return S_OK;
123 static inline HRESULT return_double(VARIANT *res, double val)
125 if(res) {
126 V_VT(res) = VT_R8;
127 V_R8(res) = val;
130 return S_OK;
133 static inline HRESULT return_float(VARIANT *res, float val)
135 if(res) {
136 V_VT(res) = VT_R4;
137 V_R4(res) = val;
140 return S_OK;
143 static inline HRESULT return_null(VARIANT *res)
145 if(res)
146 V_VT(res) = VT_NULL;
147 return S_OK;
150 static inline HRESULT return_date(VARIANT *res, double date)
152 if(res) {
153 V_VT(res) = VT_DATE;
154 V_DATE(res) = date;
156 return S_OK;
159 HRESULT to_int(VARIANT *v, int *ret)
161 VARIANT r;
162 HRESULT hres;
164 V_VT(&r) = VT_EMPTY;
165 hres = VariantChangeType(&r, v, 0, VT_I4);
166 if(FAILED(hres))
167 return hres;
169 *ret = V_I4(&r);
170 return S_OK;
173 static HRESULT to_double(VARIANT *v, double *ret)
175 VARIANT dst;
176 HRESULT hres;
178 V_VT(&dst) = VT_EMPTY;
179 hres = VariantChangeType(&dst, v, 0, VT_R8);
180 if(FAILED(hres))
181 return hres;
183 *ret = V_R8(&dst);
184 return S_OK;
187 static HRESULT to_string(VARIANT *v, BSTR *ret)
189 VARIANT dst;
190 HRESULT hres;
192 V_VT(&dst) = VT_EMPTY;
193 hres = VariantChangeType(&dst, v, VARIANT_LOCALBOOL, VT_BSTR);
194 if(FAILED(hres))
195 return hres;
197 *ret = V_BSTR(&dst);
198 return S_OK;
201 static HRESULT set_object_site(script_ctx_t *ctx, IUnknown *obj)
203 IObjectWithSite *obj_site;
204 IUnknown *ax_site;
205 HRESULT hres;
207 hres = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (void**)&obj_site);
208 if(FAILED(hres))
209 return S_OK;
211 ax_site = create_ax_site(ctx);
212 if(ax_site)
213 hres = IObjectWithSite_SetSite(obj_site, ax_site);
214 else
215 hres = E_OUTOFMEMORY;
216 IUnknown_Release(ax_site);
217 IObjectWithSite_Release(obj_site);
218 return hres;
221 static IUnknown *create_object(script_ctx_t *ctx, const WCHAR *progid)
223 IInternetHostSecurityManager *secmgr = NULL;
224 struct CONFIRMSAFETY cs;
225 IClassFactoryEx *cfex;
226 IClassFactory *cf;
227 DWORD policy_size;
228 BYTE *bpolicy;
229 IUnknown *obj;
230 DWORD policy;
231 GUID guid;
232 HRESULT hres;
234 hres = CLSIDFromProgID(progid, &guid);
235 if(FAILED(hres))
236 return NULL;
238 TRACE("GUID %s\n", debugstr_guid(&guid));
240 if(ctx->safeopt & INTERFACE_USES_SECURITY_MANAGER) {
241 secmgr = get_sec_mgr(ctx);
242 if(!secmgr)
243 return NULL;
245 policy = 0;
246 hres = IInternetHostSecurityManager_ProcessUrlAction(secmgr, URLACTION_ACTIVEX_RUN,
247 (BYTE*)&policy, sizeof(policy), (BYTE*)&guid, sizeof(GUID), 0, 0);
248 if(FAILED(hres) || policy != URLPOLICY_ALLOW)
249 return NULL;
252 hres = CoGetClassObject(&guid, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void**)&cf);
253 if(FAILED(hres))
254 return NULL;
256 hres = IClassFactory_QueryInterface(cf, &IID_IClassFactoryEx, (void**)&cfex);
257 if(SUCCEEDED(hres)) {
258 FIXME("Use IClassFactoryEx\n");
259 IClassFactoryEx_Release(cfex);
262 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (void**)&obj);
263 if(FAILED(hres))
264 return NULL;
266 if(secmgr) {
267 cs.clsid = guid;
268 cs.pUnk = obj;
269 cs.dwFlags = 0;
270 hres = IInternetHostSecurityManager_QueryCustomPolicy(secmgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
271 &bpolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
272 if(SUCCEEDED(hres)) {
273 policy = policy_size >= sizeof(DWORD) ? *(DWORD*)bpolicy : URLPOLICY_DISALLOW;
274 CoTaskMemFree(bpolicy);
277 if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
278 IUnknown_Release(obj);
279 return NULL;
283 hres = set_object_site(ctx, obj);
284 if(FAILED(hres)) {
285 IUnknown_Release(obj);
286 return NULL;
289 return obj;
292 static HRESULT show_msgbox(script_ctx_t *ctx, BSTR prompt, unsigned type, BSTR orig_title, VARIANT *res)
294 SCRIPTUICHANDLING uic_handling = SCRIPTUICHANDLING_ALLOW;
295 IActiveScriptSiteUIControl *ui_control;
296 IActiveScriptSiteWindow *acts_window;
297 WCHAR *title_buf = NULL;
298 const WCHAR *title;
299 HWND hwnd = NULL;
300 int ret = 0;
301 HRESULT hres;
303 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IActiveScriptSiteUIControl, (void**)&ui_control);
304 if(SUCCEEDED(hres)) {
305 hres = IActiveScriptSiteUIControl_GetUIBehavior(ui_control, SCRIPTUICITEM_MSGBOX, &uic_handling);
306 IActiveScriptSiteUIControl_Release(ui_control);
307 if(FAILED(hres))
308 uic_handling = SCRIPTUICHANDLING_ALLOW;
311 switch(uic_handling) {
312 case SCRIPTUICHANDLING_ALLOW:
313 break;
314 case SCRIPTUICHANDLING_NOUIDEFAULT:
315 return return_short(res, 0);
316 default:
317 FIXME("blocked\n");
318 return E_FAIL;
321 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IActiveScriptSiteWindow, (void**)&acts_window);
322 if(FAILED(hres)) {
323 FIXME("No IActiveScriptSiteWindow\n");
324 return hres;
327 if(ctx->safeopt & INTERFACE_USES_SECURITY_MANAGER) {
328 if(orig_title && *orig_title) {
329 WCHAR *ptr;
331 title = title_buf = heap_alloc(sizeof(vbscriptW) + (strlenW(orig_title)+2)*sizeof(WCHAR));
332 if(!title)
333 return E_OUTOFMEMORY;
335 memcpy(title_buf, vbscriptW, sizeof(vbscriptW));
336 ptr = title_buf + sizeof(vbscriptW)/sizeof(WCHAR)-1;
338 *ptr++ = ':';
339 *ptr++ = ' ';
340 strcpyW(ptr, orig_title);
341 }else {
342 title = vbscriptW;
344 }else {
345 title = orig_title ? orig_title : emptyW;
348 hres = IActiveScriptSiteWindow_GetWindow(acts_window, &hwnd);
349 if(SUCCEEDED(hres)) {
350 hres = IActiveScriptSiteWindow_EnableModeless(acts_window, FALSE);
351 if(SUCCEEDED(hres)) {
352 ret = MessageBoxW(hwnd, prompt, title, type);
353 hres = IActiveScriptSiteWindow_EnableModeless(acts_window, TRUE);
357 heap_free(title_buf);
358 IActiveScriptSiteWindow_Release(acts_window);
359 if(FAILED(hres)) {
360 FIXME("failed: %08x\n", hres);
361 return hres;
364 return return_short(res, ret);
367 static HRESULT Global_CCur(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
369 VARIANT v;
370 HRESULT hres;
372 TRACE("%s\n", debugstr_variant(arg));
374 assert(args_cnt == 1);
376 V_VT(&v) = VT_EMPTY;
377 hres = VariantChangeType(&v, arg, 0, VT_CY);
378 if(FAILED(hres))
379 return hres;
381 if(!res) {
382 VariantClear(&v);
383 return DISP_E_BADVARTYPE;
386 *res = v;
387 return S_OK;
390 static HRESULT Global_CInt(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
392 VARIANT v;
393 HRESULT hres;
395 TRACE("%s\n", debugstr_variant(arg));
397 assert(args_cnt == 1);
399 V_VT(&v) = VT_EMPTY;
400 hres = VariantChangeType(&v, arg, 0, VT_I2);
401 if(FAILED(hres))
402 return hres;
404 if(!res)
405 return DISP_E_BADVARTYPE;
406 else {
407 *res = v;
408 return S_OK;
412 static HRESULT Global_CLng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
414 int i;
415 HRESULT hres;
417 TRACE("%s\n", debugstr_variant(arg));
419 assert(args_cnt == 1);
421 hres = to_int(arg, &i);
422 if(FAILED(hres))
423 return hres;
424 if(!res)
425 return DISP_E_BADVARTYPE;
427 return return_int(res, i);
430 static HRESULT Global_CBool(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
432 VARIANT v;
433 HRESULT hres;
435 TRACE("%s\n", debugstr_variant(arg));
437 assert(args_cnt == 1);
439 V_VT(&v) = VT_EMPTY;
440 hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_BOOL);
441 if(FAILED(hres))
442 return hres;
444 if(res)
445 *res = v;
446 else
447 VariantClear(&v);
448 return S_OK;
451 static HRESULT Global_CByte(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
453 VARIANT v;
454 HRESULT hres;
456 TRACE("%s\n", debugstr_variant(arg));
458 assert(args_cnt == 1);
460 V_VT(&v) = VT_EMPTY;
461 hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_UI1);
462 if(FAILED(hres))
463 return hres;
465 if(!res) {
466 VariantClear(&v);
467 return DISP_E_BADVARTYPE;
470 *res = v;
471 return S_OK;
474 static HRESULT Global_CDate(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
476 FIXME("\n");
477 return E_NOTIMPL;
480 static HRESULT Global_CDbl(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
482 VARIANT v;
483 HRESULT hres;
485 TRACE("%s\n", debugstr_variant(arg));
487 assert(args_cnt == 1);
489 V_VT(&v) = VT_EMPTY;
490 hres = VariantChangeType(&v, arg, 0, VT_R8);
491 if(FAILED(hres))
492 return hres;
494 if(!res)
495 return DISP_E_BADVARTYPE;
496 else {
497 *res = v;
498 return S_OK;
502 static HRESULT Global_CSng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
504 VARIANT v;
505 HRESULT hres;
507 TRACE("%s\n", debugstr_variant(arg));
509 assert(args_cnt == 1);
511 V_VT(&v) = VT_EMPTY;
512 hres = VariantChangeType(&v, arg, 0, VT_R4);
513 if(FAILED(hres))
514 return hres;
516 if(!res)
517 return DISP_E_BADVARTYPE;
519 *res = v;
520 return S_OK;
523 static HRESULT Global_CStr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
525 BSTR str;
526 HRESULT hres;
528 TRACE("%s\n", debugstr_variant(arg));
530 hres = to_string(arg, &str);
531 if(FAILED(hres))
532 return hres;
534 return return_bstr(res, str);
537 static inline WCHAR hex_char(unsigned n)
539 return n < 10 ? '0'+n : 'A'+n-10;
542 static HRESULT Global_Hex(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
544 WCHAR buf[17], *ptr;
545 DWORD n;
547 TRACE("%s\n", debugstr_variant(arg));
549 switch(V_VT(arg)) {
550 case VT_I2:
551 n = (WORD)V_I2(arg);
552 break;
553 case VT_I4:
554 n = V_I4(arg);
555 break;
556 case VT_EMPTY:
557 n = 0;
558 break;
559 case VT_NULL:
560 if(res)
561 V_VT(res) = VT_NULL;
562 return S_OK;
563 default:
564 FIXME("unsupported type %s\n", debugstr_variant(arg));
565 return E_NOTIMPL;
568 buf[16] = 0;
569 ptr = buf+15;
571 if(n) {
572 do {
573 *ptr-- = hex_char(n & 0xf);
574 n >>= 4;
575 }while(n);
576 ptr++;
577 }else {
578 *ptr = '0';
581 return return_string(res, ptr);
584 static HRESULT Global_Oct(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
586 FIXME("\n");
587 return E_NOTIMPL;
590 static HRESULT Global_VarType(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
592 TRACE("(%s)\n", debugstr_variant(arg));
594 assert(args_cnt == 1);
596 if(V_VT(arg) & ~VT_TYPEMASK) {
597 FIXME("not supported %s\n", debugstr_variant(arg));
598 return E_NOTIMPL;
601 return return_short(res, V_VT(arg));
604 static HRESULT Global_IsDate(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
606 FIXME("\n");
607 return E_NOTIMPL;
610 static HRESULT Global_IsEmpty(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
612 TRACE("(%s)\n", debugstr_variant(arg));
614 assert(args_cnt == 1);
616 if(res) {
617 V_VT(res) = VT_BOOL;
618 V_BOOL(res) = V_VT(arg) == VT_EMPTY ? VARIANT_TRUE : VARIANT_FALSE;
620 return S_OK;
623 static HRESULT Global_IsNull(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
625 TRACE("(%s)\n", debugstr_variant(arg));
627 assert(args_cnt == 1);
629 if(res) {
630 V_VT(res) = VT_BOOL;
631 V_BOOL(res) = V_VT(arg) == VT_NULL ? VARIANT_TRUE : VARIANT_FALSE;
633 return S_OK;
636 static HRESULT Global_IsNumeric(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
638 HRESULT hres;
639 double d;
641 TRACE("(%s)\n", debugstr_variant(arg));
643 assert(args_cnt == 1);
645 hres = to_double(arg, &d);
647 return return_bool(res, SUCCEEDED(hres));
650 static HRESULT Global_IsArray(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
652 FIXME("\n");
653 return E_NOTIMPL;
656 static HRESULT Global_IsObject(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
658 TRACE("(%s)\n", debugstr_variant(arg));
660 assert(args_cnt == 1);
662 if(res) {
663 V_VT(res) = VT_BOOL;
664 V_BOOL(res) = V_VT(arg) == VT_DISPATCH ? VARIANT_TRUE : VARIANT_FALSE;
666 return S_OK;
669 static HRESULT Global_Atn(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
671 HRESULT hres;
672 double d;
674 hres = to_double(arg, &d);
675 if(FAILED(hres))
676 return hres;
678 return return_double(res, atan(d));
681 static HRESULT Global_Cos(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
683 HRESULT hres;
684 double d;
686 hres = to_double(arg, &d);
687 if(FAILED(hres))
688 return hres;
690 return return_double(res, cos(d));
693 static HRESULT Global_Sin(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
695 HRESULT hres;
696 double d;
698 hres = to_double(arg, &d);
699 if(FAILED(hres))
700 return hres;
702 return return_double(res, sin(d));
705 static HRESULT Global_Tan(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
707 HRESULT hres;
708 double d;
710 hres = to_double(arg, &d);
711 if(FAILED(hres))
712 return hres;
714 return return_double(res, tan(d));
717 static HRESULT Global_Exp(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
719 HRESULT hres;
720 double d;
722 hres = to_double(arg, &d);
723 if(FAILED(hres))
724 return hres;
726 return return_double(res, exp(d));
729 static HRESULT Global_Log(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
731 HRESULT hres;
732 double d;
734 hres = to_double(arg, &d);
735 if(FAILED(hres))
736 return hres;
738 if(d <= 0)
739 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
740 else
741 return return_double(res, log(d));
744 static HRESULT Global_Sqr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
746 HRESULT hres;
747 double d;
749 hres = to_double(arg, &d);
750 if(FAILED(hres))
751 return hres;
753 if(d < 0)
754 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
755 else
756 return return_double(res, sqrt(d));
759 static HRESULT Global_Randomize(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
761 FIXME("\n");
762 return E_NOTIMPL;
765 static HRESULT Global_Rnd(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
767 FIXME("\n");
768 return E_NOTIMPL;
771 static HRESULT Global_Timer(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
773 SYSTEMTIME lt;
774 double sec;
776 GetLocalTime(&lt);
777 sec = lt.wHour * 3600 + lt.wMinute * 60 + lt.wSecond + lt.wMilliseconds / 1000.0;
778 return return_float(res, sec);
782 static HRESULT Global_LBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
784 FIXME("\n");
785 return E_NOTIMPL;
788 static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
790 FIXME("\n");
791 return E_NOTIMPL;
794 static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
796 HRESULT hres;
797 int i, color[3];
799 TRACE("%s %s %s\n", debugstr_variant(arg), debugstr_variant(arg + 1), debugstr_variant(arg + 2));
801 assert(args_cnt == 3);
803 for(i = 0; i < 3; i++) {
804 hres = to_int(arg + i, color + i);
805 if(FAILED(hres))
806 return hres;
807 if(color[i] > 255)
808 color[i] = 255;
809 if(color[i] < 0)
810 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
813 return return_int(res, RGB(color[0], color[1], color[2]));
816 static HRESULT Global_Len(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
818 DWORD len;
819 HRESULT hres;
821 TRACE("%s\n", debugstr_variant(arg));
823 if(V_VT(arg) == VT_NULL)
824 return return_null(res);
826 if(V_VT(arg) != VT_BSTR) {
827 BSTR str;
829 hres = to_string(arg, &str);
830 if(FAILED(hres))
831 return hres;
833 len = SysStringLen(str);
834 SysFreeString(str);
835 }else {
836 len = SysStringLen(V_BSTR(arg));
839 return return_int(res, len);
842 static HRESULT Global_LenB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
844 FIXME("\n");
845 return E_NOTIMPL;
848 static HRESULT Global_Left(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
850 BSTR str, ret, conv_str = NULL;
851 int len, str_len;
852 HRESULT hres;
854 TRACE("(%s %s)\n", debugstr_variant(args+1), debugstr_variant(args));
856 if(V_VT(args) == VT_BSTR) {
857 str = V_BSTR(args);
858 }else {
859 hres = to_string(args, &conv_str);
860 if(FAILED(hres))
861 return hres;
862 str = conv_str;
865 hres = to_int(args+1, &len);
866 if(FAILED(hres))
867 return hres;
869 if(len < 0) {
870 FIXME("len = %d\n", len);
871 return E_FAIL;
874 str_len = SysStringLen(str);
875 if(len > str_len)
876 len = str_len;
878 ret = SysAllocStringLen(str, len);
879 SysFreeString(conv_str);
880 if(!ret)
881 return E_OUTOFMEMORY;
883 return return_bstr(res, ret);
886 static HRESULT Global_LeftB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
888 FIXME("\n");
889 return E_NOTIMPL;
892 static HRESULT Global_Right(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
894 BSTR str, ret, conv_str = NULL;
895 int len, str_len;
896 HRESULT hres;
898 TRACE("(%s %s)\n", debugstr_variant(args), debugstr_variant(args+1));
900 if(V_VT(args+1) == VT_BSTR) {
901 str = V_BSTR(args);
902 }else {
903 hres = to_string(args, &conv_str);
904 if(FAILED(hres))
905 return hres;
906 str = conv_str;
909 hres = to_int(args+1, &len);
910 if(FAILED(hres))
911 return hres;
913 if(len < 0) {
914 FIXME("len = %d\n", len);
915 return E_FAIL;
918 str_len = SysStringLen(str);
919 if(len > str_len)
920 len = str_len;
922 ret = SysAllocStringLen(str+str_len-len, len);
923 SysFreeString(conv_str);
924 if(!ret)
925 return E_OUTOFMEMORY;
927 return return_bstr(res, ret);
930 static HRESULT Global_RightB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
932 FIXME("\n");
933 return E_NOTIMPL;
936 static HRESULT Global_Mid(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
938 int len = -1, start, str_len;
939 BSTR str;
940 HRESULT hres;
942 TRACE("(%s %s ...)\n", debugstr_variant(args), debugstr_variant(args+1));
944 assert(args_cnt == 2 || args_cnt == 3);
946 if(V_VT(args) != VT_BSTR) {
947 FIXME("args[0] = %s\n", debugstr_variant(args));
948 return E_NOTIMPL;
951 str = V_BSTR(args);
953 hres = to_int(args+1, &start);
954 if(FAILED(hres))
955 return hres;
957 if(args_cnt == 3) {
958 hres = to_int(args+2, &len);
959 if(FAILED(hres))
960 return hres;
962 if(len < 0) {
963 FIXME("len = %d\n", len);
964 return E_FAIL;
969 str_len = SysStringLen(str);
970 start--;
971 if(start > str_len)
972 start = str_len;
974 if(len == -1)
975 len = str_len-start;
976 else if(len > str_len-start)
977 len = str_len-start;
979 if(res) {
980 V_VT(res) = VT_BSTR;
981 V_BSTR(res) = SysAllocStringLen(str+start, len);
982 if(!V_BSTR(res))
983 return E_OUTOFMEMORY;
986 return S_OK;
989 static HRESULT Global_MidB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
991 FIXME("\n");
992 return E_NOTIMPL;
995 static HRESULT Global_StrComp(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
997 FIXME("\n");
998 return E_NOTIMPL;
1001 static HRESULT Global_LCase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1003 BSTR str;
1004 HRESULT hres;
1006 TRACE("%s\n", debugstr_variant(arg));
1008 if(V_VT(arg) == VT_NULL) {
1009 if(res)
1010 V_VT(res) = VT_NULL;
1011 return S_OK;
1014 hres = to_string(arg, &str);
1015 if(FAILED(hres))
1016 return hres;
1018 if(res) {
1019 WCHAR *ptr;
1021 for(ptr = str; *ptr; ptr++)
1022 *ptr = tolowerW(*ptr);
1024 V_VT(res) = VT_BSTR;
1025 V_BSTR(res) = str;
1026 }else {
1027 SysFreeString(str);
1029 return S_OK;
1032 static HRESULT Global_UCase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1034 BSTR str;
1035 HRESULT hres;
1037 TRACE("%s\n", debugstr_variant(arg));
1039 if(V_VT(arg) == VT_NULL) {
1040 if(res)
1041 V_VT(res) = VT_NULL;
1042 return S_OK;
1045 hres = to_string(arg, &str);
1046 if(FAILED(hres))
1047 return hres;
1049 if(res) {
1050 WCHAR *ptr;
1052 for(ptr = str; *ptr; ptr++)
1053 *ptr = toupperW(*ptr);
1055 V_VT(res) = VT_BSTR;
1056 V_BSTR(res) = str;
1057 }else {
1058 SysFreeString(str);
1060 return S_OK;
1063 static HRESULT Global_LTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1065 BSTR str, conv_str = NULL;
1066 WCHAR *ptr;
1067 HRESULT hres;
1069 TRACE("%s\n", debugstr_variant(arg));
1071 if(V_VT(arg) == VT_BSTR) {
1072 str = V_BSTR(arg);
1073 }else {
1074 hres = to_string(arg, &conv_str);
1075 if(FAILED(hres))
1076 return hres;
1077 str = conv_str;
1080 for(ptr = str; *ptr && isspaceW(*ptr); ptr++);
1082 str = SysAllocString(ptr);
1083 SysFreeString(conv_str);
1084 if(!str)
1085 return E_OUTOFMEMORY;
1087 return return_bstr(res, str);
1090 static HRESULT Global_RTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1092 BSTR str, conv_str = NULL;
1093 WCHAR *ptr;
1094 HRESULT hres;
1096 TRACE("%s\n", debugstr_variant(arg));
1098 if(V_VT(arg) == VT_BSTR) {
1099 str = V_BSTR(arg);
1100 }else {
1101 hres = to_string(arg, &conv_str);
1102 if(FAILED(hres))
1103 return hres;
1104 str = conv_str;
1107 for(ptr = str+SysStringLen(str); ptr-1 > str && isspaceW(*(ptr-1)); ptr--);
1109 str = SysAllocStringLen(str, ptr-str);
1110 SysFreeString(conv_str);
1111 if(!str)
1112 return E_OUTOFMEMORY;
1114 return return_bstr(res, str);
1117 static HRESULT Global_Trim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1119 BSTR str, conv_str = NULL;
1120 WCHAR *begin_ptr, *end_ptr;
1121 HRESULT hres;
1123 TRACE("%s\n", debugstr_variant(arg));
1125 if(V_VT(arg) == VT_BSTR) {
1126 str = V_BSTR(arg);
1127 }else {
1128 hres = to_string(arg, &conv_str);
1129 if(FAILED(hres))
1130 return hres;
1131 str = conv_str;
1134 for(begin_ptr = str; *begin_ptr && isspaceW(*begin_ptr); begin_ptr++);
1135 for(end_ptr = str+SysStringLen(str); end_ptr-1 > begin_ptr && isspaceW(*(end_ptr-1)); end_ptr--);
1137 str = SysAllocStringLen(begin_ptr, end_ptr-begin_ptr);
1138 SysFreeString(conv_str);
1139 if(!str)
1140 return E_OUTOFMEMORY;
1142 return return_bstr(res, str);
1145 static HRESULT Global_Space(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1147 BSTR str;
1148 int n, i;
1149 HRESULT hres;
1151 TRACE("%s\n", debugstr_variant(arg));
1153 hres = to_int(arg, &n);
1154 if(FAILED(hres))
1155 return hres;
1157 if(n < 0) {
1158 FIXME("n = %d\n", n);
1159 return E_NOTIMPL;
1162 if(!res)
1163 return S_OK;
1165 str = SysAllocStringLen(NULL, n);
1166 if(!str)
1167 return E_OUTOFMEMORY;
1169 for(i=0; i<n; i++)
1170 str[i] = ' ';
1172 V_VT(res) = VT_BSTR;
1173 V_BSTR(res) = str;
1174 return S_OK;
1177 static HRESULT Global_String(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1179 FIXME("\n");
1180 return E_NOTIMPL;
1183 static HRESULT Global_InStr(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1185 VARIANT *startv, *str1v, *str2v;
1186 BSTR str1, str2;
1187 int start, ret;
1188 HRESULT hres;
1190 TRACE("\n");
1192 assert(2 <= args_cnt && args_cnt <= 4);
1194 switch(args_cnt) {
1195 case 2:
1196 startv = NULL;
1197 str1v = args;
1198 str2v = args+1;
1199 break;
1200 case 3:
1201 startv = args;
1202 str1v = args+1;
1203 str2v = args+2;
1204 break;
1205 case 4:
1206 FIXME("unsupported compare argument %s\n", debugstr_variant(args));
1207 return E_NOTIMPL;
1208 DEFAULT_UNREACHABLE;
1211 if(startv) {
1212 hres = to_int(startv, &start);
1213 if(FAILED(hres))
1214 return hres;
1215 if(--start < 0) {
1216 FIXME("start %d\n", start);
1217 return E_FAIL;
1219 }else {
1220 start = 0;
1223 if(V_VT(str1v) == VT_NULL || V_VT(str2v) == VT_NULL)
1224 return return_null(res);
1226 if(V_VT(str1v) != VT_BSTR) {
1227 FIXME("Unsupported str1 type %s\n", debugstr_variant(str1v));
1228 return E_NOTIMPL;
1230 str1 = V_BSTR(str1v);
1232 if(V_VT(str2v) != VT_BSTR) {
1233 FIXME("Unsupported str2 type %s\n", debugstr_variant(str2v));
1234 return E_NOTIMPL;
1236 str2 = V_BSTR(str2v);
1238 if(start < SysStringLen(str1)) {
1239 WCHAR *ptr;
1241 ptr = strstrW(str1+start, str2);
1242 ret = ptr ? ptr-str1+1 : 0;
1243 }else {
1244 ret = 0;
1247 return return_int(res, ret);
1250 static HRESULT Global_InStrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1252 FIXME("\n");
1253 return E_NOTIMPL;
1256 static HRESULT Global_AscB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1258 FIXME("\n");
1259 return E_NOTIMPL;
1262 static HRESULT Global_ChrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1264 FIXME("\n");
1265 return E_NOTIMPL;
1268 static HRESULT Global_Asc(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1270 FIXME("\n");
1271 return E_NOTIMPL;
1274 /* The function supports only single-byte and double-byte character sets. It
1275 * ignores language specified by IActiveScriptSite::GetLCID. The argument needs
1276 * to be in range of short or unsigned short. */
1277 static HRESULT Global_Chr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1279 int cp, c, len = 0;
1280 CPINFO cpi;
1281 WCHAR ch;
1282 char buf[2];
1283 HRESULT hres;
1285 TRACE("%s\n", debugstr_variant(arg));
1287 hres = to_int(arg, &c);
1288 if(FAILED(hres))
1289 return hres;
1291 cp = GetACP();
1292 if(!GetCPInfo(cp, &cpi))
1293 cpi.MaxCharSize = 1;
1295 if((c!=(short)c && c!=(unsigned short)c) ||
1296 (unsigned short)c>=(cpi.MaxCharSize>1 ? 0x10000 : 0x100)) {
1297 WARN("invalid arg %d\n", c);
1298 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
1301 if(c>>8)
1302 buf[len++] = c>>8;
1303 if(!len || IsDBCSLeadByteEx(cp, buf[0]))
1304 buf[len++] = c;
1305 if(!MultiByteToWideChar(0, 0, buf, len, &ch, 1)) {
1306 WARN("invalid arg %d, cp %d\n", c, cp);
1307 return E_FAIL;
1310 if(res) {
1311 V_VT(res) = VT_BSTR;
1312 V_BSTR(res) = SysAllocStringLen(&ch, 1);
1313 if(!V_BSTR(res))
1314 return E_OUTOFMEMORY;
1316 return S_OK;
1319 static HRESULT Global_AscW(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1321 FIXME("\n");
1322 return E_NOTIMPL;
1325 static HRESULT Global_ChrW(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1327 FIXME("\n");
1328 return E_NOTIMPL;
1331 static HRESULT Global_Abs(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1333 HRESULT hres;
1334 VARIANT dst;
1336 TRACE("(%s)\n", debugstr_variant(arg));
1338 assert(args_cnt == 1);
1340 hres = VarAbs(arg, &dst);
1341 if(FAILED(hres))
1342 return hres;
1344 if (res)
1345 *res = dst;
1346 else
1347 VariantClear(&dst);
1349 return S_OK;
1352 static HRESULT Global_Fix(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1354 HRESULT hres;
1355 VARIANT dst;
1357 TRACE("(%s)\n", debugstr_variant(arg));
1359 assert(args_cnt == 1);
1361 hres = VarFix(arg, &dst);
1362 if(FAILED(hres))
1363 return hres;
1365 if (res)
1366 *res = dst;
1367 else
1368 VariantClear(&dst);
1370 return S_OK;
1373 static HRESULT Global_Int(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1375 HRESULT hres;
1376 VARIANT dst;
1378 TRACE("(%s)\n", debugstr_variant(arg));
1380 assert(args_cnt == 1);
1382 hres = VarInt(arg, &dst);
1383 if(FAILED(hres))
1384 return hres;
1386 if (res)
1387 *res = dst;
1388 else
1389 VariantClear(&dst);
1391 return S_OK;
1394 static HRESULT Global_Sgn(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1396 double v;
1397 short val;
1398 HRESULT hres;
1400 TRACE("(%s)\n", debugstr_variant(arg));
1402 assert(args_cnt == 1);
1404 if(V_VT(arg) == VT_NULL)
1405 return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
1407 hres = to_double(arg, &v);
1408 if (FAILED(hres))
1409 return hres;
1411 val = v == 0 ? 0 : (v > 0 ? 1 : -1);
1412 return return_short(res, val);
1415 static HRESULT Global_Now(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1417 SYSTEMTIME lt;
1418 double date;
1420 TRACE("\n");
1422 GetLocalTime(&lt);
1423 SystemTimeToVariantTime(&lt, &date);
1424 return return_date(res, date);
1427 static HRESULT Global_Date(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1429 SYSTEMTIME lt;
1430 UDATE ud;
1431 DATE date;
1432 HRESULT hres;
1434 TRACE("\n");
1436 GetLocalTime(&lt);
1437 ud.st = lt;
1438 ud.wDayOfYear = 0;
1439 hres = VarDateFromUdateEx(&ud, 0, VAR_DATEVALUEONLY, &date);
1440 if(FAILED(hres))
1441 return hres;
1442 return return_date(res, date);
1445 static HRESULT Global_Time(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1447 SYSTEMTIME lt;
1448 UDATE ud;
1449 DATE time;
1450 HRESULT hres;
1452 TRACE("\n");
1454 GetLocalTime(&lt);
1455 ud.st = lt;
1456 ud.wDayOfYear = 0;
1457 hres = VarDateFromUdateEx(&ud, 0, VAR_TIMEVALUEONLY, &time);
1458 if(FAILED(hres))
1459 return hres;
1460 return return_date(res, time);
1463 static HRESULT Global_Day(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1465 FIXME("\n");
1466 return E_NOTIMPL;
1469 static HRESULT Global_Month(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1471 FIXME("\n");
1472 return E_NOTIMPL;
1475 static HRESULT Global_Weekday(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1477 FIXME("\n");
1478 return E_NOTIMPL;
1481 static HRESULT Global_Year(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1483 FIXME("\n");
1484 return E_NOTIMPL;
1487 static HRESULT Global_Hour(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1489 FIXME("\n");
1490 return E_NOTIMPL;
1493 static HRESULT Global_Minute(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1495 FIXME("\n");
1496 return E_NOTIMPL;
1499 static HRESULT Global_Second(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1501 FIXME("\n");
1502 return E_NOTIMPL;
1505 static HRESULT Global_DateValue(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1507 FIXME("\n");
1508 return E_NOTIMPL;
1511 static HRESULT Global_TimeValue(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1513 FIXME("\n");
1514 return E_NOTIMPL;
1517 static HRESULT Global_DateSerial(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1519 FIXME("\n");
1520 return E_NOTIMPL;
1523 static HRESULT Global_TimeSerial(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1525 FIXME("\n");
1526 return E_NOTIMPL;
1529 static HRESULT Global_InputBox(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1531 FIXME("\n");
1532 return E_NOTIMPL;
1535 static HRESULT Global_MsgBox(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1537 BSTR prompt, title = NULL;
1538 int type = MB_OK;
1539 HRESULT hres;
1541 TRACE("\n");
1543 assert(1 <= args_cnt && args_cnt <= 5);
1545 hres = to_string(args, &prompt);
1546 if(FAILED(hres))
1547 return hres;
1549 if(args_cnt > 1)
1550 hres = to_int(args+1, &type);
1552 if(SUCCEEDED(hres) && args_cnt > 2)
1553 hres = to_string(args+2, &title);
1555 if(SUCCEEDED(hres) && args_cnt > 3) {
1556 FIXME("unsupported arg_cnt %d\n", args_cnt);
1557 hres = E_NOTIMPL;
1560 if(SUCCEEDED(hres))
1561 hres = show_msgbox(This->desc->ctx, prompt, type, title, res);
1563 SysFreeString(prompt);
1564 SysFreeString(title);
1565 return hres;
1568 static HRESULT Global_CreateObject(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1570 IUnknown *obj;
1571 HRESULT hres;
1573 TRACE("(%s)\n", debugstr_variant(arg));
1575 if(V_VT(arg) != VT_BSTR) {
1576 FIXME("non-bstr arg\n");
1577 return E_INVALIDARG;
1580 obj = create_object(This->desc->ctx, V_BSTR(arg));
1581 if(!obj)
1582 return VB_E_CANNOT_CREATE_OBJ;
1584 if(res) {
1585 hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&V_DISPATCH(res));
1586 if(FAILED(hres))
1587 return hres;
1589 V_VT(res) = VT_DISPATCH;
1592 IUnknown_Release(obj);
1593 return S_OK;
1596 static HRESULT Global_GetObject(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1598 IBindCtx *bind_ctx;
1599 IUnknown *obj_unk;
1600 IDispatch *disp;
1601 ULONG eaten = 0;
1602 IMoniker *mon;
1603 HRESULT hres;
1605 TRACE("%s %s\n", args_cnt ? debugstr_variant(args) : "", args_cnt > 1 ? debugstr_variant(args+1) : "");
1607 if(args_cnt != 1 || V_VT(args) != VT_BSTR) {
1608 FIXME("unsupported args\n");
1609 return E_NOTIMPL;
1612 if(This->desc->ctx->safeopt & (INTERFACE_USES_SECURITY_MANAGER|INTERFACESAFE_FOR_UNTRUSTED_DATA)) {
1613 WARN("blocked in current safety mode\n");
1614 return VB_E_CANNOT_CREATE_OBJ;
1617 hres = CreateBindCtx(0, &bind_ctx);
1618 if(FAILED(hres))
1619 return hres;
1621 hres = MkParseDisplayName(bind_ctx, V_BSTR(args), &eaten, &mon);
1622 if(SUCCEEDED(hres)) {
1623 hres = IMoniker_BindToObject(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&obj_unk);
1624 IMoniker_Release(mon);
1625 }else {
1626 hres = MK_E_SYNTAX;
1628 IBindCtx_Release(bind_ctx);
1629 if(FAILED(hres))
1630 return hres;
1632 hres = set_object_site(This->desc->ctx, obj_unk);
1633 if(FAILED(hres)) {
1634 IUnknown_Release(obj_unk);
1635 return hres;
1638 hres = IUnknown_QueryInterface(obj_unk, &IID_IDispatch, (void**)&disp);
1639 if(SUCCEEDED(hres)) {
1640 if(res) {
1641 V_VT(res) = VT_DISPATCH;
1642 V_DISPATCH(res) = disp;
1643 }else {
1644 IDispatch_Release(disp);
1646 }else {
1647 FIXME("object does not support IDispatch\n");
1650 return hres;
1653 static HRESULT Global_DateAdd(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1655 FIXME("\n");
1656 return E_NOTIMPL;
1659 static HRESULT Global_DateDiff(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1661 FIXME("\n");
1662 return E_NOTIMPL;
1665 static HRESULT Global_DatePart(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1667 FIXME("\n");
1668 return E_NOTIMPL;
1671 static HRESULT Global_TypeName(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1673 static const WCHAR ByteW[] = {'B', 'y', 't', 'e', 0};
1674 static const WCHAR IntegerW[] = {'I', 'n', 't', 'e', 'g', 'e', 'r', 0};
1675 static const WCHAR LongW[] = {'L', 'o', 'n', 'g', 0};
1676 static const WCHAR SingleW[] = {'S', 'i', 'n', 'g', 'l', 'e', 0};
1677 static const WCHAR DoubleW[] = {'D', 'o', 'u', 'b', 'l', 'e', 0};
1678 static const WCHAR CurrencyW[] = {'C', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 0};
1679 static const WCHAR DecimalW[] = {'D', 'e', 'c', 'i', 'm', 'a', 'l', 0};
1680 static const WCHAR DateW[] = {'D', 'a', 't', 'e', 0};
1681 static const WCHAR StringW[] = {'S', 't', 'r', 'i', 'n', 'g', 0};
1682 static const WCHAR BooleanW[] = {'B', 'o', 'o', 'l', 'e', 'a', 'n', 0};
1683 static const WCHAR EmptyW[] = {'E', 'm', 'p', 't', 'y', 0};
1684 static const WCHAR NullW[] = {'N', 'u', 'l', 'l', 0};
1686 TRACE("(%s)\n", debugstr_variant(arg));
1688 assert(args_cnt == 1);
1690 switch(V_VT(arg)) {
1691 case VT_UI1:
1692 return return_string(res, ByteW);
1693 case VT_I2:
1694 return return_string(res, IntegerW);
1695 case VT_I4:
1696 return return_string(res, LongW);
1697 case VT_R4:
1698 return return_string(res, SingleW);
1699 case VT_R8:
1700 return return_string(res, DoubleW);
1701 case VT_CY:
1702 return return_string(res, CurrencyW);
1703 case VT_DECIMAL:
1704 return return_string(res, DecimalW);
1705 case VT_DATE:
1706 return return_string(res, DateW);
1707 case VT_BSTR:
1708 return return_string(res, StringW);
1709 case VT_BOOL:
1710 return return_string(res, BooleanW);
1711 case VT_EMPTY:
1712 return return_string(res, EmptyW);
1713 case VT_NULL:
1714 return return_string(res, NullW);
1715 default:
1716 FIXME("arg %s not supported\n", debugstr_variant(arg));
1717 return E_NOTIMPL;
1721 static HRESULT Global_Array(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1723 FIXME("\n");
1724 return E_NOTIMPL;
1727 static HRESULT Global_Erase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1729 FIXME("\n");
1730 return E_NOTIMPL;
1733 static HRESULT Global_Filter(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1735 FIXME("\n");
1736 return E_NOTIMPL;
1739 static HRESULT Global_Join(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1741 FIXME("\n");
1742 return E_NOTIMPL;
1745 static HRESULT Global_Split(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1747 FIXME("\n");
1748 return E_NOTIMPL;
1751 static HRESULT Global_Replace(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1753 FIXME("\n");
1754 return E_NOTIMPL;
1757 static HRESULT Global_StrReverse(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1759 WCHAR *ptr1, *ptr2, ch;
1760 BSTR ret;
1761 HRESULT hres;
1763 TRACE("%s\n", debugstr_variant(arg));
1765 hres = to_string(arg, &ret);
1766 if(FAILED(hres))
1767 return hres;
1769 ptr1 = ret;
1770 ptr2 = ret + SysStringLen(ret)-1;
1771 while(ptr1 < ptr2) {
1772 ch = *ptr1;
1773 *ptr1++ = *ptr2;
1774 *ptr2-- = ch;
1777 return return_bstr(res, ret);
1780 static HRESULT Global_InStrRev(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1782 FIXME("\n");
1783 return E_NOTIMPL;
1786 static HRESULT Global_LoadPicture(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1788 FIXME("\n");
1789 return E_NOTIMPL;
1792 static HRESULT Global_ScriptEngine(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1794 TRACE("%s\n", debugstr_variant(arg));
1796 assert(args_cnt == 0);
1798 return return_string(res, vbscriptW);
1801 static HRESULT Global_ScriptEngineMajorVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1803 TRACE("%s\n", debugstr_variant(arg));
1805 assert(args_cnt == 0);
1807 return return_int(res, VBSCRIPT_MAJOR_VERSION);
1810 static HRESULT Global_ScriptEngineMinorVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1812 TRACE("%s\n", debugstr_variant(arg));
1814 assert(args_cnt == 0);
1816 return return_int(res, VBSCRIPT_MINOR_VERSION);
1819 static HRESULT Global_ScriptEngineBuildVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1821 TRACE("%s\n", debugstr_variant(arg));
1823 assert(args_cnt == 0);
1825 return return_int(res, VBSCRIPT_BUILD_VERSION);
1828 static HRESULT Global_FormatNumber(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1830 FIXME("\n");
1831 return E_NOTIMPL;
1834 static HRESULT Global_FormatCurrency(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1836 FIXME("\n");
1837 return E_NOTIMPL;
1840 static HRESULT Global_FormatPercent(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1842 FIXME("\n");
1843 return E_NOTIMPL;
1846 static HRESULT Global_FormatDateTime(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1848 FIXME("\n");
1849 return E_NOTIMPL;
1852 static HRESULT Global_WeekdayName(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1854 int weekday, first_day = 1, abbrev = 0;
1855 BSTR ret;
1856 HRESULT hres;
1858 TRACE("\n");
1860 assert(1 <= args_cnt && args_cnt <= 3);
1862 hres = to_int(args, &weekday);
1863 if(FAILED(hres))
1864 return hres;
1866 if(args_cnt > 1) {
1867 hres = to_int(args+1, &abbrev);
1868 if(FAILED(hres))
1869 return hres;
1871 if(args_cnt == 3) {
1872 hres = to_int(args+2, &first_day);
1873 if(FAILED(hres))
1874 return hres;
1878 hres = VarWeekdayName(weekday, abbrev, first_day, 0, &ret);
1879 if(FAILED(hres))
1880 return hres;
1882 return return_bstr(res, ret);
1885 static HRESULT Global_MonthName(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1887 int month, abbrev = 0;
1888 BSTR ret;
1889 HRESULT hres;
1891 TRACE("\n");
1893 assert(args_cnt == 1 || args_cnt == 2);
1895 hres = to_int(args, &month);
1896 if(FAILED(hres))
1897 return hres;
1899 if(args_cnt == 2) {
1900 hres = to_int(args+1, &abbrev);
1901 if(FAILED(hres))
1902 return hres;
1905 hres = VarMonthName(month, abbrev, 0, &ret);
1906 if(FAILED(hres))
1907 return hres;
1909 return return_bstr(res, ret);
1912 static HRESULT Global_Round(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1914 double n;
1915 HRESULT hres;
1917 TRACE("%s\n", debugstr_variant(arg));
1919 if(!res)
1920 return S_OK;
1922 switch(V_VT(arg)) {
1923 case VT_I2:
1924 case VT_I4:
1925 case VT_BOOL:
1926 *res = *arg;
1927 return S_OK;
1928 case VT_R8:
1929 n = V_R8(arg);
1930 break;
1931 default:
1932 hres = to_double(arg, &n);
1933 if(FAILED(hres))
1934 return hres;
1937 return return_double(res, round(n));
1940 static HRESULT Global_Escape(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1942 FIXME("\n");
1943 return E_NOTIMPL;
1946 static HRESULT Global_Unescape(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1948 FIXME("\n");
1949 return E_NOTIMPL;
1952 static HRESULT Global_Eval(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1954 FIXME("\n");
1955 return E_NOTIMPL;
1958 static HRESULT Global_Execute(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1960 FIXME("\n");
1961 return E_NOTIMPL;
1964 static HRESULT Global_ExecuteGlobal(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1966 FIXME("\n");
1967 return E_NOTIMPL;
1970 static HRESULT Global_GetRef(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1972 FIXME("\n");
1973 return E_NOTIMPL;
1976 static const string_constant_t vbCr = {1, {'\r'}};
1977 static const string_constant_t vbCrLf = {2, {'\r','\n'}};
1978 static const string_constant_t vbNewLine = {2, {'\r','\n'}};
1979 static const string_constant_t vbFormFeed = {1, {0xc}};
1980 static const string_constant_t vbLf = {1, {'\n'}};
1981 static const string_constant_t vbNullChar = {1};
1982 static const string_constant_t vbNullString = {0};
1983 static const string_constant_t vbTab = {1, {'\t'}};
1984 static const string_constant_t vbVerticalTab = {1, {0xb}};
1986 static const builtin_prop_t global_props[] = {
1987 {DISPID_GLOBAL_VBUSESYSTEM, NULL, BP_GET, VT_I2, 0},
1988 {DISPID_GLOBAL_USESYSTEMDAYOFWEEK, NULL, BP_GET, VT_I2, 0},
1989 {DISPID_GLOBAL_VBSUNDAY, NULL, BP_GET, VT_I2, 1},
1990 {DISPID_GLOBAL_VBMONDAY, NULL, BP_GET, VT_I2, 2},
1991 {DISPID_GLOBAL_VBTUESDAY, NULL, BP_GET, VT_I2, 3},
1992 {DISPID_GLOBAL_VBWEDNESDAY, NULL, BP_GET, VT_I2, 4},
1993 {DISPID_GLOBAL_VBTHURSDAY, NULL, BP_GET, VT_I2, 5},
1994 {DISPID_GLOBAL_VBFRIDAY, NULL, BP_GET, VT_I2, 6},
1995 {DISPID_GLOBAL_VBSATURDAY, NULL, BP_GET, VT_I2, 7},
1996 {DISPID_GLOBAL_VBFIRSTJAN1, NULL, BP_GET, VT_I2, 1},
1997 {DISPID_GLOBAL_VBFIRSTFOURDAYS, NULL, BP_GET, VT_I2, 2},
1998 {DISPID_GLOBAL_VBFIRSTFULLWEEK, NULL, BP_GET, VT_I2, 3},
1999 {DISPID_GLOBAL_VBOKONLY, NULL, BP_GET, VT_I2, MB_OK},
2000 {DISPID_GLOBAL_VBOKCANCEL, NULL, BP_GET, VT_I2, MB_OKCANCEL},
2001 {DISPID_GLOBAL_VBABORTRETRYIGNORE, NULL, BP_GET, VT_I2, MB_ABORTRETRYIGNORE},
2002 {DISPID_GLOBAL_VBYESNOCANCEL, NULL, BP_GET, VT_I2, MB_YESNOCANCEL},
2003 {DISPID_GLOBAL_VBYESNO, NULL, BP_GET, VT_I2, MB_YESNO},
2004 {DISPID_GLOBAL_VBRETRYCANCEL, NULL, BP_GET, VT_I2, MB_RETRYCANCEL},
2005 {DISPID_GLOBAL_VBCRITICAL, NULL, BP_GET, VT_I2, MB_ICONHAND},
2006 {DISPID_GLOBAL_VBQUESTION, NULL, BP_GET, VT_I2, MB_ICONQUESTION},
2007 {DISPID_GLOBAL_VBEXCLAMATION, NULL, BP_GET, VT_I2, MB_ICONEXCLAMATION},
2008 {DISPID_GLOBAL_VBINFORMATION, NULL, BP_GET, VT_I2, MB_ICONASTERISK},
2009 {DISPID_GLOBAL_VBDEFAULTBUTTON1, NULL, BP_GET, VT_I2, MB_DEFBUTTON1},
2010 {DISPID_GLOBAL_VBDEFAULTBUTTON2, NULL, BP_GET, VT_I2, MB_DEFBUTTON2},
2011 {DISPID_GLOBAL_VBDEFAULTBUTTON3, NULL, BP_GET, VT_I2, MB_DEFBUTTON3},
2012 {DISPID_GLOBAL_VBDEFAULTBUTTON4, NULL, BP_GET, VT_I2, MB_DEFBUTTON4},
2013 {DISPID_GLOBAL_VBAPPLICATIONMODAL, NULL, BP_GET, VT_I2, MB_APPLMODAL},
2014 {DISPID_GLOBAL_VBSYSTEMMODAL, NULL, BP_GET, VT_I2, MB_SYSTEMMODAL},
2015 {DISPID_GLOBAL_VBOK, NULL, BP_GET, VT_I2, IDOK},
2016 {DISPID_GLOBAL_VBCANCEL, NULL, BP_GET, VT_I2, IDCANCEL},
2017 {DISPID_GLOBAL_VBABORT, NULL, BP_GET, VT_I2, IDABORT},
2018 {DISPID_GLOBAL_VBRETRY, NULL, BP_GET, VT_I2, IDRETRY},
2019 {DISPID_GLOBAL_VBIGNORE, NULL, BP_GET, VT_I2, IDIGNORE},
2020 {DISPID_GLOBAL_VBYES, NULL, BP_GET, VT_I2, IDYES},
2021 {DISPID_GLOBAL_VBNO, NULL, BP_GET, VT_I2, IDNO},
2022 {DISPID_GLOBAL_VBEMPTY, NULL, BP_GET, VT_I2, VT_EMPTY},
2023 {DISPID_GLOBAL_VBNULL, NULL, BP_GET, VT_I2, VT_NULL},
2024 {DISPID_GLOBAL_VBINTEGER, NULL, BP_GET, VT_I2, VT_I2},
2025 {DISPID_GLOBAL_VBLONG, NULL, BP_GET, VT_I2, VT_I4},
2026 {DISPID_GLOBAL_VBSINGLE, NULL, BP_GET, VT_I2, VT_R4},
2027 {DISPID_GLOBAL_VBDOUBLE, NULL, BP_GET, VT_I2, VT_R8},
2028 {DISPID_GLOBAL_VBCURRENCY, NULL, BP_GET, VT_I2, VT_CY},
2029 {DISPID_GLOBAL_VBDATE, NULL, BP_GET, VT_I2, VT_DATE},
2030 {DISPID_GLOBAL_VBSTRING, NULL, BP_GET, VT_I2, VT_BSTR},
2031 {DISPID_GLOBAL_VBOBJECT, NULL, BP_GET, VT_I2, VT_DISPATCH},
2032 {DISPID_GLOBAL_VBERROR, NULL, BP_GET, VT_I2, VT_ERROR},
2033 {DISPID_GLOBAL_VBBOOLEAN, NULL, BP_GET, VT_I2, VT_BOOL},
2034 {DISPID_GLOBAL_VBVARIANT, NULL, BP_GET, VT_I2, VT_VARIANT},
2035 {DISPID_GLOBAL_VBDATAOBJECT, NULL, BP_GET, VT_I2, VT_UNKNOWN},
2036 {DISPID_GLOBAL_VBDECIMAL, NULL, BP_GET, VT_I2, VT_DECIMAL},
2037 {DISPID_GLOBAL_VBBYTE, NULL, BP_GET, VT_I2, VT_UI1},
2038 {DISPID_GLOBAL_VBARRAY, NULL, BP_GET, VT_I2, VT_ARRAY},
2039 {DISPID_GLOBAL_VBTRUE, NULL, BP_GET, VT_I2, VARIANT_TRUE},
2040 {DISPID_GLOBAL_VBFALSE, NULL, BP_GET, VT_I2, VARIANT_FALSE},
2041 {DISPID_GLOBAL_VBUSEDEFAULT, NULL, BP_GET, VT_I2, -2},
2042 {DISPID_GLOBAL_VBBINARYCOMPARE, NULL, BP_GET, VT_I2, 0},
2043 {DISPID_GLOBAL_VBTEXTCOMPARE, NULL, BP_GET, VT_I2, 1},
2044 {DISPID_GLOBAL_VBDATABASECOMPARE, NULL, BP_GET, VT_I2, 2},
2045 {DISPID_GLOBAL_VBGENERALDATE, NULL, BP_GET, VT_I2, 0},
2046 {DISPID_GLOBAL_VBLONGDATE, NULL, BP_GET, VT_I2, 1},
2047 {DISPID_GLOBAL_VBSHORTDATE, NULL, BP_GET, VT_I2, 2},
2048 {DISPID_GLOBAL_VBLONGTIME, NULL, BP_GET, VT_I2, 3},
2049 {DISPID_GLOBAL_VBSHORTTIME, NULL, BP_GET, VT_I2, 4},
2050 {DISPID_GLOBAL_VBOBJECTERROR, NULL, BP_GET, VT_I4, 0x80040000},
2051 {DISPID_GLOBAL_VBBLACK, NULL, BP_GET, VT_I4, 0x000000},
2052 {DISPID_GLOBAL_VBBLUE, NULL, BP_GET, VT_I4, 0xff0000},
2053 {DISPID_GLOBAL_VBCYAN, NULL, BP_GET, VT_I4, 0xffff00},
2054 {DISPID_GLOBAL_VBGREEN, NULL, BP_GET, VT_I4, 0x00ff00},
2055 {DISPID_GLOBAL_VBMAGENTA, NULL, BP_GET, VT_I4, 0xff00ff},
2056 {DISPID_GLOBAL_VBRED, NULL, BP_GET, VT_I4, 0x0000ff},
2057 {DISPID_GLOBAL_VBWHITE, NULL, BP_GET, VT_I4, 0xffffff},
2058 {DISPID_GLOBAL_VBYELLOW, NULL, BP_GET, VT_I4, 0x00ffff},
2059 {DISPID_GLOBAL_VBCR, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbCr},
2060 {DISPID_GLOBAL_VBCRLF, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbCrLf},
2061 {DISPID_GLOBAL_VBNEWLINE, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNewLine},
2062 {DISPID_GLOBAL_VBFORMFEED, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbFormFeed},
2063 {DISPID_GLOBAL_VBLF, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbLf},
2064 {DISPID_GLOBAL_VBNULLCHAR, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNullChar},
2065 {DISPID_GLOBAL_VBNULLSTRING, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNullString},
2066 {DISPID_GLOBAL_VBTAB, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbTab},
2067 {DISPID_GLOBAL_VBVERTICALTAB, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbVerticalTab},
2068 {DISPID_GLOBAL_CCUR, Global_CCur, 0, 1},
2069 {DISPID_GLOBAL_CINT, Global_CInt, 0, 1},
2070 {DISPID_GLOBAL_CLNG, Global_CLng, 0, 1},
2071 {DISPID_GLOBAL_CBOOL, Global_CBool, 0, 1},
2072 {DISPID_GLOBAL_CBYTE, Global_CByte, 0, 1},
2073 {DISPID_GLOBAL_CDATE, Global_CDate, 0, 1},
2074 {DISPID_GLOBAL_CDBL, Global_CDbl, 0, 1},
2075 {DISPID_GLOBAL_CSNG, Global_CSng, 0, 1},
2076 {DISPID_GLOBAL_CSTR, Global_CStr, 0, 1},
2077 {DISPID_GLOBAL_HEX, Global_Hex, 0, 1},
2078 {DISPID_GLOBAL_OCT, Global_Oct, 0, 1},
2079 {DISPID_GLOBAL_VARTYPE, Global_VarType, 0, 1},
2080 {DISPID_GLOBAL_ISDATE, Global_IsDate, 0, 1},
2081 {DISPID_GLOBAL_ISEMPTY, Global_IsEmpty, 0, 1},
2082 {DISPID_GLOBAL_ISNULL, Global_IsNull, 0, 1},
2083 {DISPID_GLOBAL_ISNUMERIC, Global_IsNumeric, 0, 1},
2084 {DISPID_GLOBAL_ISARRAY, Global_IsArray, 0, 1},
2085 {DISPID_GLOBAL_ISOBJECT, Global_IsObject, 0, 1},
2086 {DISPID_GLOBAL_ATN, Global_Atn, 0, 1},
2087 {DISPID_GLOBAL_COS, Global_Cos, 0, 1},
2088 {DISPID_GLOBAL_SIN, Global_Sin, 0, 1},
2089 {DISPID_GLOBAL_TAN, Global_Tan, 0, 1},
2090 {DISPID_GLOBAL_EXP, Global_Exp, 0, 1},
2091 {DISPID_GLOBAL_LOG, Global_Log, 0, 1},
2092 {DISPID_GLOBAL_SQR, Global_Sqr, 0, 1},
2093 {DISPID_GLOBAL_RANDOMIZE, Global_Randomize, 0, 1},
2094 {DISPID_GLOBAL_RND, Global_Rnd, 0, 1},
2095 {DISPID_GLOBAL_TIMER, Global_Timer, 0, 0},
2096 {DISPID_GLOBAL_LBOUND, Global_LBound, 0, 1},
2097 {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1},
2098 {DISPID_GLOBAL_RGB, Global_RGB, 0, 3},
2099 {DISPID_GLOBAL_LEN, Global_Len, 0, 1},
2100 {DISPID_GLOBAL_LENB, Global_LenB, 0, 1},
2101 {DISPID_GLOBAL_LEFT, Global_Left, 0, 2},
2102 {DISPID_GLOBAL_LEFTB, Global_LeftB, 0, 2},
2103 {DISPID_GLOBAL_RIGHT, Global_Right, 0, 2},
2104 {DISPID_GLOBAL_RIGHTB, Global_RightB, 0, 2},
2105 {DISPID_GLOBAL_MID, Global_Mid, 0, 2, 3},
2106 {DISPID_GLOBAL_MIDB, Global_MidB, 0, 2, 3},
2107 {DISPID_GLOBAL_STRCOMP, Global_StrComp, 0, 2, 3},
2108 {DISPID_GLOBAL_LCASE, Global_LCase, 0, 1},
2109 {DISPID_GLOBAL_UCASE, Global_UCase, 0, 1},
2110 {DISPID_GLOBAL_LTRIM, Global_LTrim, 0, 1},
2111 {DISPID_GLOBAL_RTRIM, Global_RTrim, 0, 1},
2112 {DISPID_GLOBAL_TRIM, Global_Trim, 0, 1},
2113 {DISPID_GLOBAL_SPACE, Global_Space, 0, 1},
2114 {DISPID_GLOBAL_STRING, Global_String, 0, 0, 2},
2115 {DISPID_GLOBAL_INSTR, Global_InStr, 0, 2, 4},
2116 {DISPID_GLOBAL_INSTRB, Global_InStrB, 0, 3, 4},
2117 {DISPID_GLOBAL_ASCB, Global_AscB, 0, 1},
2118 {DISPID_GLOBAL_CHRB, Global_ChrB, 0, 1},
2119 {DISPID_GLOBAL_ASC, Global_Asc, 0, 1},
2120 {DISPID_GLOBAL_CHR, Global_Chr, 0, 1},
2121 {DISPID_GLOBAL_ASCW, Global_AscW, 0, 1},
2122 {DISPID_GLOBAL_CHRW, Global_ChrW, 0, 1},
2123 {DISPID_GLOBAL_ABS, Global_Abs, 0, 1},
2124 {DISPID_GLOBAL_FIX, Global_Fix, 0, 1},
2125 {DISPID_GLOBAL_INT, Global_Int, 0, 1},
2126 {DISPID_GLOBAL_SGN, Global_Sgn, 0, 1},
2127 {DISPID_GLOBAL_NOW, Global_Now, 0, 0},
2128 {DISPID_GLOBAL_DATE, Global_Date, 0, 0},
2129 {DISPID_GLOBAL_TIME, Global_Time, 0, 0},
2130 {DISPID_GLOBAL_DAY, Global_Day, 0, 1},
2131 {DISPID_GLOBAL_MONTH, Global_Month, 0, 1},
2132 {DISPID_GLOBAL_WEEKDAY, Global_Weekday, 0, 1, 2},
2133 {DISPID_GLOBAL_YEAR, Global_Year, 0, 1},
2134 {DISPID_GLOBAL_HOUR, Global_Hour, 0, 1},
2135 {DISPID_GLOBAL_MINUTE, Global_Minute, 0, 1},
2136 {DISPID_GLOBAL_SECOND, Global_Second, 0, 1},
2137 {DISPID_GLOBAL_DATEVALUE, Global_DateValue, 0, 1},
2138 {DISPID_GLOBAL_TIMEVALUE, Global_TimeValue, 0, 1},
2139 {DISPID_GLOBAL_DATESERIAL, Global_DateSerial, 0, 3},
2140 {DISPID_GLOBAL_TIMESERIAL, Global_TimeSerial, 0, 3},
2141 {DISPID_GLOBAL_INPUTBOX, Global_InputBox, 0, 1, 7},
2142 {DISPID_GLOBAL_MSGBOX, Global_MsgBox, 0, 1, 5},
2143 {DISPID_GLOBAL_CREATEOBJECT, Global_CreateObject, 0, 1},
2144 {DISPID_GLOBAL_GETOBJECT, Global_GetObject, 0, 0, 2},
2145 {DISPID_GLOBAL_DATEADD, Global_DateAdd, 0, 3},
2146 {DISPID_GLOBAL_DATEDIFF, Global_DateDiff, 0, 3, 5},
2147 {DISPID_GLOBAL_DATEPART, Global_DatePart, 0, 2, 4},
2148 {DISPID_GLOBAL_TYPENAME, Global_TypeName, 0, 1},
2149 {DISPID_GLOBAL_ARRAY, Global_Array, 0, 1},
2150 {DISPID_GLOBAL_ERASE, Global_Erase, 0, 1},
2151 {DISPID_GLOBAL_FILTER, Global_Filter, 0, 2, 4},
2152 {DISPID_GLOBAL_JOIN, Global_Join, 0, 1, 2},
2153 {DISPID_GLOBAL_SPLIT, Global_Split, 0, 1, 4},
2154 {DISPID_GLOBAL_REPLACE, Global_Replace, 0, 3, 6},
2155 {DISPID_GLOBAL_STRREVERSE, Global_StrReverse, 0, 1},
2156 {DISPID_GLOBAL_INSTRREV, Global_InStrRev, 0, 2, 4},
2157 {DISPID_GLOBAL_LOADPICTURE, Global_LoadPicture, 0, 1},
2158 {DISPID_GLOBAL_SCRIPTENGINE, Global_ScriptEngine, 0, 0},
2159 {DISPID_GLOBAL_SCRIPTENGINEMAJORVERSION, Global_ScriptEngineMajorVersion, 0, 0},
2160 {DISPID_GLOBAL_SCRIPTENGINEMINORVERSION, Global_ScriptEngineMinorVersion, 0, 0},
2161 {DISPID_GLOBAL_SCRIPTENGINEBUILDVERSION, Global_ScriptEngineBuildVersion, 0, 0},
2162 {DISPID_GLOBAL_FORMATNUMBER, Global_FormatNumber, 0, 1, 5},
2163 {DISPID_GLOBAL_FORMATCURRENCY, Global_FormatCurrency, 0, 1, 5},
2164 {DISPID_GLOBAL_FORMATPERCENT, Global_FormatPercent, 0, 1, 5},
2165 {DISPID_GLOBAL_FORMATDATETIME, Global_FormatDateTime, 0, 1, 2},
2166 {DISPID_GLOBAL_WEEKDAYNAME, Global_WeekdayName, 0, 1, 3},
2167 {DISPID_GLOBAL_MONTHNAME, Global_MonthName, 0, 1, 2},
2168 {DISPID_GLOBAL_ROUND, Global_Round, 0, 1, 2},
2169 {DISPID_GLOBAL_ESCAPE, Global_Escape, 0, 1},
2170 {DISPID_GLOBAL_UNESCAPE, Global_Unescape, 0, 1},
2171 {DISPID_GLOBAL_EVAL, Global_Eval, 0, 1},
2172 {DISPID_GLOBAL_EXECUTE, Global_Execute, 0, 1},
2173 {DISPID_GLOBAL_EXECUTEGLOBAL, Global_ExecuteGlobal, 0, 1},
2174 {DISPID_GLOBAL_GETREF, Global_GetRef, 0, 1},
2175 {DISPID_GLOBAL_VBMSGBOXHELPBUTTON, NULL, BP_GET, VT_I4, MB_HELP},
2176 {DISPID_GLOBAL_VBMSGBOXSETFOREGROUND, NULL, BP_GET, VT_I4, MB_SETFOREGROUND},
2177 {DISPID_GLOBAL_VBMSGBOXRIGHT, NULL, BP_GET, VT_I4, MB_RIGHT},
2178 {DISPID_GLOBAL_VBMSGBOXRTLREADING, NULL, BP_GET, VT_I4, MB_RTLREADING}
2181 static HRESULT Err_Description(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2183 FIXME("\n");
2184 return E_NOTIMPL;
2187 static HRESULT Err_HelpContext(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2189 FIXME("\n");
2190 return E_NOTIMPL;
2193 static HRESULT Err_HelpFile(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2195 FIXME("\n");
2196 return E_NOTIMPL;
2199 static HRESULT Err_Number(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2201 HRESULT hres;
2203 TRACE("\n");
2205 if(!This->desc)
2206 return E_UNEXPECTED;
2208 if(args_cnt) {
2209 FIXME("setter not implemented\n");
2210 return E_NOTIMPL;
2213 hres = This->desc->ctx->err_number;
2214 return return_int(res, HRESULT_FACILITY(hres) == FACILITY_VBS ? HRESULT_CODE(hres) : hres);
2217 static HRESULT Err_Source(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2219 FIXME("\n");
2220 return E_NOTIMPL;
2223 static HRESULT Err_Clear(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2225 TRACE("\n");
2227 if(!This->desc)
2228 return E_UNEXPECTED;
2230 This->desc->ctx->err_number = S_OK;
2231 return S_OK;
2234 static HRESULT Err_Raise(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2236 FIXME("\n");
2237 return E_NOTIMPL;
2240 static const builtin_prop_t err_props[] = {
2241 {DISPID_ERR_DESCRIPTION, Err_Description, BP_GETPUT},
2242 {DISPID_ERR_HELPCONTEXT, Err_HelpContext, BP_GETPUT},
2243 {DISPID_ERR_HELPFILE, Err_HelpFile, BP_GETPUT},
2244 {DISPID_ERR_NUMBER, Err_Number, BP_GETPUT},
2245 {DISPID_ERR_SOURCE, Err_Source, BP_GETPUT},
2246 {DISPID_ERR_CLEAR, Err_Clear},
2247 {DISPID_ERR_RAISE, Err_Raise, 0, 5},
2250 HRESULT init_global(script_ctx_t *ctx)
2252 HRESULT hres;
2254 ctx->global_desc.ctx = ctx;
2255 ctx->global_desc.builtin_prop_cnt = sizeof(global_props)/sizeof(*global_props);
2256 ctx->global_desc.builtin_props = global_props;
2258 hres = get_typeinfo(GlobalObj_tid, &ctx->global_desc.typeinfo);
2259 if(FAILED(hres))
2260 return hres;
2262 hres = create_vbdisp(&ctx->global_desc, &ctx->global_obj);
2263 if(FAILED(hres))
2264 return hres;
2266 hres = create_script_disp(ctx, &ctx->script_obj);
2267 if(FAILED(hres))
2268 return hres;
2270 ctx->err_desc.ctx = ctx;
2271 ctx->err_desc.builtin_prop_cnt = sizeof(err_props)/sizeof(*err_props);
2272 ctx->err_desc.builtin_props = err_props;
2274 hres = get_typeinfo(ErrObj_tid, &ctx->err_desc.typeinfo);
2275 if(FAILED(hres))
2276 return hres;
2278 return create_vbdisp(&ctx->err_desc, &ctx->err_obj);