d2d1: Implement d2d_d3d_render_target_GetTransform().
[wine.git] / dlls / vbscript / global.c
blob68fa388341cc53e78a419211dde7ee69d604fecc
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((short)val == val)
116 return return_short(res, val);
118 if(res) {
119 V_VT(res) = VT_I4;
120 V_I4(res) = val;
123 return S_OK;
126 static inline HRESULT return_double(VARIANT *res, double val)
128 if(res) {
129 V_VT(res) = VT_R8;
130 V_R8(res) = val;
133 return S_OK;
136 static inline HRESULT return_null(VARIANT *res)
138 if(res)
139 V_VT(res) = VT_NULL;
140 return S_OK;
143 static inline HRESULT return_date(VARIANT *res, double date)
145 if(res) {
146 V_VT(res) = VT_DATE;
147 V_DATE(res) = date;
149 return S_OK;
152 HRESULT to_int(VARIANT *v, int *ret)
154 VARIANT r;
155 HRESULT hres;
157 V_VT(&r) = VT_EMPTY;
158 hres = VariantChangeType(&r, v, 0, VT_I4);
159 if(FAILED(hres))
160 return hres;
162 *ret = V_I4(&r);
163 return S_OK;
166 static HRESULT to_double(VARIANT *v, double *ret)
168 VARIANT dst;
169 HRESULT hres;
171 V_VT(&dst) = VT_EMPTY;
172 hres = VariantChangeType(&dst, v, 0, VT_R8);
173 if(FAILED(hres))
174 return hres;
176 *ret = V_R8(&dst);
177 return S_OK;
180 static HRESULT to_string(VARIANT *v, BSTR *ret)
182 VARIANT dst;
183 HRESULT hres;
185 V_VT(&dst) = VT_EMPTY;
186 hres = VariantChangeType(&dst, v, VARIANT_LOCALBOOL, VT_BSTR);
187 if(FAILED(hres))
188 return hres;
190 *ret = V_BSTR(&dst);
191 return S_OK;
194 static HRESULT set_object_site(script_ctx_t *ctx, IUnknown *obj)
196 IObjectWithSite *obj_site;
197 IUnknown *ax_site;
198 HRESULT hres;
200 hres = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (void**)&obj_site);
201 if(FAILED(hres))
202 return S_OK;
204 ax_site = create_ax_site(ctx);
205 if(ax_site)
206 hres = IObjectWithSite_SetSite(obj_site, ax_site);
207 else
208 hres = E_OUTOFMEMORY;
209 IUnknown_Release(ax_site);
210 IObjectWithSite_Release(obj_site);
211 return hres;
214 static IUnknown *create_object(script_ctx_t *ctx, const WCHAR *progid)
216 IInternetHostSecurityManager *secmgr = NULL;
217 struct CONFIRMSAFETY cs;
218 IClassFactoryEx *cfex;
219 IClassFactory *cf;
220 DWORD policy_size;
221 BYTE *bpolicy;
222 IUnknown *obj;
223 DWORD policy;
224 GUID guid;
225 HRESULT hres;
227 hres = CLSIDFromProgID(progid, &guid);
228 if(FAILED(hres))
229 return NULL;
231 TRACE("GUID %s\n", debugstr_guid(&guid));
233 if(ctx->safeopt & INTERFACE_USES_SECURITY_MANAGER) {
234 secmgr = get_sec_mgr(ctx);
235 if(!secmgr)
236 return NULL;
238 policy = 0;
239 hres = IInternetHostSecurityManager_ProcessUrlAction(secmgr, URLACTION_ACTIVEX_RUN,
240 (BYTE*)&policy, sizeof(policy), (BYTE*)&guid, sizeof(GUID), 0, 0);
241 if(FAILED(hres) || policy != URLPOLICY_ALLOW)
242 return NULL;
245 hres = CoGetClassObject(&guid, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void**)&cf);
246 if(FAILED(hres))
247 return NULL;
249 hres = IClassFactory_QueryInterface(cf, &IID_IClassFactoryEx, (void**)&cfex);
250 if(SUCCEEDED(hres)) {
251 FIXME("Use IClassFactoryEx\n");
252 IClassFactoryEx_Release(cfex);
255 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (void**)&obj);
256 if(FAILED(hres))
257 return NULL;
259 if(secmgr) {
260 cs.clsid = guid;
261 cs.pUnk = obj;
262 cs.dwFlags = 0;
263 hres = IInternetHostSecurityManager_QueryCustomPolicy(secmgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
264 &bpolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
265 if(SUCCEEDED(hres)) {
266 policy = policy_size >= sizeof(DWORD) ? *(DWORD*)bpolicy : URLPOLICY_DISALLOW;
267 CoTaskMemFree(bpolicy);
270 if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
271 IUnknown_Release(obj);
272 return NULL;
276 hres = set_object_site(ctx, obj);
277 if(FAILED(hres)) {
278 IUnknown_Release(obj);
279 return NULL;
282 return obj;
285 static HRESULT show_msgbox(script_ctx_t *ctx, BSTR prompt, VARIANT *res)
287 SCRIPTUICHANDLING uic_handling = SCRIPTUICHANDLING_ALLOW;
288 IActiveScriptSiteUIControl *ui_control;
289 IActiveScriptSiteWindow *acts_window;
290 const WCHAR *title;
291 HWND hwnd = NULL;
292 int ret;
293 HRESULT hres;
295 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IActiveScriptSiteUIControl, (void**)&ui_control);
296 if(SUCCEEDED(hres)) {
297 hres = IActiveScriptSiteUIControl_GetUIBehavior(ui_control, SCRIPTUICITEM_MSGBOX, &uic_handling);
298 IActiveScriptSiteUIControl_Release(ui_control);
299 if(FAILED(hres))
300 uic_handling = SCRIPTUICHANDLING_ALLOW;
303 switch(uic_handling) {
304 case SCRIPTUICHANDLING_ALLOW:
305 break;
306 case SCRIPTUICHANDLING_NOUIDEFAULT:
307 return return_short(res, 0);
308 default:
309 FIXME("blocked\n");
310 return E_FAIL;
313 title = (ctx->safeopt & INTERFACE_USES_SECURITY_MANAGER) ? vbscriptW : emptyW;
315 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IActiveScriptSiteWindow, (void**)&acts_window);
316 if(FAILED(hres)) {
317 FIXME("No IActiveScriptSiteWindow\n");
318 return hres;
321 hres = IActiveScriptSiteWindow_GetWindow(acts_window, &hwnd);
322 if(SUCCEEDED(hres)) {
323 hres = IActiveScriptSiteWindow_EnableModeless(acts_window, FALSE);
324 if(SUCCEEDED(hres)) {
325 ret = MessageBoxW(hwnd, prompt, title, MB_OK);
326 hres = IActiveScriptSiteWindow_EnableModeless(acts_window, TRUE);
330 IActiveScriptSiteWindow_Release(acts_window);
331 if(FAILED(hres)) {
332 FIXME("failed: %08x\n", hres);
333 return hres;
336 return return_short(res, ret);
339 static HRESULT Global_CCur(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
341 VARIANT v;
342 HRESULT hres;
344 TRACE("%s\n", debugstr_variant(arg));
346 assert(args_cnt == 1);
348 V_VT(&v) = VT_EMPTY;
349 hres = VariantChangeType(&v, arg, 0, VT_CY);
350 if(FAILED(hres))
351 return hres;
353 if(!res) {
354 VariantClear(&v);
355 return DISP_E_BADVARTYPE;
358 *res = v;
359 return S_OK;
362 static HRESULT Global_CInt(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
364 VARIANT v;
365 HRESULT hres;
367 TRACE("%s\n", debugstr_variant(arg));
369 assert(args_cnt == 1);
371 V_VT(&v) = VT_EMPTY;
372 hres = VariantChangeType(&v, arg, 0, VT_I2);
373 if(FAILED(hres))
374 return hres;
376 if(!res)
377 return DISP_E_BADVARTYPE;
378 else {
379 *res = v;
380 return S_OK;
384 static HRESULT Global_CLng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
386 int i;
387 HRESULT hres;
389 TRACE("%s\n", debugstr_variant(arg));
391 assert(args_cnt == 1);
393 hres = to_int(arg, &i);
394 if(FAILED(hres))
395 return hres;
396 if(!res)
397 return DISP_E_BADVARTYPE;
399 V_VT(res) = VT_I4;
400 V_I4(res) = i;
401 return S_OK;
404 static HRESULT Global_CBool(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
406 VARIANT v;
407 HRESULT hres;
409 TRACE("%s\n", debugstr_variant(arg));
411 assert(args_cnt == 1);
413 V_VT(&v) = VT_EMPTY;
414 hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_BOOL);
415 if(FAILED(hres))
416 return hres;
418 if(res)
419 *res = v;
420 else
421 VariantClear(&v);
422 return S_OK;
425 static HRESULT Global_CByte(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
427 VARIANT v;
428 HRESULT hres;
430 TRACE("%s\n", debugstr_variant(arg));
432 assert(args_cnt == 1);
434 V_VT(&v) = VT_EMPTY;
435 hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_UI1);
436 if(FAILED(hres))
437 return hres;
439 if(!res) {
440 VariantClear(&v);
441 return DISP_E_BADVARTYPE;
444 *res = v;
445 return S_OK;
448 static HRESULT Global_CDate(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
450 FIXME("\n");
451 return E_NOTIMPL;
454 static HRESULT Global_CDbl(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
456 VARIANT v;
457 HRESULT hres;
459 TRACE("%s\n", debugstr_variant(arg));
461 assert(args_cnt == 1);
463 V_VT(&v) = VT_EMPTY;
464 hres = VariantChangeType(&v, arg, 0, VT_R8);
465 if(FAILED(hres))
466 return hres;
468 if(!res)
469 return DISP_E_BADVARTYPE;
470 else {
471 *res = v;
472 return S_OK;
476 static HRESULT Global_CSng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
478 VARIANT v;
479 HRESULT hres;
481 TRACE("%s\n", debugstr_variant(arg));
483 assert(args_cnt == 1);
485 V_VT(&v) = VT_EMPTY;
486 hres = VariantChangeType(&v, arg, 0, VT_R4);
487 if(FAILED(hres))
488 return hres;
490 if(!res)
491 return DISP_E_BADVARTYPE;
493 *res = v;
494 return S_OK;
497 static HRESULT Global_CStr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
499 BSTR str;
500 HRESULT hres;
502 TRACE("%s\n", debugstr_variant(arg));
504 hres = to_string(arg, &str);
505 if(FAILED(hres))
506 return hres;
508 return return_bstr(res, str);
511 static inline WCHAR hex_char(unsigned n)
513 return n < 10 ? '0'+n : 'A'+n-10;
516 static HRESULT Global_Hex(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
518 WCHAR buf[17], *ptr;
519 DWORD n;
521 TRACE("%s\n", debugstr_variant(arg));
523 switch(V_VT(arg)) {
524 case VT_I2:
525 n = (WORD)V_I2(arg);
526 break;
527 case VT_I4:
528 n = V_I4(arg);
529 break;
530 case VT_EMPTY:
531 n = 0;
532 break;
533 case VT_NULL:
534 if(res)
535 V_VT(res) = VT_NULL;
536 return S_OK;
537 default:
538 FIXME("unsupported type %s\n", debugstr_variant(arg));
539 return E_NOTIMPL;
542 buf[16] = 0;
543 ptr = buf+15;
545 if(n) {
546 do {
547 *ptr-- = hex_char(n & 0xf);
548 n >>= 4;
549 }while(n);
550 ptr++;
551 }else {
552 *ptr = '0';
555 return return_string(res, ptr);
558 static HRESULT Global_Oct(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
560 FIXME("\n");
561 return E_NOTIMPL;
564 static HRESULT Global_VarType(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
566 TRACE("(%s)\n", debugstr_variant(arg));
568 assert(args_cnt == 1);
570 if(V_VT(arg) & ~VT_TYPEMASK) {
571 FIXME("not supported %s\n", debugstr_variant(arg));
572 return E_NOTIMPL;
575 return return_short(res, V_VT(arg));
578 static HRESULT Global_IsDate(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
580 FIXME("\n");
581 return E_NOTIMPL;
584 static HRESULT Global_IsEmpty(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
586 TRACE("(%s)\n", debugstr_variant(arg));
588 assert(args_cnt == 1);
590 if(res) {
591 V_VT(res) = VT_BOOL;
592 V_BOOL(res) = V_VT(arg) == VT_EMPTY ? VARIANT_TRUE : VARIANT_FALSE;
594 return S_OK;
597 static HRESULT Global_IsNull(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
599 TRACE("(%s)\n", debugstr_variant(arg));
601 assert(args_cnt == 1);
603 if(res) {
604 V_VT(res) = VT_BOOL;
605 V_BOOL(res) = V_VT(arg) == VT_NULL ? VARIANT_TRUE : VARIANT_FALSE;
607 return S_OK;
610 static HRESULT Global_IsNumeric(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
612 HRESULT hres;
613 double d;
615 TRACE("(%s)\n", debugstr_variant(arg));
617 assert(args_cnt == 1);
619 hres = to_double(arg, &d);
621 return return_bool(res, SUCCEEDED(hres));
624 static HRESULT Global_IsArray(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
626 FIXME("\n");
627 return E_NOTIMPL;
630 static HRESULT Global_IsObject(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
632 TRACE("(%s)\n", debugstr_variant(arg));
634 assert(args_cnt == 1);
636 if(res) {
637 V_VT(res) = VT_BOOL;
638 V_BOOL(res) = V_VT(arg) == VT_DISPATCH ? VARIANT_TRUE : VARIANT_FALSE;
640 return S_OK;
643 static HRESULT Global_Ant(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
645 FIXME("\n");
646 return E_NOTIMPL;
649 static HRESULT Global_Cos(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
651 FIXME("\n");
652 return E_NOTIMPL;
655 static HRESULT Global_Sin(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
657 FIXME("\n");
658 return E_NOTIMPL;
661 static HRESULT Global_Tan(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
663 FIXME("\n");
664 return E_NOTIMPL;
667 static HRESULT Global_Exp(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
669 FIXME("\n");
670 return E_NOTIMPL;
673 static HRESULT Global_Log(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
675 FIXME("\n");
676 return E_NOTIMPL;
679 static HRESULT Global_Sqr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
681 FIXME("\n");
682 return E_NOTIMPL;
685 static HRESULT Global_Randomize(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
687 FIXME("\n");
688 return E_NOTIMPL;
691 static HRESULT Global_Rnd(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
693 FIXME("\n");
694 return E_NOTIMPL;
697 static HRESULT Global_Timer(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
699 FIXME("\n");
700 return E_NOTIMPL;
703 static HRESULT Global_LBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
705 FIXME("\n");
706 return E_NOTIMPL;
709 static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
711 FIXME("\n");
712 return E_NOTIMPL;
715 static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
717 FIXME("\n");
718 return E_NOTIMPL;
721 static HRESULT Global_Len(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
723 DWORD len;
724 HRESULT hres;
726 TRACE("%s\n", debugstr_variant(arg));
728 if(V_VT(arg) == VT_NULL)
729 return return_null(res);
731 if(V_VT(arg) != VT_BSTR) {
732 BSTR str;
734 hres = to_string(arg, &str);
735 if(FAILED(hres))
736 return hres;
738 len = SysStringLen(str);
739 SysFreeString(str);
740 }else {
741 len = SysStringLen(V_BSTR(arg));
744 return return_int(res, len);
747 static HRESULT Global_LenB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
749 FIXME("\n");
750 return E_NOTIMPL;
753 static HRESULT Global_Left(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
755 BSTR str, ret, conv_str = NULL;
756 int len, str_len;
757 HRESULT hres;
759 TRACE("(%s %s)\n", debugstr_variant(args+1), debugstr_variant(args));
761 if(V_VT(args) == VT_BSTR) {
762 str = V_BSTR(args);
763 }else {
764 hres = to_string(args, &conv_str);
765 if(FAILED(hres))
766 return hres;
767 str = conv_str;
770 hres = to_int(args+1, &len);
771 if(FAILED(hres))
772 return hres;
774 if(len < 0) {
775 FIXME("len = %d\n", len);
776 return E_FAIL;
779 str_len = SysStringLen(str);
780 if(len > str_len)
781 len = str_len;
783 ret = SysAllocStringLen(str, len);
784 SysFreeString(conv_str);
785 if(!ret)
786 return E_OUTOFMEMORY;
788 return return_bstr(res, ret);
791 static HRESULT Global_LeftB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
793 FIXME("\n");
794 return E_NOTIMPL;
797 static HRESULT Global_Right(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
799 BSTR str, ret, conv_str = NULL;
800 int len, str_len;
801 HRESULT hres;
803 TRACE("(%s %s)\n", debugstr_variant(args), debugstr_variant(args+1));
805 if(V_VT(args+1) == VT_BSTR) {
806 str = V_BSTR(args);
807 }else {
808 hres = to_string(args, &conv_str);
809 if(FAILED(hres))
810 return hres;
811 str = conv_str;
814 hres = to_int(args+1, &len);
815 if(FAILED(hres))
816 return hres;
818 if(len < 0) {
819 FIXME("len = %d\n", len);
820 return E_FAIL;
823 str_len = SysStringLen(str);
824 if(len > str_len)
825 len = str_len;
827 ret = SysAllocStringLen(str+str_len-len, len);
828 SysFreeString(conv_str);
829 if(!ret)
830 return E_OUTOFMEMORY;
832 return return_bstr(res, ret);
835 static HRESULT Global_RightB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
837 FIXME("\n");
838 return E_NOTIMPL;
841 static HRESULT Global_Mid(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
843 int len = -1, start, str_len;
844 BSTR str;
845 HRESULT hres;
847 TRACE("(%s %s ...)\n", debugstr_variant(args), debugstr_variant(args+1));
849 assert(args_cnt == 2 || args_cnt == 3);
851 if(V_VT(args) != VT_BSTR) {
852 FIXME("args[0] = %s\n", debugstr_variant(args));
853 return E_NOTIMPL;
856 str = V_BSTR(args);
858 hres = to_int(args+1, &start);
859 if(FAILED(hres))
860 return hres;
862 if(args_cnt == 3) {
863 hres = to_int(args+2, &len);
864 if(FAILED(hres))
865 return hres;
867 if(len < 0) {
868 FIXME("len = %d\n", len);
869 return E_FAIL;
874 str_len = SysStringLen(str);
875 start--;
876 if(start > str_len)
877 start = str_len;
879 if(len == -1)
880 len = str_len-start;
881 else if(len > str_len-start)
882 len = str_len-start;
884 if(res) {
885 V_VT(res) = VT_BSTR;
886 V_BSTR(res) = SysAllocStringLen(str+start, len);
887 if(!V_BSTR(res))
888 return E_OUTOFMEMORY;
891 return S_OK;
894 static HRESULT Global_MidB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
896 FIXME("\n");
897 return E_NOTIMPL;
900 static HRESULT Global_StrComp(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
902 FIXME("\n");
903 return E_NOTIMPL;
906 static HRESULT Global_LCase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
908 BSTR str;
909 HRESULT hres;
911 TRACE("%s\n", debugstr_variant(arg));
913 if(V_VT(arg) == VT_NULL) {
914 if(res)
915 V_VT(res) = VT_NULL;
916 return S_OK;
919 hres = to_string(arg, &str);
920 if(FAILED(hres))
921 return hres;
923 if(res) {
924 WCHAR *ptr;
926 for(ptr = str; *ptr; ptr++)
927 *ptr = tolowerW(*ptr);
929 V_VT(res) = VT_BSTR;
930 V_BSTR(res) = str;
931 }else {
932 SysFreeString(str);
934 return S_OK;
937 static HRESULT Global_UCase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
939 BSTR str;
940 HRESULT hres;
942 TRACE("%s\n", debugstr_variant(arg));
944 if(V_VT(arg) == VT_NULL) {
945 if(res)
946 V_VT(res) = VT_NULL;
947 return S_OK;
950 hres = to_string(arg, &str);
951 if(FAILED(hres))
952 return hres;
954 if(res) {
955 WCHAR *ptr;
957 for(ptr = str; *ptr; ptr++)
958 *ptr = toupperW(*ptr);
960 V_VT(res) = VT_BSTR;
961 V_BSTR(res) = str;
962 }else {
963 SysFreeString(str);
965 return S_OK;
968 static HRESULT Global_LTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
970 BSTR str, conv_str = NULL;
971 WCHAR *ptr;
972 HRESULT hres;
974 TRACE("%s\n", debugstr_variant(arg));
976 if(V_VT(arg) == VT_BSTR) {
977 str = V_BSTR(arg);
978 }else {
979 hres = to_string(arg, &conv_str);
980 if(FAILED(hres))
981 return hres;
982 str = conv_str;
985 for(ptr = str; *ptr && isspaceW(*ptr); ptr++);
987 str = SysAllocString(ptr);
988 SysFreeString(conv_str);
989 if(!str)
990 return E_OUTOFMEMORY;
992 return return_bstr(res, str);
995 static HRESULT Global_RTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
997 BSTR str, conv_str = NULL;
998 WCHAR *ptr;
999 HRESULT hres;
1001 TRACE("%s\n", debugstr_variant(arg));
1003 if(V_VT(arg) == VT_BSTR) {
1004 str = V_BSTR(arg);
1005 }else {
1006 hres = to_string(arg, &conv_str);
1007 if(FAILED(hres))
1008 return hres;
1009 str = conv_str;
1012 for(ptr = str+SysStringLen(str); ptr-1 > str && isspaceW(*(ptr-1)); ptr--);
1014 str = SysAllocStringLen(str, ptr-str);
1015 SysFreeString(conv_str);
1016 if(!str)
1017 return E_OUTOFMEMORY;
1019 return return_bstr(res, str);
1022 static HRESULT Global_Trim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1024 BSTR str, conv_str = NULL;
1025 WCHAR *begin_ptr, *end_ptr;
1026 HRESULT hres;
1028 TRACE("%s\n", debugstr_variant(arg));
1030 if(V_VT(arg) == VT_BSTR) {
1031 str = V_BSTR(arg);
1032 }else {
1033 hres = to_string(arg, &conv_str);
1034 if(FAILED(hres))
1035 return hres;
1036 str = conv_str;
1039 for(begin_ptr = str; *begin_ptr && isspaceW(*begin_ptr); begin_ptr++);
1040 for(end_ptr = str+SysStringLen(str); end_ptr-1 > begin_ptr && isspaceW(*(end_ptr-1)); end_ptr--);
1042 str = SysAllocStringLen(begin_ptr, end_ptr-begin_ptr);
1043 SysFreeString(conv_str);
1044 if(!str)
1045 return E_OUTOFMEMORY;
1047 return return_bstr(res, str);
1050 static HRESULT Global_Space(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1052 BSTR str;
1053 int n, i;
1054 HRESULT hres;
1056 TRACE("%s\n", debugstr_variant(arg));
1058 hres = to_int(arg, &n);
1059 if(FAILED(hres))
1060 return hres;
1062 if(n < 0) {
1063 FIXME("n = %d\n", n);
1064 return E_NOTIMPL;
1067 if(!res)
1068 return S_OK;
1070 str = SysAllocStringLen(NULL, n);
1071 if(!str)
1072 return E_OUTOFMEMORY;
1074 for(i=0; i<n; i++)
1075 str[i] = ' ';
1077 V_VT(res) = VT_BSTR;
1078 V_BSTR(res) = str;
1079 return S_OK;
1082 static HRESULT Global_String(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1084 FIXME("\n");
1085 return E_NOTIMPL;
1088 static HRESULT Global_InStr(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1090 VARIANT *startv, *str1v, *str2v;
1091 BSTR str1, str2;
1092 int start, ret;
1093 HRESULT hres;
1095 TRACE("\n");
1097 assert(2 <= args_cnt && args_cnt <= 4);
1099 switch(args_cnt) {
1100 case 2:
1101 startv = NULL;
1102 str1v = args;
1103 str2v = args+1;
1104 break;
1105 case 3:
1106 startv = args;
1107 str1v = args+1;
1108 str2v = args+2;
1109 break;
1110 case 4:
1111 FIXME("unsupported compare argument %s\n", debugstr_variant(args));
1112 return E_NOTIMPL;
1113 DEFAULT_UNREACHABLE;
1116 if(startv) {
1117 hres = to_int(startv, &start);
1118 if(FAILED(hres))
1119 return hres;
1120 if(--start < 0) {
1121 FIXME("start %d\n", start);
1122 return E_FAIL;
1124 }else {
1125 start = 0;
1128 if(V_VT(str1v) == VT_NULL || V_VT(str2v) == VT_NULL)
1129 return return_null(res);
1131 if(V_VT(str1v) != VT_BSTR) {
1132 FIXME("Unsupported str1 type %s\n", debugstr_variant(str1v));
1133 return E_NOTIMPL;
1135 str1 = V_BSTR(str1v);
1137 if(V_VT(str2v) != VT_BSTR) {
1138 FIXME("Unsupported str2 type %s\n", debugstr_variant(str2v));
1139 return E_NOTIMPL;
1141 str2 = V_BSTR(str2v);
1143 if(start < SysStringLen(str1)) {
1144 WCHAR *ptr;
1146 ptr = strstrW(str1+start, str2);
1147 ret = ptr ? ptr-str1+1 : 0;
1148 }else {
1149 ret = 0;
1152 return return_int(res, ret);
1155 static HRESULT Global_InStrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1157 FIXME("\n");
1158 return E_NOTIMPL;
1161 static HRESULT Global_AscB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1163 FIXME("\n");
1164 return E_NOTIMPL;
1167 static HRESULT Global_ChrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1169 FIXME("\n");
1170 return E_NOTIMPL;
1173 static HRESULT Global_Asc(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1175 FIXME("\n");
1176 return E_NOTIMPL;
1179 /* The function supports only single-byte and double-byte character sets. It
1180 * ignores language specified by IActiveScriptSite::GetLCID. The argument needs
1181 * to be in range of short or unsigned short. */
1182 static HRESULT Global_Chr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1184 int cp, c, len = 0;
1185 CPINFO cpi;
1186 WCHAR ch;
1187 char buf[2];
1188 HRESULT hres;
1190 TRACE("%s\n", debugstr_variant(arg));
1192 hres = to_int(arg, &c);
1193 if(FAILED(hres))
1194 return hres;
1196 cp = GetACP();
1197 if(!GetCPInfo(cp, &cpi))
1198 cpi.MaxCharSize = 1;
1200 if((c!=(short)c && c!=(unsigned short)c) ||
1201 (unsigned short)c>=(cpi.MaxCharSize>1 ? 0x10000 : 0x100)) {
1202 WARN("invalid arg %d\n", c);
1203 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
1206 if(c>>8)
1207 buf[len++] = c>>8;
1208 if(!len || IsDBCSLeadByteEx(cp, buf[0]))
1209 buf[len++] = c;
1210 if(!MultiByteToWideChar(0, 0, buf, len, &ch, 1)) {
1211 WARN("invalid arg %d, cp %d\n", c, cp);
1212 return E_FAIL;
1215 if(res) {
1216 V_VT(res) = VT_BSTR;
1217 V_BSTR(res) = SysAllocStringLen(&ch, 1);
1218 if(!V_BSTR(res))
1219 return E_OUTOFMEMORY;
1221 return S_OK;
1224 static HRESULT Global_AscW(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1226 FIXME("\n");
1227 return E_NOTIMPL;
1230 static HRESULT Global_ChrW(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1232 FIXME("\n");
1233 return E_NOTIMPL;
1236 static HRESULT Global_Abs(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1238 HRESULT hres;
1239 VARIANT dst;
1241 TRACE("(%s)\n", debugstr_variant(arg));
1243 assert(args_cnt == 1);
1245 hres = VarAbs(arg, &dst);
1246 if(FAILED(hres))
1247 return hres;
1249 if (res)
1250 *res = dst;
1251 else
1252 VariantClear(&dst);
1254 return S_OK;
1257 static HRESULT Global_Fix(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1259 FIXME("\n");
1260 return E_NOTIMPL;
1263 static HRESULT Global_Int(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1265 FIXME("\n");
1266 return E_NOTIMPL;
1269 static HRESULT Global_Sgn(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1271 double v;
1272 short val;
1273 HRESULT hres;
1275 TRACE("(%s)\n", debugstr_variant(arg));
1277 assert(args_cnt == 1);
1279 if(V_VT(arg) == VT_NULL)
1280 return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
1282 hres = to_double(arg, &v);
1283 if (FAILED(hres))
1284 return hres;
1286 val = v == 0 ? 0 : (v > 0 ? 1 : -1);
1287 return return_short(res, val);
1290 static HRESULT Global_Now(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1292 SYSTEMTIME lt;
1293 double date;
1295 TRACE("\n");
1297 GetLocalTime(&lt);
1298 SystemTimeToVariantTime(&lt, &date);
1299 return return_date(res, date);
1302 static HRESULT Global_Date(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1304 FIXME("\n");
1305 return E_NOTIMPL;
1308 static HRESULT Global_Time(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1310 FIXME("\n");
1311 return E_NOTIMPL;
1314 static HRESULT Global_Day(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1316 FIXME("\n");
1317 return E_NOTIMPL;
1320 static HRESULT Global_Month(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1322 FIXME("\n");
1323 return E_NOTIMPL;
1326 static HRESULT Global_Weekday(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1328 FIXME("\n");
1329 return E_NOTIMPL;
1332 static HRESULT Global_Year(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1334 FIXME("\n");
1335 return E_NOTIMPL;
1338 static HRESULT Global_Hour(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1340 FIXME("\n");
1341 return E_NOTIMPL;
1344 static HRESULT Global_Minute(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1346 FIXME("\n");
1347 return E_NOTIMPL;
1350 static HRESULT Global_Second(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1352 FIXME("\n");
1353 return E_NOTIMPL;
1356 static HRESULT Global_DateValue(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1358 FIXME("\n");
1359 return E_NOTIMPL;
1362 static HRESULT Global_TimeValue(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1364 FIXME("\n");
1365 return E_NOTIMPL;
1368 static HRESULT Global_DateSerial(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1370 FIXME("\n");
1371 return E_NOTIMPL;
1374 static HRESULT Global_TimeSerial(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1376 FIXME("\n");
1377 return E_NOTIMPL;
1380 static HRESULT Global_InputBox(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1382 FIXME("\n");
1383 return E_NOTIMPL;
1386 static HRESULT Global_MsgBox(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1388 BSTR prompt;
1389 HRESULT hres;
1391 TRACE("\n");
1393 if(args_cnt != 1) {
1394 FIXME("unsupported arg_cnt %d\n", args_cnt);
1395 return E_NOTIMPL;
1398 hres = to_string(args, &prompt);
1399 if(FAILED(hres))
1400 return hres;
1402 hres = show_msgbox(This->desc->ctx, prompt, res);
1403 SysFreeString(prompt);
1404 return hres;
1407 static HRESULT Global_CreateObject(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1409 IUnknown *obj;
1410 HRESULT hres;
1412 TRACE("(%s)\n", debugstr_variant(arg));
1414 if(V_VT(arg) != VT_BSTR) {
1415 FIXME("non-bstr arg\n");
1416 return E_INVALIDARG;
1419 obj = create_object(This->desc->ctx, V_BSTR(arg));
1420 if(!obj)
1421 return VB_E_CANNOT_CREATE_OBJ;
1423 if(res) {
1424 hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&V_DISPATCH(res));
1425 if(FAILED(hres))
1426 return hres;
1428 V_VT(res) = VT_DISPATCH;
1431 IUnknown_Release(obj);
1432 return S_OK;
1435 static HRESULT Global_GetObject(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1437 IBindCtx *bind_ctx;
1438 IUnknown *obj_unk;
1439 IDispatch *disp;
1440 ULONG eaten = 0;
1441 IMoniker *mon;
1442 HRESULT hres;
1444 TRACE("%s %s\n", args_cnt ? debugstr_variant(args) : "", args_cnt > 1 ? debugstr_variant(args+1) : "");
1446 if(args_cnt != 1 || V_VT(args) != VT_BSTR) {
1447 FIXME("unsupported args\n");
1448 return E_NOTIMPL;
1451 if(This->desc->ctx->safeopt & (INTERFACE_USES_SECURITY_MANAGER|INTERFACESAFE_FOR_UNTRUSTED_DATA)) {
1452 WARN("blocked in current safety mode\n");
1453 return VB_E_CANNOT_CREATE_OBJ;
1456 hres = CreateBindCtx(0, &bind_ctx);
1457 if(FAILED(hres))
1458 return hres;
1460 hres = MkParseDisplayName(bind_ctx, V_BSTR(args), &eaten, &mon);
1461 if(SUCCEEDED(hres)) {
1462 hres = IMoniker_BindToObject(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&obj_unk);
1463 IMoniker_Release(mon);
1464 }else {
1465 hres = MK_E_SYNTAX;
1467 IBindCtx_Release(bind_ctx);
1468 if(FAILED(hres))
1469 return hres;
1471 hres = set_object_site(This->desc->ctx, obj_unk);
1472 if(FAILED(hres)) {
1473 IUnknown_Release(obj_unk);
1474 return hres;
1477 hres = IUnknown_QueryInterface(obj_unk, &IID_IDispatch, (void**)&disp);
1478 if(SUCCEEDED(hres)) {
1479 if(res) {
1480 V_VT(res) = VT_DISPATCH;
1481 V_DISPATCH(res) = disp;
1482 }else {
1483 IDispatch_Release(disp);
1485 }else {
1486 FIXME("object does not support IDispatch\n");
1489 return hres;
1492 static HRESULT Global_DateAdd(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1494 FIXME("\n");
1495 return E_NOTIMPL;
1498 static HRESULT Global_DateDiff(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1500 FIXME("\n");
1501 return E_NOTIMPL;
1504 static HRESULT Global_DatePart(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1506 FIXME("\n");
1507 return E_NOTIMPL;
1510 static HRESULT Global_TypeName(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1512 static const WCHAR ByteW[] = {'B', 'y', 't', 'e', 0};
1513 static const WCHAR IntegerW[] = {'I', 'n', 't', 'e', 'g', 'e', 'r', 0};
1514 static const WCHAR LongW[] = {'L', 'o', 'n', 'g', 0};
1515 static const WCHAR SingleW[] = {'S', 'i', 'n', 'g', 'l', 'e', 0};
1516 static const WCHAR DoubleW[] = {'D', 'o', 'u', 'b', 'l', 'e', 0};
1517 static const WCHAR CurrencyW[] = {'C', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 0};
1518 static const WCHAR DecimalW[] = {'D', 'e', 'c', 'i', 'm', 'a', 'l', 0};
1519 static const WCHAR DateW[] = {'D', 'a', 't', 'e', 0};
1520 static const WCHAR StringW[] = {'S', 't', 'r', 'i', 'n', 'g', 0};
1521 static const WCHAR BooleanW[] = {'B', 'o', 'o', 'l', 'e', 'a', 'n', 0};
1522 static const WCHAR EmptyW[] = {'E', 'm', 'p', 't', 'y', 0};
1523 static const WCHAR NullW[] = {'N', 'u', 'l', 'l', 0};
1525 TRACE("(%s)\n", debugstr_variant(arg));
1527 assert(args_cnt == 1);
1529 switch(V_VT(arg)) {
1530 case VT_UI1:
1531 return return_string(res, ByteW);
1532 case VT_I2:
1533 return return_string(res, IntegerW);
1534 case VT_I4:
1535 return return_string(res, LongW);
1536 case VT_R4:
1537 return return_string(res, SingleW);
1538 case VT_R8:
1539 return return_string(res, DoubleW);
1540 case VT_CY:
1541 return return_string(res, CurrencyW);
1542 case VT_DECIMAL:
1543 return return_string(res, DecimalW);
1544 case VT_DATE:
1545 return return_string(res, DateW);
1546 case VT_BSTR:
1547 return return_string(res, StringW);
1548 case VT_BOOL:
1549 return return_string(res, BooleanW);
1550 case VT_EMPTY:
1551 return return_string(res, EmptyW);
1552 case VT_NULL:
1553 return return_string(res, NullW);
1554 default:
1555 FIXME("arg %s not supported\n", debugstr_variant(arg));
1556 return E_NOTIMPL;
1560 static HRESULT Global_Array(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1562 FIXME("\n");
1563 return E_NOTIMPL;
1566 static HRESULT Global_Erase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1568 FIXME("\n");
1569 return E_NOTIMPL;
1572 static HRESULT Global_Filter(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1574 FIXME("\n");
1575 return E_NOTIMPL;
1578 static HRESULT Global_Join(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1580 FIXME("\n");
1581 return E_NOTIMPL;
1584 static HRESULT Global_Split(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1586 FIXME("\n");
1587 return E_NOTIMPL;
1590 static HRESULT Global_Replace(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1592 FIXME("\n");
1593 return E_NOTIMPL;
1596 static HRESULT Global_StrReverse(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1598 WCHAR *ptr1, *ptr2, ch;
1599 BSTR ret;
1600 HRESULT hres;
1602 TRACE("%s\n", debugstr_variant(arg));
1604 hres = to_string(arg, &ret);
1605 if(FAILED(hres))
1606 return hres;
1608 ptr1 = ret;
1609 ptr2 = ret + SysStringLen(ret)-1;
1610 while(ptr1 < ptr2) {
1611 ch = *ptr1;
1612 *ptr1++ = *ptr2;
1613 *ptr2-- = ch;
1616 return return_bstr(res, ret);
1619 static HRESULT Global_InStrRev(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1621 FIXME("\n");
1622 return E_NOTIMPL;
1625 static HRESULT Global_LoadPicture(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1627 FIXME("\n");
1628 return E_NOTIMPL;
1631 static HRESULT Global_ScriptEngine(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1633 FIXME("\n");
1634 return E_NOTIMPL;
1637 static HRESULT Global_ScriptEngineMajorVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1639 FIXME("\n");
1640 return E_NOTIMPL;
1643 static HRESULT Global_ScriptEngineMinorVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1645 FIXME("\n");
1646 return E_NOTIMPL;
1649 static HRESULT Global_ScriptEngineBuildVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1651 FIXME("\n");
1652 return E_NOTIMPL;
1655 static HRESULT Global_FormatNumber(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1657 FIXME("\n");
1658 return E_NOTIMPL;
1661 static HRESULT Global_FormatCurrency(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1663 FIXME("\n");
1664 return E_NOTIMPL;
1667 static HRESULT Global_FormatPercent(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1669 FIXME("\n");
1670 return E_NOTIMPL;
1673 static HRESULT Global_FormatDateTime(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1675 FIXME("\n");
1676 return E_NOTIMPL;
1679 static HRESULT Global_WeekdayName(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1681 int weekday, first_day = 1, abbrev = 0;
1682 BSTR ret;
1683 HRESULT hres;
1685 TRACE("\n");
1687 assert(1 <= args_cnt && args_cnt <= 3);
1689 hres = to_int(args, &weekday);
1690 if(FAILED(hres))
1691 return hres;
1693 if(args_cnt > 1) {
1694 hres = to_int(args+1, &abbrev);
1695 if(FAILED(hres))
1696 return hres;
1698 if(args_cnt == 3) {
1699 hres = to_int(args+2, &first_day);
1700 if(FAILED(hres))
1701 return hres;
1705 hres = VarWeekdayName(weekday, abbrev, first_day, 0, &ret);
1706 if(FAILED(hres))
1707 return hres;
1709 return return_bstr(res, ret);
1712 static HRESULT Global_MonthName(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1714 int month, abbrev = 0;
1715 BSTR ret;
1716 HRESULT hres;
1718 TRACE("\n");
1720 assert(args_cnt == 1 || args_cnt == 2);
1722 hres = to_int(args, &month);
1723 if(FAILED(hres))
1724 return hres;
1726 if(args_cnt == 2) {
1727 hres = to_int(args+1, &abbrev);
1728 if(FAILED(hres))
1729 return hres;
1732 hres = VarMonthName(month, abbrev, 0, &ret);
1733 if(FAILED(hres))
1734 return hres;
1736 return return_bstr(res, ret);
1739 static HRESULT Global_Round(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1741 double n;
1742 HRESULT hres;
1744 TRACE("%s\n", debugstr_variant(arg));
1746 if(!res)
1747 return S_OK;
1749 switch(V_VT(arg)) {
1750 case VT_I2:
1751 case VT_I4:
1752 case VT_BOOL:
1753 *res = *arg;
1754 return S_OK;
1755 case VT_R8:
1756 n = V_R8(arg);
1757 break;
1758 default:
1759 hres = to_double(arg, &n);
1760 if(FAILED(hres))
1761 return hres;
1764 return return_double(res, round(n));
1767 static HRESULT Global_Escape(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1769 FIXME("\n");
1770 return E_NOTIMPL;
1773 static HRESULT Global_Unescape(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1775 FIXME("\n");
1776 return E_NOTIMPL;
1779 static HRESULT Global_Eval(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1781 FIXME("\n");
1782 return E_NOTIMPL;
1785 static HRESULT Global_Execute(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1787 FIXME("\n");
1788 return E_NOTIMPL;
1791 static HRESULT Global_ExecuteGlobal(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1793 FIXME("\n");
1794 return E_NOTIMPL;
1797 static HRESULT Global_GetRef(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1799 FIXME("\n");
1800 return E_NOTIMPL;
1803 static const string_constant_t vbCr = {1, {'\r'}};
1804 static const string_constant_t vbCrLf = {2, {'\r','\n'}};
1805 static const string_constant_t vbNewLine = {2, {'\r','\n'}};
1806 static const string_constant_t vbFormFeed = {1, {0xc}};
1807 static const string_constant_t vbLf = {1, {'\n'}};
1808 static const string_constant_t vbNullChar = {1};
1809 static const string_constant_t vbNullString = {0};
1810 static const string_constant_t vbTab = {1, {'\t'}};
1811 static const string_constant_t vbVerticalTab = {1, {0xb}};
1813 static const builtin_prop_t global_props[] = {
1814 {DISPID_GLOBAL_VBUSESYSTEM, NULL, BP_GET, VT_I2, 0},
1815 {DISPID_GLOBAL_USESYSTEMDAYOFWEEK, NULL, BP_GET, VT_I2, 0},
1816 {DISPID_GLOBAL_VBSUNDAY, NULL, BP_GET, VT_I2, 1},
1817 {DISPID_GLOBAL_VBMONDAY, NULL, BP_GET, VT_I2, 2},
1818 {DISPID_GLOBAL_VBTUESDAY, NULL, BP_GET, VT_I2, 3},
1819 {DISPID_GLOBAL_VBWEDNESDAY, NULL, BP_GET, VT_I2, 4},
1820 {DISPID_GLOBAL_VBTHURSDAY, NULL, BP_GET, VT_I2, 5},
1821 {DISPID_GLOBAL_VBFRIDAY, NULL, BP_GET, VT_I2, 6},
1822 {DISPID_GLOBAL_VBSATURDAY, NULL, BP_GET, VT_I2, 7},
1823 {DISPID_GLOBAL_VBFIRSTJAN1, NULL, BP_GET, VT_I2, 1},
1824 {DISPID_GLOBAL_VBFIRSTFOURDAYS, NULL, BP_GET, VT_I2, 2},
1825 {DISPID_GLOBAL_VBFIRSTFULLWEEK, NULL, BP_GET, VT_I2, 3},
1826 {DISPID_GLOBAL_VBOKONLY, NULL, BP_GET, VT_I2, MB_OK},
1827 {DISPID_GLOBAL_VBOKCANCEL, NULL, BP_GET, VT_I2, MB_OKCANCEL},
1828 {DISPID_GLOBAL_VBABORTRETRYIGNORE, NULL, BP_GET, VT_I2, MB_ABORTRETRYIGNORE},
1829 {DISPID_GLOBAL_VBYESNOCANCEL, NULL, BP_GET, VT_I2, MB_YESNOCANCEL},
1830 {DISPID_GLOBAL_VBYESNO, NULL, BP_GET, VT_I2, MB_YESNO},
1831 {DISPID_GLOBAL_VBRETRYCANCEL, NULL, BP_GET, VT_I2, MB_RETRYCANCEL},
1832 {DISPID_GLOBAL_VBCRITICAL, NULL, BP_GET, VT_I2, MB_ICONHAND},
1833 {DISPID_GLOBAL_VBQUESTION, NULL, BP_GET, VT_I2, MB_ICONQUESTION},
1834 {DISPID_GLOBAL_VBEXCLAMATION, NULL, BP_GET, VT_I2, MB_ICONEXCLAMATION},
1835 {DISPID_GLOBAL_VBINFORMATION, NULL, BP_GET, VT_I2, MB_ICONASTERISK},
1836 {DISPID_GLOBAL_VBDEFAULTBUTTON1, NULL, BP_GET, VT_I2, MB_DEFBUTTON1},
1837 {DISPID_GLOBAL_VBDEFAULTBUTTON2, NULL, BP_GET, VT_I2, MB_DEFBUTTON2},
1838 {DISPID_GLOBAL_VBDEFAULTBUTTON3, NULL, BP_GET, VT_I2, MB_DEFBUTTON3},
1839 {DISPID_GLOBAL_VBDEFAULTBUTTON4, NULL, BP_GET, VT_I2, MB_DEFBUTTON4},
1840 {DISPID_GLOBAL_VBAPPLICATIONMODAL, NULL, BP_GET, VT_I2, MB_APPLMODAL},
1841 {DISPID_GLOBAL_VBSYSTEMMODAL, NULL, BP_GET, VT_I2, MB_SYSTEMMODAL},
1842 {DISPID_GLOBAL_VBOK, NULL, BP_GET, VT_I2, IDOK},
1843 {DISPID_GLOBAL_VBCANCEL, NULL, BP_GET, VT_I2, IDCANCEL},
1844 {DISPID_GLOBAL_VBABORT, NULL, BP_GET, VT_I2, IDABORT},
1845 {DISPID_GLOBAL_VBRETRY, NULL, BP_GET, VT_I2, IDRETRY},
1846 {DISPID_GLOBAL_VBIGNORE, NULL, BP_GET, VT_I2, IDIGNORE},
1847 {DISPID_GLOBAL_VBYES, NULL, BP_GET, VT_I2, IDYES},
1848 {DISPID_GLOBAL_VBNO, NULL, BP_GET, VT_I2, IDNO},
1849 {DISPID_GLOBAL_VBEMPTY, NULL, BP_GET, VT_I2, VT_EMPTY},
1850 {DISPID_GLOBAL_VBNULL, NULL, BP_GET, VT_I2, VT_NULL},
1851 {DISPID_GLOBAL_VBINTEGER, NULL, BP_GET, VT_I2, VT_I2},
1852 {DISPID_GLOBAL_VBLONG, NULL, BP_GET, VT_I2, VT_I4},
1853 {DISPID_GLOBAL_VBSINGLE, NULL, BP_GET, VT_I2, VT_R4},
1854 {DISPID_GLOBAL_VBDOUBLE, NULL, BP_GET, VT_I2, VT_R8},
1855 {DISPID_GLOBAL_VBCURRENCY, NULL, BP_GET, VT_I2, VT_CY},
1856 {DISPID_GLOBAL_VBDATE, NULL, BP_GET, VT_I2, VT_DATE},
1857 {DISPID_GLOBAL_VBSTRING, NULL, BP_GET, VT_I2, VT_BSTR},
1858 {DISPID_GLOBAL_VBOBJECT, NULL, BP_GET, VT_I2, VT_DISPATCH},
1859 {DISPID_GLOBAL_VBERROR, NULL, BP_GET, VT_I2, VT_ERROR},
1860 {DISPID_GLOBAL_VBBOOLEAN, NULL, BP_GET, VT_I2, VT_BOOL},
1861 {DISPID_GLOBAL_VBVARIANT, NULL, BP_GET, VT_I2, VT_VARIANT},
1862 {DISPID_GLOBAL_VBDATAOBJECT, NULL, BP_GET, VT_I2, VT_UNKNOWN},
1863 {DISPID_GLOBAL_VBDECIMAL, NULL, BP_GET, VT_I2, VT_DECIMAL},
1864 {DISPID_GLOBAL_VBBYTE, NULL, BP_GET, VT_I2, VT_UI1},
1865 {DISPID_GLOBAL_VBARRAY, NULL, BP_GET, VT_I2, VT_ARRAY},
1866 {DISPID_GLOBAL_VBTRUE, NULL, BP_GET, VT_I2, VARIANT_TRUE},
1867 {DISPID_GLOBAL_VBFALSE, NULL, BP_GET, VT_I2, VARIANT_FALSE},
1868 {DISPID_GLOBAL_VBUSEDEFAULT, NULL, BP_GET, VT_I2, -2},
1869 {DISPID_GLOBAL_VBBINARYCOMPARE, NULL, BP_GET, VT_I2, 0},
1870 {DISPID_GLOBAL_VBTEXTCOMPARE, NULL, BP_GET, VT_I2, 1},
1871 {DISPID_GLOBAL_VBDATABASECOMPARE, NULL, BP_GET, VT_I2, 2},
1872 {DISPID_GLOBAL_VBGENERALDATE, NULL, BP_GET, VT_I2, 0},
1873 {DISPID_GLOBAL_VBLONGDATE, NULL, BP_GET, VT_I2, 1},
1874 {DISPID_GLOBAL_VBSHORTDATE, NULL, BP_GET, VT_I2, 2},
1875 {DISPID_GLOBAL_VBLONGTIME, NULL, BP_GET, VT_I2, 3},
1876 {DISPID_GLOBAL_VBSHORTTIME, NULL, BP_GET, VT_I2, 4},
1877 {DISPID_GLOBAL_VBOBJECTERROR, NULL, BP_GET, VT_I4, 0x80040000},
1878 {DISPID_GLOBAL_VBBLACK, NULL, BP_GET, VT_I4, 0x000000},
1879 {DISPID_GLOBAL_VBBLUE, NULL, BP_GET, VT_I4, 0xff0000},
1880 {DISPID_GLOBAL_VBCYAN, NULL, BP_GET, VT_I4, 0xffff00},
1881 {DISPID_GLOBAL_VBGREEN, NULL, BP_GET, VT_I4, 0x00ff00},
1882 {DISPID_GLOBAL_VBMAGENTA, NULL, BP_GET, VT_I4, 0xff00ff},
1883 {DISPID_GLOBAL_VBRED, NULL, BP_GET, VT_I4, 0x0000ff},
1884 {DISPID_GLOBAL_VBWHITE, NULL, BP_GET, VT_I4, 0xffffff},
1885 {DISPID_GLOBAL_VBYELLOW, NULL, BP_GET, VT_I4, 0x00ffff},
1886 {DISPID_GLOBAL_VBCR, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbCr},
1887 {DISPID_GLOBAL_VBCRLF, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbCrLf},
1888 {DISPID_GLOBAL_VBNEWLINE, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNewLine},
1889 {DISPID_GLOBAL_VBFORMFEED, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbFormFeed},
1890 {DISPID_GLOBAL_VBLF, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbLf},
1891 {DISPID_GLOBAL_VBNULLCHAR, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNullChar},
1892 {DISPID_GLOBAL_VBNULLSTRING, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNullString},
1893 {DISPID_GLOBAL_VBTAB, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbTab},
1894 {DISPID_GLOBAL_VBVERTICALTAB, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbVerticalTab},
1895 {DISPID_GLOBAL_CCUR, Global_CCur, 0, 1},
1896 {DISPID_GLOBAL_CINT, Global_CInt, 0, 1},
1897 {DISPID_GLOBAL_CLNG, Global_CLng, 0, 1},
1898 {DISPID_GLOBAL_CBOOL, Global_CBool, 0, 1},
1899 {DISPID_GLOBAL_CBYTE, Global_CByte, 0, 1},
1900 {DISPID_GLOBAL_CDATE, Global_CDate, 0, 1},
1901 {DISPID_GLOBAL_CDBL, Global_CDbl, 0, 1},
1902 {DISPID_GLOBAL_CSNG, Global_CSng, 0, 1},
1903 {DISPID_GLOBAL_CSTR, Global_CStr, 0, 1},
1904 {DISPID_GLOBAL_HEX, Global_Hex, 0, 1},
1905 {DISPID_GLOBAL_OCT, Global_Oct, 0, 1},
1906 {DISPID_GLOBAL_VARTYPE, Global_VarType, 0, 1},
1907 {DISPID_GLOBAL_ISDATE, Global_IsDate, 0, 1},
1908 {DISPID_GLOBAL_ISEMPTY, Global_IsEmpty, 0, 1},
1909 {DISPID_GLOBAL_ISNULL, Global_IsNull, 0, 1},
1910 {DISPID_GLOBAL_ISNUMERIC, Global_IsNumeric, 0, 1},
1911 {DISPID_GLOBAL_ISARRAY, Global_IsArray, 0, 1},
1912 {DISPID_GLOBAL_ISOBJECT, Global_IsObject, 0, 1},
1913 {DISPID_GLOBAL_ATN, Global_Ant, 0, 1},
1914 {DISPID_GLOBAL_COS, Global_Cos, 0, 1},
1915 {DISPID_GLOBAL_SIN, Global_Sin, 0, 1},
1916 {DISPID_GLOBAL_TAN, Global_Tan, 0, 1},
1917 {DISPID_GLOBAL_EXP, Global_Exp, 0, 1},
1918 {DISPID_GLOBAL_LOG, Global_Log, 0, 1},
1919 {DISPID_GLOBAL_SQR, Global_Sqr, 0, 1},
1920 {DISPID_GLOBAL_RANDOMIZE, Global_Randomize, 0, 1},
1921 {DISPID_GLOBAL_RND, Global_Rnd, 0, 1},
1922 {DISPID_GLOBAL_TIMER, Global_Timer, 0, 0},
1923 {DISPID_GLOBAL_LBOUND, Global_LBound, 0, 1},
1924 {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1},
1925 {DISPID_GLOBAL_RGB, Global_RGB, 0, 3},
1926 {DISPID_GLOBAL_LEN, Global_Len, 0, 1},
1927 {DISPID_GLOBAL_LENB, Global_LenB, 0, 1},
1928 {DISPID_GLOBAL_LEFT, Global_Left, 0, 2},
1929 {DISPID_GLOBAL_LEFTB, Global_LeftB, 0, 2},
1930 {DISPID_GLOBAL_RIGHT, Global_Right, 0, 2},
1931 {DISPID_GLOBAL_RIGHTB, Global_RightB, 0, 2},
1932 {DISPID_GLOBAL_MID, Global_Mid, 0, 2, 3},
1933 {DISPID_GLOBAL_MIDB, Global_MidB, 0, 2, 3},
1934 {DISPID_GLOBAL_STRCOMP, Global_StrComp, 0, 2, 3},
1935 {DISPID_GLOBAL_LCASE, Global_LCase, 0, 1},
1936 {DISPID_GLOBAL_UCASE, Global_UCase, 0, 1},
1937 {DISPID_GLOBAL_LTRIM, Global_LTrim, 0, 1},
1938 {DISPID_GLOBAL_RTRIM, Global_RTrim, 0, 1},
1939 {DISPID_GLOBAL_TRIM, Global_Trim, 0, 1},
1940 {DISPID_GLOBAL_SPACE, Global_Space, 0, 1},
1941 {DISPID_GLOBAL_STRING, Global_String, 0, 0, 2},
1942 {DISPID_GLOBAL_INSTR, Global_InStr, 0, 2, 4},
1943 {DISPID_GLOBAL_INSTRB, Global_InStrB, 0, 3, 4},
1944 {DISPID_GLOBAL_ASCB, Global_AscB, 0, 1},
1945 {DISPID_GLOBAL_CHRB, Global_ChrB, 0, 1},
1946 {DISPID_GLOBAL_ASC, Global_Asc, 0, 1},
1947 {DISPID_GLOBAL_CHR, Global_Chr, 0, 1},
1948 {DISPID_GLOBAL_ASCW, Global_AscW, 0, 1},
1949 {DISPID_GLOBAL_CHRW, Global_ChrW, 0, 1},
1950 {DISPID_GLOBAL_ABS, Global_Abs, 0, 1},
1951 {DISPID_GLOBAL_FIX, Global_Fix, 0, 1},
1952 {DISPID_GLOBAL_INT, Global_Int, 0, 1},
1953 {DISPID_GLOBAL_SGN, Global_Sgn, 0, 1},
1954 {DISPID_GLOBAL_NOW, Global_Now, 0, 0},
1955 {DISPID_GLOBAL_DATE, Global_Date, 0, 0},
1956 {DISPID_GLOBAL_TIME, Global_Time, 0, 0},
1957 {DISPID_GLOBAL_DAY, Global_Day, 0, 1},
1958 {DISPID_GLOBAL_MONTH, Global_Month, 0, 1},
1959 {DISPID_GLOBAL_WEEKDAY, Global_Weekday, 0, 1, 2},
1960 {DISPID_GLOBAL_YEAR, Global_Year, 0, 1},
1961 {DISPID_GLOBAL_HOUR, Global_Hour, 0, 1},
1962 {DISPID_GLOBAL_MINUTE, Global_Minute, 0, 1},
1963 {DISPID_GLOBAL_SECOND, Global_Second, 0, 1},
1964 {DISPID_GLOBAL_DATEVALUE, Global_DateValue, 0, 1},
1965 {DISPID_GLOBAL_TIMEVALUE, Global_TimeValue, 0, 1},
1966 {DISPID_GLOBAL_DATESERIAL, Global_DateSerial, 0, 3},
1967 {DISPID_GLOBAL_TIMESERIAL, Global_TimeSerial, 0, 3},
1968 {DISPID_GLOBAL_INPUTBOX, Global_InputBox, 0, 1, 7},
1969 {DISPID_GLOBAL_MSGBOX, Global_MsgBox, 0, 1, 5},
1970 {DISPID_GLOBAL_CREATEOBJECT, Global_CreateObject, 0, 1},
1971 {DISPID_GLOBAL_GETOBJECT, Global_GetObject, 0, 0, 2},
1972 {DISPID_GLOBAL_DATEADD, Global_DateAdd, 0, 3},
1973 {DISPID_GLOBAL_DATEDIFF, Global_DateDiff, 0, 3, 5},
1974 {DISPID_GLOBAL_DATEPART, Global_DatePart, 0, 2, 4},
1975 {DISPID_GLOBAL_TYPENAME, Global_TypeName, 0, 1},
1976 {DISPID_GLOBAL_ARRAY, Global_Array, 0, 1},
1977 {DISPID_GLOBAL_ERASE, Global_Erase, 0, 1},
1978 {DISPID_GLOBAL_FILTER, Global_Filter, 0, 2, 4},
1979 {DISPID_GLOBAL_JOIN, Global_Join, 0, 1, 2},
1980 {DISPID_GLOBAL_SPLIT, Global_Split, 0, 1, 4},
1981 {DISPID_GLOBAL_REPLACE, Global_Replace, 0, 3, 6},
1982 {DISPID_GLOBAL_STRREVERSE, Global_StrReverse, 0, 1},
1983 {DISPID_GLOBAL_INSTRREV, Global_InStrRev, 0, 2, 4},
1984 {DISPID_GLOBAL_LOADPICTURE, Global_LoadPicture, 0, 1},
1985 {DISPID_GLOBAL_SCRIPTENGINE, Global_ScriptEngine, 0, 0},
1986 {DISPID_GLOBAL_SCRIPTENGINEMAJORVERSION, Global_ScriptEngineMajorVersion, 0, 0},
1987 {DISPID_GLOBAL_SCRIPTENGINEMINORVERSION, Global_ScriptEngineMinorVersion, 0, 0},
1988 {DISPID_GLOBAL_SCRIPTENGINEBUILDVERSION, Global_ScriptEngineBuildVersion, 0, 0},
1989 {DISPID_GLOBAL_FORMATNUMBER, Global_FormatNumber, 0, 1, 5},
1990 {DISPID_GLOBAL_FORMATCURRENCY, Global_FormatCurrency, 0, 1, 5},
1991 {DISPID_GLOBAL_FORMATPERCENT, Global_FormatPercent, 0, 1, 5},
1992 {DISPID_GLOBAL_FORMATDATETIME, Global_FormatDateTime, 0, 1, 2},
1993 {DISPID_GLOBAL_WEEKDAYNAME, Global_WeekdayName, 0, 1, 3},
1994 {DISPID_GLOBAL_MONTHNAME, Global_MonthName, 0, 1, 2},
1995 {DISPID_GLOBAL_ROUND, Global_Round, 0, 1, 2},
1996 {DISPID_GLOBAL_ESCAPE, Global_Escape, 0, 1},
1997 {DISPID_GLOBAL_UNESCAPE, Global_Unescape, 0, 1},
1998 {DISPID_GLOBAL_EVAL, Global_Eval, 0, 1},
1999 {DISPID_GLOBAL_EXECUTE, Global_Execute, 0, 1},
2000 {DISPID_GLOBAL_EXECUTEGLOBAL, Global_ExecuteGlobal, 0, 1},
2001 {DISPID_GLOBAL_GETREF, Global_GetRef, 0, 1},
2002 {DISPID_GLOBAL_VBMSGBOXHELPBUTTON, NULL, BP_GET, VT_I4, MB_HELP},
2003 {DISPID_GLOBAL_VBMSGBOXSETFOREGROUND, NULL, BP_GET, VT_I4, MB_SETFOREGROUND},
2004 {DISPID_GLOBAL_VBMSGBOXRIGHT, NULL, BP_GET, VT_I4, MB_RIGHT},
2005 {DISPID_GLOBAL_VBMSGBOXRTLREADING, NULL, BP_GET, VT_I4, MB_RTLREADING}
2008 static HRESULT Err_Description(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2010 FIXME("\n");
2011 return E_NOTIMPL;
2014 static HRESULT Err_HelpContext(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2016 FIXME("\n");
2017 return E_NOTIMPL;
2020 static HRESULT Err_HelpFile(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2022 FIXME("\n");
2023 return E_NOTIMPL;
2026 static HRESULT Err_Number(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2028 HRESULT hres;
2030 TRACE("\n");
2032 if(!This->desc)
2033 return E_UNEXPECTED;
2035 if(args_cnt) {
2036 FIXME("setter not implemented\n");
2037 return E_NOTIMPL;
2040 hres = This->desc->ctx->err_number;
2041 return return_int(res, HRESULT_FACILITY(hres) == FACILITY_VBS ? HRESULT_CODE(hres) : hres);
2044 static HRESULT Err_Source(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2046 FIXME("\n");
2047 return E_NOTIMPL;
2050 static HRESULT Err_Clear(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2052 TRACE("\n");
2054 if(!This->desc)
2055 return E_UNEXPECTED;
2057 This->desc->ctx->err_number = S_OK;
2058 return S_OK;
2061 static HRESULT Err_Raise(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
2063 FIXME("\n");
2064 return E_NOTIMPL;
2067 static const builtin_prop_t err_props[] = {
2068 {DISPID_ERR_DESCRIPTION, Err_Description, BP_GETPUT},
2069 {DISPID_ERR_HELPCONTEXT, Err_HelpContext, BP_GETPUT},
2070 {DISPID_ERR_HELPFILE, Err_HelpFile, BP_GETPUT},
2071 {DISPID_ERR_NUMBER, Err_Number, BP_GETPUT},
2072 {DISPID_ERR_SOURCE, Err_Source, BP_GETPUT},
2073 {DISPID_ERR_CLEAR, Err_Clear},
2074 {DISPID_ERR_RAISE, Err_Raise, 0, 5},
2077 HRESULT init_global(script_ctx_t *ctx)
2079 HRESULT hres;
2081 ctx->global_desc.ctx = ctx;
2082 ctx->global_desc.builtin_prop_cnt = sizeof(global_props)/sizeof(*global_props);
2083 ctx->global_desc.builtin_props = global_props;
2085 hres = get_typeinfo(GlobalObj_tid, &ctx->global_desc.typeinfo);
2086 if(FAILED(hres))
2087 return hres;
2089 hres = create_vbdisp(&ctx->global_desc, &ctx->global_obj);
2090 if(FAILED(hres))
2091 return hres;
2093 hres = create_script_disp(ctx, &ctx->script_obj);
2094 if(FAILED(hres))
2095 return hres;
2097 ctx->err_desc.ctx = ctx;
2098 ctx->err_desc.builtin_prop_cnt = sizeof(err_props)/sizeof(*err_props);
2099 ctx->err_desc.builtin_props = err_props;
2101 hres = get_typeinfo(ErrObj_tid, &ctx->err_desc.typeinfo);
2102 if(FAILED(hres))
2103 return hres;
2105 return create_vbdisp(&ctx->err_desc, &ctx->err_obj);