vbscript: Implemented CDbl.
[wine.git] / dlls / vbscript / global.c
blob68b76385b65d2c8c3fdd6def0be4fefc445a0695
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_short(VARIANT *res, short val)
96 if(res) {
97 V_VT(res) = VT_I2;
98 V_I2(res) = val;
101 return S_OK;
104 static HRESULT return_int(VARIANT *res, int val)
106 if((short)val == val)
107 return return_short(res, val);
109 if(res) {
110 V_VT(res) = VT_I4;
111 V_I4(res) = val;
114 return S_OK;
117 static inline HRESULT return_double(VARIANT *res, double val)
119 if(res) {
120 V_VT(res) = VT_R8;
121 V_R8(res) = val;
124 return S_OK;
127 static inline HRESULT return_null(VARIANT *res)
129 if(res)
130 V_VT(res) = VT_NULL;
131 return S_OK;
134 static inline HRESULT return_date(VARIANT *res, double date)
136 if(res) {
137 V_VT(res) = VT_DATE;
138 V_DATE(res) = date;
140 return S_OK;
143 HRESULT to_int(VARIANT *v, int *ret)
145 if(V_VT(v) == (VT_BYREF|VT_VARIANT))
146 v = V_VARIANTREF(v);
148 switch(V_VT(v)) {
149 case VT_I2:
150 *ret = V_I2(v);
151 break;
152 case VT_I4:
153 *ret = V_I4(v);
154 break;
155 case VT_R8: {
156 double n = floor(V_R8(v)+0.5);
157 INT32 i;
159 if(!is_int32(n)) {
160 FIXME("%lf is out of int range\n", n);
161 return E_FAIL;
164 /* Round half to even */
165 i = n;
166 if(i%2 && n-V_R8(v) == 0.5)
167 i--;
169 *ret = i;
170 break;
172 case VT_BOOL:
173 *ret = V_BOOL(v) ? -1 : 0;
174 break;
175 default:
176 FIXME("not supported %s\n", debugstr_variant(v));
177 return E_NOTIMPL;
180 return S_OK;
183 static HRESULT to_double(VARIANT *v, double *ret)
185 switch(V_VT(v)) {
186 case VT_I2:
187 *ret = V_I2(v);
188 break;
189 case VT_I4:
190 *ret = V_I4(v);
191 break;
192 case VT_R4:
193 *ret = V_R4(v);
194 break;
195 case VT_R8:
196 *ret = V_R8(v);
197 break;
198 case VT_BSTR: {
199 VARIANT dst;
200 HRESULT hres;
202 V_VT(&dst) = VT_EMPTY;
203 hres = VariantChangeType(&dst, v, VARIANT_LOCALBOOL, VT_R8);
204 if(FAILED(hres))
205 return hres;
206 *ret = V_R8(&dst);
207 break;
209 default:
210 FIXME("arg %s not supported\n", debugstr_variant(v));
211 return E_NOTIMPL;
214 return S_OK;
217 static HRESULT to_string(VARIANT *v, BSTR *ret)
219 VARIANT dst;
220 HRESULT hres;
222 V_VT(&dst) = VT_EMPTY;
223 hres = VariantChangeType(&dst, v, VARIANT_LOCALBOOL, VT_BSTR);
224 if(FAILED(hres))
225 return hres;
227 *ret = V_BSTR(&dst);
228 return S_OK;
231 static HRESULT set_object_site(script_ctx_t *ctx, IUnknown *obj)
233 IObjectWithSite *obj_site;
234 IUnknown *ax_site;
235 HRESULT hres;
237 hres = IUnknown_QueryInterface(obj, &IID_IObjectWithSite, (void**)&obj_site);
238 if(FAILED(hres))
239 return S_OK;
241 ax_site = create_ax_site(ctx);
242 if(ax_site)
243 hres = IObjectWithSite_SetSite(obj_site, ax_site);
244 else
245 hres = E_OUTOFMEMORY;
246 IUnknown_Release(ax_site);
247 IObjectWithSite_Release(obj_site);
248 return hres;
251 static IUnknown *create_object(script_ctx_t *ctx, const WCHAR *progid)
253 IInternetHostSecurityManager *secmgr = NULL;
254 struct CONFIRMSAFETY cs;
255 IClassFactoryEx *cfex;
256 IClassFactory *cf;
257 DWORD policy_size;
258 BYTE *bpolicy;
259 IUnknown *obj;
260 DWORD policy;
261 GUID guid;
262 HRESULT hres;
264 hres = CLSIDFromProgID(progid, &guid);
265 if(FAILED(hres))
266 return NULL;
268 TRACE("GUID %s\n", debugstr_guid(&guid));
270 if(ctx->safeopt & INTERFACE_USES_SECURITY_MANAGER) {
271 secmgr = get_sec_mgr(ctx);
272 if(!secmgr)
273 return NULL;
275 policy = 0;
276 hres = IInternetHostSecurityManager_ProcessUrlAction(secmgr, URLACTION_ACTIVEX_RUN,
277 (BYTE*)&policy, sizeof(policy), (BYTE*)&guid, sizeof(GUID), 0, 0);
278 if(FAILED(hres) || policy != URLPOLICY_ALLOW)
279 return NULL;
282 hres = CoGetClassObject(&guid, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, NULL, &IID_IClassFactory, (void**)&cf);
283 if(FAILED(hres))
284 return NULL;
286 hres = IClassFactory_QueryInterface(cf, &IID_IClassFactoryEx, (void**)&cfex);
287 if(SUCCEEDED(hres)) {
288 FIXME("Use IClassFactoryEx\n");
289 IClassFactoryEx_Release(cfex);
292 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IUnknown, (void**)&obj);
293 if(FAILED(hres))
294 return NULL;
296 if(secmgr) {
297 cs.clsid = guid;
298 cs.pUnk = obj;
299 cs.dwFlags = 0;
300 hres = IInternetHostSecurityManager_QueryCustomPolicy(secmgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
301 &bpolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
302 if(SUCCEEDED(hres)) {
303 policy = policy_size >= sizeof(DWORD) ? *(DWORD*)bpolicy : URLPOLICY_DISALLOW;
304 CoTaskMemFree(bpolicy);
307 if(FAILED(hres) || policy != URLPOLICY_ALLOW) {
308 IUnknown_Release(obj);
309 return NULL;
313 hres = set_object_site(ctx, obj);
314 if(FAILED(hres)) {
315 IUnknown_Release(obj);
316 return NULL;
319 return obj;
322 static HRESULT show_msgbox(script_ctx_t *ctx, BSTR prompt, VARIANT *res)
324 SCRIPTUICHANDLING uic_handling = SCRIPTUICHANDLING_ALLOW;
325 IActiveScriptSiteUIControl *ui_control;
326 IActiveScriptSiteWindow *acts_window;
327 const WCHAR *title;
328 HWND hwnd = NULL;
329 int ret;
330 HRESULT hres;
332 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IActiveScriptSiteUIControl, (void**)&ui_control);
333 if(SUCCEEDED(hres)) {
334 hres = IActiveScriptSiteUIControl_GetUIBehavior(ui_control, SCRIPTUICITEM_MSGBOX, &uic_handling);
335 IActiveScriptSiteUIControl_Release(ui_control);
336 if(FAILED(hres))
337 uic_handling = SCRIPTUICHANDLING_ALLOW;
340 switch(uic_handling) {
341 case SCRIPTUICHANDLING_ALLOW:
342 break;
343 case SCRIPTUICHANDLING_NOUIDEFAULT:
344 return return_short(res, 0);
345 default:
346 FIXME("blocked\n");
347 return E_FAIL;
350 title = (ctx->safeopt & INTERFACE_USES_SECURITY_MANAGER) ? vbscriptW : emptyW;
352 hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IActiveScriptSiteWindow, (void**)&acts_window);
353 if(FAILED(hres)) {
354 FIXME("No IActiveScriptSiteWindow\n");
355 return hres;
358 hres = IActiveScriptSiteWindow_GetWindow(acts_window, &hwnd);
359 if(SUCCEEDED(hres)) {
360 hres = IActiveScriptSiteWindow_EnableModeless(acts_window, FALSE);
361 if(SUCCEEDED(hres)) {
362 ret = MessageBoxW(hwnd, prompt, title, MB_OK);
363 hres = IActiveScriptSiteWindow_EnableModeless(acts_window, TRUE);
367 IActiveScriptSiteWindow_Release(acts_window);
368 if(FAILED(hres)) {
369 FIXME("failed: %08x\n", hres);
370 return hres;
373 return return_short(res, ret);
376 static HRESULT Global_CCur(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
378 VARIANT v;
379 HRESULT hres;
381 TRACE("%s\n", debugstr_variant(arg));
383 assert(args_cnt == 1);
385 V_VT(&v) = VT_EMPTY;
386 hres = VariantChangeType(&v, arg, 0, VT_CY);
387 if(FAILED(hres))
388 return hres;
390 if(!res) {
391 VariantClear(&v);
392 return DISP_E_BADVARTYPE;
395 *res = v;
396 return S_OK;
399 static HRESULT Global_CInt(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
401 int val;
402 HRESULT hres;
404 TRACE("%s\n", debugstr_variant(arg));
406 assert(args_cnt == 1);
408 hres = to_int(arg, &val);
409 if(FAILED(hres))
410 return hres;
412 return return_int(res, val);
415 static HRESULT Global_CLng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
417 FIXME("\n");
418 return E_NOTIMPL;
421 static HRESULT Global_CBool(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
423 VARIANT v;
424 HRESULT hres;
426 TRACE("%s\n", debugstr_variant(arg));
428 assert(args_cnt == 1);
430 V_VT(&v) = VT_EMPTY;
431 hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_BOOL);
432 if(FAILED(hres))
433 return hres;
435 if(res)
436 *res = v;
437 else
438 VariantClear(&v);
439 return S_OK;
442 static HRESULT Global_CByte(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
444 VARIANT v;
445 HRESULT hres;
447 TRACE("%s\n", debugstr_variant(arg));
449 assert(args_cnt == 1);
451 V_VT(&v) = VT_EMPTY;
452 hres = VariantChangeType(&v, arg, VARIANT_LOCALBOOL, VT_UI1);
453 if(FAILED(hres))
454 return hres;
456 if(!res) {
457 VariantClear(&v);
458 return DISP_E_BADVARTYPE;
461 *res = v;
462 return S_OK;
465 static HRESULT Global_CDate(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
467 FIXME("\n");
468 return E_NOTIMPL;
471 static HRESULT Global_CDbl(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
473 VARIANT v;
474 HRESULT hres;
476 TRACE("%s\n", debugstr_variant(arg));
478 assert(args_cnt == 1);
480 V_VT(&v) = VT_EMPTY;
481 hres = VariantChangeType(&v, arg, 0, VT_R8);
482 if(FAILED(hres))
483 return hres;
485 if(!res)
486 return DISP_E_BADVARTYPE;
487 else {
488 *res = v;
489 return S_OK;
493 static HRESULT Global_CSng(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
495 FIXME("\n");
496 return E_NOTIMPL;
499 static HRESULT Global_CStr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
501 BSTR str;
502 HRESULT hres;
504 TRACE("%s\n", debugstr_variant(arg));
506 hres = to_string(arg, &str);
507 if(FAILED(hres))
508 return hres;
510 return return_bstr(res, str);
513 static inline WCHAR hex_char(unsigned n)
515 return n < 10 ? '0'+n : 'A'+n-10;
518 static HRESULT Global_Hex(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
520 WCHAR buf[17], *ptr;
521 DWORD n;
523 TRACE("%s\n", debugstr_variant(arg));
525 switch(V_VT(arg)) {
526 case VT_I2:
527 n = (WORD)V_I2(arg);
528 break;
529 case VT_I4:
530 n = V_I4(arg);
531 break;
532 case VT_EMPTY:
533 n = 0;
534 break;
535 case VT_NULL:
536 if(res)
537 V_VT(res) = VT_NULL;
538 return S_OK;
539 default:
540 FIXME("unsupported type %s\n", debugstr_variant(arg));
541 return E_NOTIMPL;
544 buf[16] = 0;
545 ptr = buf+15;
547 if(n) {
548 do {
549 *ptr-- = hex_char(n & 0xf);
550 n >>= 4;
551 }while(n);
552 ptr++;
553 }else {
554 *ptr = '0';
557 return return_string(res, ptr);
560 static HRESULT Global_Oct(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
562 FIXME("\n");
563 return E_NOTIMPL;
566 static HRESULT Global_VarType(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
568 FIXME("\n");
569 return E_NOTIMPL;
572 static HRESULT Global_IsDate(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
574 FIXME("\n");
575 return E_NOTIMPL;
578 static HRESULT Global_IsEmpty(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
580 TRACE("(%s)\n", debugstr_variant(arg));
582 assert(args_cnt == 1);
584 if(res) {
585 V_VT(res) = VT_BOOL;
586 V_BOOL(res) = V_VT(arg) == VT_EMPTY ? VARIANT_TRUE : VARIANT_FALSE;
588 return S_OK;
591 static HRESULT Global_IsNull(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
593 TRACE("(%s)\n", debugstr_variant(arg));
595 assert(args_cnt == 1);
597 if(res) {
598 V_VT(res) = VT_BOOL;
599 V_BOOL(res) = V_VT(arg) == VT_NULL ? VARIANT_TRUE : VARIANT_FALSE;
601 return S_OK;
604 static HRESULT Global_IsNumeric(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
606 FIXME("\n");
607 return E_NOTIMPL;
610 static HRESULT Global_IsArray(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
612 FIXME("\n");
613 return E_NOTIMPL;
616 static HRESULT Global_IsObject(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
618 TRACE("(%s)\n", debugstr_variant(arg));
620 assert(args_cnt == 1);
622 if(res) {
623 V_VT(res) = VT_BOOL;
624 V_BOOL(res) = V_VT(arg) == VT_DISPATCH ? VARIANT_TRUE : VARIANT_FALSE;
626 return S_OK;
629 static HRESULT Global_Ant(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
631 FIXME("\n");
632 return E_NOTIMPL;
635 static HRESULT Global_Cos(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
637 FIXME("\n");
638 return E_NOTIMPL;
641 static HRESULT Global_Sin(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
643 FIXME("\n");
644 return E_NOTIMPL;
647 static HRESULT Global_Tan(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
649 FIXME("\n");
650 return E_NOTIMPL;
653 static HRESULT Global_Exp(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
655 FIXME("\n");
656 return E_NOTIMPL;
659 static HRESULT Global_Log(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
661 FIXME("\n");
662 return E_NOTIMPL;
665 static HRESULT Global_Sqr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
667 FIXME("\n");
668 return E_NOTIMPL;
671 static HRESULT Global_Randomize(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
673 FIXME("\n");
674 return E_NOTIMPL;
677 static HRESULT Global_Rnd(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
679 FIXME("\n");
680 return E_NOTIMPL;
683 static HRESULT Global_Timer(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
685 FIXME("\n");
686 return E_NOTIMPL;
689 static HRESULT Global_LBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
691 FIXME("\n");
692 return E_NOTIMPL;
695 static HRESULT Global_UBound(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
697 FIXME("\n");
698 return E_NOTIMPL;
701 static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
703 FIXME("\n");
704 return E_NOTIMPL;
707 static HRESULT Global_Len(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
709 DWORD len;
710 HRESULT hres;
712 TRACE("%s\n", debugstr_variant(arg));
714 if(V_VT(arg) == VT_NULL)
715 return return_null(res);
717 if(V_VT(arg) != VT_BSTR) {
718 BSTR str;
720 hres = to_string(arg, &str);
721 if(FAILED(hres))
722 return hres;
724 len = SysStringLen(str);
725 SysFreeString(str);
726 }else {
727 len = SysStringLen(V_BSTR(arg));
730 return return_int(res, len);
733 static HRESULT Global_LenB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
735 FIXME("\n");
736 return E_NOTIMPL;
739 static HRESULT Global_Left(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
741 BSTR str, ret, conv_str = NULL;
742 int len, str_len;
743 HRESULT hres;
745 TRACE("(%s %s)\n", debugstr_variant(args+1), debugstr_variant(args));
747 if(V_VT(args) == VT_BSTR) {
748 str = V_BSTR(args);
749 }else {
750 hres = to_string(args, &conv_str);
751 if(FAILED(hres))
752 return hres;
753 str = conv_str;
756 hres = to_int(args+1, &len);
757 if(FAILED(hres))
758 return hres;
760 if(len < 0) {
761 FIXME("len = %d\n", len);
762 return E_FAIL;
765 str_len = SysStringLen(str);
766 if(len > str_len)
767 len = str_len;
769 ret = SysAllocStringLen(str, len);
770 SysFreeString(conv_str);
771 if(!ret)
772 return E_OUTOFMEMORY;
774 return return_bstr(res, ret);
777 static HRESULT Global_LeftB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
779 FIXME("\n");
780 return E_NOTIMPL;
783 static HRESULT Global_Right(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
785 BSTR str, ret, conv_str = NULL;
786 int len, str_len;
787 HRESULT hres;
789 TRACE("(%s %s)\n", debugstr_variant(args), debugstr_variant(args+1));
791 if(V_VT(args+1) == VT_BSTR) {
792 str = V_BSTR(args);
793 }else {
794 hres = to_string(args, &conv_str);
795 if(FAILED(hres))
796 return hres;
797 str = conv_str;
800 hres = to_int(args+1, &len);
801 if(FAILED(hres))
802 return hres;
804 if(len < 0) {
805 FIXME("len = %d\n", len);
806 return E_FAIL;
809 str_len = SysStringLen(str);
810 if(len > str_len)
811 len = str_len;
813 ret = SysAllocStringLen(str+str_len-len, len);
814 SysFreeString(conv_str);
815 if(!ret)
816 return E_OUTOFMEMORY;
818 return return_bstr(res, ret);
821 static HRESULT Global_RightB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
823 FIXME("\n");
824 return E_NOTIMPL;
827 static HRESULT Global_Mid(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
829 int len = -1, start, str_len;
830 BSTR str;
831 HRESULT hres;
833 TRACE("(%s %s ...)\n", debugstr_variant(args), debugstr_variant(args+1));
835 assert(args_cnt == 2 || args_cnt == 3);
837 if(V_VT(args) != VT_BSTR) {
838 FIXME("args[0] = %s\n", debugstr_variant(args));
839 return E_NOTIMPL;
842 str = V_BSTR(args);
844 hres = to_int(args+1, &start);
845 if(FAILED(hres))
846 return hres;
848 if(args_cnt == 3) {
849 hres = to_int(args+2, &len);
850 if(FAILED(hres))
851 return hres;
853 if(len < 0) {
854 FIXME("len = %d\n", len);
855 return E_FAIL;
860 str_len = SysStringLen(str);
861 start--;
862 if(start > str_len)
863 start = str_len;
865 if(len == -1)
866 len = str_len-start;
867 else if(len > str_len-start)
868 len = str_len-start;
870 if(res) {
871 V_VT(res) = VT_BSTR;
872 V_BSTR(res) = SysAllocStringLen(str+start, len);
873 if(!V_BSTR(res))
874 return E_OUTOFMEMORY;
877 return S_OK;
880 static HRESULT Global_MidB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
882 FIXME("\n");
883 return E_NOTIMPL;
886 static HRESULT Global_StrComp(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
888 FIXME("\n");
889 return E_NOTIMPL;
892 static HRESULT Global_LCase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
894 BSTR str;
895 HRESULT hres;
897 TRACE("%s\n", debugstr_variant(arg));
899 if(V_VT(arg) == VT_NULL) {
900 if(res)
901 V_VT(res) = VT_NULL;
902 return S_OK;
905 hres = to_string(arg, &str);
906 if(FAILED(hres))
907 return hres;
909 if(res) {
910 WCHAR *ptr;
912 for(ptr = str; *ptr; ptr++)
913 *ptr = tolowerW(*ptr);
915 V_VT(res) = VT_BSTR;
916 V_BSTR(res) = str;
917 }else {
918 SysFreeString(str);
920 return S_OK;
923 static HRESULT Global_UCase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
925 BSTR str;
926 HRESULT hres;
928 TRACE("%s\n", debugstr_variant(arg));
930 if(V_VT(arg) == VT_NULL) {
931 if(res)
932 V_VT(res) = VT_NULL;
933 return S_OK;
936 hres = to_string(arg, &str);
937 if(FAILED(hres))
938 return hres;
940 if(res) {
941 WCHAR *ptr;
943 for(ptr = str; *ptr; ptr++)
944 *ptr = toupperW(*ptr);
946 V_VT(res) = VT_BSTR;
947 V_BSTR(res) = str;
948 }else {
949 SysFreeString(str);
951 return S_OK;
954 static HRESULT Global_LTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
956 BSTR str, conv_str = NULL;
957 WCHAR *ptr;
958 HRESULT hres;
960 TRACE("%s\n", debugstr_variant(arg));
962 if(V_VT(arg) == VT_BSTR) {
963 str = V_BSTR(arg);
964 }else {
965 hres = to_string(arg, &conv_str);
966 if(FAILED(hres))
967 return hres;
968 str = conv_str;
971 for(ptr = str; *ptr && isspaceW(*ptr); ptr++);
973 str = SysAllocString(ptr);
974 SysFreeString(conv_str);
975 if(!str)
976 return E_OUTOFMEMORY;
978 return return_bstr(res, str);
981 static HRESULT Global_RTrim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
983 BSTR str, conv_str = NULL;
984 WCHAR *ptr;
985 HRESULT hres;
987 TRACE("%s\n", debugstr_variant(arg));
989 if(V_VT(arg) == VT_BSTR) {
990 str = V_BSTR(arg);
991 }else {
992 hres = to_string(arg, &conv_str);
993 if(FAILED(hres))
994 return hres;
995 str = conv_str;
998 for(ptr = str+SysStringLen(str); ptr-1 > str && isspaceW(*(ptr-1)); ptr--);
1000 str = SysAllocStringLen(str, ptr-str);
1001 SysFreeString(conv_str);
1002 if(!str)
1003 return E_OUTOFMEMORY;
1005 return return_bstr(res, str);
1008 static HRESULT Global_Trim(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1010 BSTR str, conv_str = NULL;
1011 WCHAR *begin_ptr, *end_ptr;
1012 HRESULT hres;
1014 TRACE("%s\n", debugstr_variant(arg));
1016 if(V_VT(arg) == VT_BSTR) {
1017 str = V_BSTR(arg);
1018 }else {
1019 hres = to_string(arg, &conv_str);
1020 if(FAILED(hres))
1021 return hres;
1022 str = conv_str;
1025 for(begin_ptr = str; *begin_ptr && isspaceW(*begin_ptr); begin_ptr++);
1026 for(end_ptr = str+SysStringLen(str); end_ptr-1 > begin_ptr && isspaceW(*(end_ptr-1)); end_ptr--);
1028 str = SysAllocStringLen(begin_ptr, end_ptr-begin_ptr);
1029 SysFreeString(conv_str);
1030 if(!str)
1031 return E_OUTOFMEMORY;
1033 return return_bstr(res, str);
1036 static HRESULT Global_Space(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1038 BSTR str;
1039 int n, i;
1040 HRESULT hres;
1042 TRACE("%s\n", debugstr_variant(arg));
1044 hres = to_int(arg, &n);
1045 if(FAILED(hres))
1046 return hres;
1048 if(n < 0) {
1049 FIXME("n = %d\n", n);
1050 return E_NOTIMPL;
1053 if(!res)
1054 return S_OK;
1056 str = SysAllocStringLen(NULL, n);
1057 if(!str)
1058 return E_OUTOFMEMORY;
1060 for(i=0; i<n; i++)
1061 str[i] = ' ';
1063 V_VT(res) = VT_BSTR;
1064 V_BSTR(res) = str;
1065 return S_OK;
1068 static HRESULT Global_String(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1070 FIXME("\n");
1071 return E_NOTIMPL;
1074 static HRESULT Global_InStr(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1076 VARIANT *startv, *str1v, *str2v;
1077 BSTR str1, str2;
1078 int start, ret;
1079 HRESULT hres;
1081 TRACE("\n");
1083 assert(2 <= args_cnt && args_cnt <= 4);
1085 switch(args_cnt) {
1086 case 2:
1087 startv = NULL;
1088 str1v = args;
1089 str2v = args+1;
1090 break;
1091 case 3:
1092 startv = args;
1093 str1v = args+1;
1094 str2v = args+2;
1095 break;
1096 case 4:
1097 FIXME("unsupported compare argument %s\n", debugstr_variant(args));
1098 return E_NOTIMPL;
1099 DEFAULT_UNREACHABLE;
1102 if(startv) {
1103 hres = to_int(startv, &start);
1104 if(FAILED(hres))
1105 return hres;
1106 if(--start < 0) {
1107 FIXME("start %d\n", start);
1108 return E_FAIL;
1110 }else {
1111 start = 0;
1114 if(V_VT(str1v) == VT_NULL || V_VT(str2v) == VT_NULL)
1115 return return_null(res);
1117 if(V_VT(str1v) != VT_BSTR) {
1118 FIXME("Unsupported str1 type %s\n", debugstr_variant(str1v));
1119 return E_NOTIMPL;
1121 str1 = V_BSTR(str1v);
1123 if(V_VT(str2v) != VT_BSTR) {
1124 FIXME("Unsupported str2 type %s\n", debugstr_variant(str2v));
1125 return E_NOTIMPL;
1127 str2 = V_BSTR(str2v);
1129 if(start < SysStringLen(str1)) {
1130 WCHAR *ptr;
1132 ptr = strstrW(str1+start, str2);
1133 ret = ptr ? ptr-str1+1 : 0;
1134 }else {
1135 ret = 0;
1138 return return_int(res, ret);
1141 static HRESULT Global_InStrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1143 FIXME("\n");
1144 return E_NOTIMPL;
1147 static HRESULT Global_AscB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1149 FIXME("\n");
1150 return E_NOTIMPL;
1153 static HRESULT Global_ChrB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1155 FIXME("\n");
1156 return E_NOTIMPL;
1159 static HRESULT Global_Asc(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1161 FIXME("\n");
1162 return E_NOTIMPL;
1165 /* The function supports only single-byte and double-byte character sets. It
1166 * ignores language specified by IActiveScriptSite::GetLCID. The argument needs
1167 * to be in range of short or unsigned short. */
1168 static HRESULT Global_Chr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1170 int cp, c, len = 0;
1171 CPINFO cpi;
1172 WCHAR ch;
1173 char buf[2];
1174 HRESULT hres;
1176 TRACE("%s\n", debugstr_variant(arg));
1178 hres = to_int(arg, &c);
1179 if(FAILED(hres))
1180 return hres;
1182 cp = GetACP();
1183 if(!GetCPInfo(cp, &cpi))
1184 cpi.MaxCharSize = 1;
1186 if((c!=(short)c && c!=(unsigned short)c) ||
1187 (unsigned short)c>=(cpi.MaxCharSize>1 ? 0x10000 : 0x100)) {
1188 WARN("invalid arg %d\n", c);
1189 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
1192 if(c>>8)
1193 buf[len++] = c>>8;
1194 if(!len || IsDBCSLeadByteEx(cp, buf[0]))
1195 buf[len++] = c;
1196 if(!MultiByteToWideChar(0, 0, buf, len, &ch, 1)) {
1197 WARN("invalid arg %d, cp %d\n", c, cp);
1198 return E_FAIL;
1201 if(res) {
1202 V_VT(res) = VT_BSTR;
1203 V_BSTR(res) = SysAllocStringLen(&ch, 1);
1204 if(!V_BSTR(res))
1205 return E_OUTOFMEMORY;
1207 return S_OK;
1210 static HRESULT Global_AscW(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1212 FIXME("\n");
1213 return E_NOTIMPL;
1216 static HRESULT Global_ChrW(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1218 FIXME("\n");
1219 return E_NOTIMPL;
1222 static HRESULT Global_Abs(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1224 FIXME("\n");
1225 return E_NOTIMPL;
1228 static HRESULT Global_Fix(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1230 FIXME("\n");
1231 return E_NOTIMPL;
1234 static HRESULT Global_Int(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1236 FIXME("\n");
1237 return E_NOTIMPL;
1240 static HRESULT Global_Sgn(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1242 FIXME("\n");
1243 return E_NOTIMPL;
1246 static HRESULT Global_Now(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1248 SYSTEMTIME lt;
1249 double date;
1251 TRACE("\n");
1253 GetLocalTime(&lt);
1254 SystemTimeToVariantTime(&lt, &date);
1255 return return_date(res, date);
1258 static HRESULT Global_Date(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1260 FIXME("\n");
1261 return E_NOTIMPL;
1264 static HRESULT Global_Time(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1266 FIXME("\n");
1267 return E_NOTIMPL;
1270 static HRESULT Global_Day(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1272 FIXME("\n");
1273 return E_NOTIMPL;
1276 static HRESULT Global_Month(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1278 FIXME("\n");
1279 return E_NOTIMPL;
1282 static HRESULT Global_Weekday(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1284 FIXME("\n");
1285 return E_NOTIMPL;
1288 static HRESULT Global_Year(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1290 FIXME("\n");
1291 return E_NOTIMPL;
1294 static HRESULT Global_Hour(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1296 FIXME("\n");
1297 return E_NOTIMPL;
1300 static HRESULT Global_Minute(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1302 FIXME("\n");
1303 return E_NOTIMPL;
1306 static HRESULT Global_Second(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1308 FIXME("\n");
1309 return E_NOTIMPL;
1312 static HRESULT Global_DateValue(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1314 FIXME("\n");
1315 return E_NOTIMPL;
1318 static HRESULT Global_TimeValue(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1320 FIXME("\n");
1321 return E_NOTIMPL;
1324 static HRESULT Global_DateSerial(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1326 FIXME("\n");
1327 return E_NOTIMPL;
1330 static HRESULT Global_TimeSerial(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1332 FIXME("\n");
1333 return E_NOTIMPL;
1336 static HRESULT Global_InputBox(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1338 FIXME("\n");
1339 return E_NOTIMPL;
1342 static HRESULT Global_MsgBox(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1344 BSTR prompt;
1345 HRESULT hres;
1347 TRACE("\n");
1349 if(args_cnt != 1) {
1350 FIXME("unsupported arg_cnt %d\n", args_cnt);
1351 return E_NOTIMPL;
1354 hres = to_string(args, &prompt);
1355 if(FAILED(hres))
1356 return hres;
1358 hres = show_msgbox(This->desc->ctx, prompt, res);
1359 SysFreeString(prompt);
1360 return hres;
1363 static HRESULT Global_CreateObject(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1365 IUnknown *obj;
1366 HRESULT hres;
1368 TRACE("(%s)\n", debugstr_variant(arg));
1370 if(V_VT(arg) != VT_BSTR) {
1371 FIXME("non-bstr arg\n");
1372 return E_INVALIDARG;
1375 obj = create_object(This->desc->ctx, V_BSTR(arg));
1376 if(!obj)
1377 return VB_E_CANNOT_CREATE_OBJ;
1379 if(res) {
1380 hres = IUnknown_QueryInterface(obj, &IID_IDispatch, (void**)&V_DISPATCH(res));
1381 if(FAILED(hres))
1382 return hres;
1384 V_VT(res) = VT_DISPATCH;
1387 IUnknown_Release(obj);
1388 return S_OK;
1391 static HRESULT Global_GetObject(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1393 IBindCtx *bind_ctx;
1394 IUnknown *obj_unk;
1395 IDispatch *disp;
1396 ULONG eaten = 0;
1397 IMoniker *mon;
1398 HRESULT hres;
1400 TRACE("%s %s\n", args_cnt ? debugstr_variant(args) : "", args_cnt > 1 ? debugstr_variant(args+1) : "");
1402 if(args_cnt != 1 || V_VT(args) != VT_BSTR) {
1403 FIXME("unsupported args\n");
1404 return E_NOTIMPL;
1407 if(This->desc->ctx->safeopt & (INTERFACE_USES_SECURITY_MANAGER|INTERFACESAFE_FOR_UNTRUSTED_DATA)) {
1408 WARN("blocked in current safety mode\n");
1409 return VB_E_CANNOT_CREATE_OBJ;
1412 hres = CreateBindCtx(0, &bind_ctx);
1413 if(FAILED(hres))
1414 return hres;
1416 hres = MkParseDisplayName(bind_ctx, V_BSTR(args), &eaten, &mon);
1417 if(SUCCEEDED(hres)) {
1418 hres = IMoniker_BindToObject(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&obj_unk);
1419 IMoniker_Release(mon);
1420 }else {
1421 hres = MK_E_SYNTAX;
1423 IBindCtx_Release(bind_ctx);
1424 if(FAILED(hres))
1425 return hres;
1427 hres = set_object_site(This->desc->ctx, obj_unk);
1428 if(FAILED(hres)) {
1429 IUnknown_Release(obj_unk);
1430 return hres;
1433 hres = IUnknown_QueryInterface(obj_unk, &IID_IDispatch, (void**)&disp);
1434 if(SUCCEEDED(hres)) {
1435 if(res) {
1436 V_VT(res) = VT_DISPATCH;
1437 V_DISPATCH(res) = disp;
1438 }else {
1439 IDispatch_Release(disp);
1441 }else {
1442 FIXME("object does not support IDispatch\n");
1445 return hres;
1448 static HRESULT Global_DateAdd(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1450 FIXME("\n");
1451 return E_NOTIMPL;
1454 static HRESULT Global_DateDiff(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1456 FIXME("\n");
1457 return E_NOTIMPL;
1460 static HRESULT Global_DatePart(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1462 FIXME("\n");
1463 return E_NOTIMPL;
1466 static HRESULT Global_TypeName(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1468 FIXME("\n");
1469 return E_NOTIMPL;
1472 static HRESULT Global_Array(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1474 FIXME("\n");
1475 return E_NOTIMPL;
1478 static HRESULT Global_Erase(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1480 FIXME("\n");
1481 return E_NOTIMPL;
1484 static HRESULT Global_Filter(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1486 FIXME("\n");
1487 return E_NOTIMPL;
1490 static HRESULT Global_Join(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1492 FIXME("\n");
1493 return E_NOTIMPL;
1496 static HRESULT Global_Split(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1498 FIXME("\n");
1499 return E_NOTIMPL;
1502 static HRESULT Global_Replace(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1504 FIXME("\n");
1505 return E_NOTIMPL;
1508 static HRESULT Global_StrReverse(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1510 WCHAR *ptr1, *ptr2, ch;
1511 BSTR ret;
1512 HRESULT hres;
1514 TRACE("%s\n", debugstr_variant(arg));
1516 hres = to_string(arg, &ret);
1517 if(FAILED(hres))
1518 return hres;
1520 ptr1 = ret;
1521 ptr2 = ret + SysStringLen(ret)-1;
1522 while(ptr1 < ptr2) {
1523 ch = *ptr1;
1524 *ptr1++ = *ptr2;
1525 *ptr2-- = ch;
1528 return return_bstr(res, ret);
1531 static HRESULT Global_InStrRev(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1533 FIXME("\n");
1534 return E_NOTIMPL;
1537 static HRESULT Global_LoadPicture(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1539 FIXME("\n");
1540 return E_NOTIMPL;
1543 static HRESULT Global_ScriptEngine(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1545 FIXME("\n");
1546 return E_NOTIMPL;
1549 static HRESULT Global_ScriptEngineMajorVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1551 FIXME("\n");
1552 return E_NOTIMPL;
1555 static HRESULT Global_ScriptEngineMinorVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1557 FIXME("\n");
1558 return E_NOTIMPL;
1561 static HRESULT Global_ScriptEngineBuildVersion(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1563 FIXME("\n");
1564 return E_NOTIMPL;
1567 static HRESULT Global_FormatNumber(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1569 FIXME("\n");
1570 return E_NOTIMPL;
1573 static HRESULT Global_FormatCurrency(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1575 FIXME("\n");
1576 return E_NOTIMPL;
1579 static HRESULT Global_FormatPercent(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1581 FIXME("\n");
1582 return E_NOTIMPL;
1585 static HRESULT Global_FormatDateTime(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1587 FIXME("\n");
1588 return E_NOTIMPL;
1591 static HRESULT Global_WeekdayName(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1593 int weekday, first_day = 1, abbrev = 0;
1594 BSTR ret;
1595 HRESULT hres;
1597 TRACE("\n");
1599 assert(1 <= args_cnt && args_cnt <= 3);
1601 hres = to_int(args, &weekday);
1602 if(FAILED(hres))
1603 return hres;
1605 if(args_cnt > 1) {
1606 hres = to_int(args+1, &abbrev);
1607 if(FAILED(hres))
1608 return hres;
1610 if(args_cnt == 3) {
1611 hres = to_int(args+2, &first_day);
1612 if(FAILED(hres))
1613 return hres;
1617 hres = VarWeekdayName(weekday, abbrev, first_day, 0, &ret);
1618 if(FAILED(hres))
1619 return hres;
1621 return return_bstr(res, ret);
1624 static HRESULT Global_MonthName(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1626 int month, abbrev = 0;
1627 BSTR ret;
1628 HRESULT hres;
1630 TRACE("\n");
1632 assert(args_cnt == 1 || args_cnt == 2);
1634 hres = to_int(args, &month);
1635 if(FAILED(hres))
1636 return hres;
1638 if(args_cnt == 2) {
1639 hres = to_int(args+1, &abbrev);
1640 if(FAILED(hres))
1641 return hres;
1644 hres = VarMonthName(month, abbrev, 0, &ret);
1645 if(FAILED(hres))
1646 return hres;
1648 return return_bstr(res, ret);
1651 static HRESULT Global_Round(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1653 double n;
1654 HRESULT hres;
1656 TRACE("%s\n", debugstr_variant(arg));
1658 if(!res)
1659 return S_OK;
1661 switch(V_VT(arg)) {
1662 case VT_I2:
1663 case VT_I4:
1664 case VT_BOOL:
1665 *res = *arg;
1666 return S_OK;
1667 case VT_R8:
1668 n = V_R8(arg);
1669 break;
1670 default:
1671 hres = to_double(arg, &n);
1672 if(FAILED(hres))
1673 return hres;
1676 return return_double(res, round(n));
1679 static HRESULT Global_Escape(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1681 FIXME("\n");
1682 return E_NOTIMPL;
1685 static HRESULT Global_Unescape(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1687 FIXME("\n");
1688 return E_NOTIMPL;
1691 static HRESULT Global_Eval(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1693 FIXME("\n");
1694 return E_NOTIMPL;
1697 static HRESULT Global_Execute(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1699 FIXME("\n");
1700 return E_NOTIMPL;
1703 static HRESULT Global_ExecuteGlobal(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1705 FIXME("\n");
1706 return E_NOTIMPL;
1709 static HRESULT Global_GetRef(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
1711 FIXME("\n");
1712 return E_NOTIMPL;
1715 static const string_constant_t vbCr = {1, {'\r'}};
1716 static const string_constant_t vbCrLf = {2, {'\r','\n'}};
1717 static const string_constant_t vbNewLine = {2, {'\r','\n'}};
1718 static const string_constant_t vbFormFeed = {1, {0xc}};
1719 static const string_constant_t vbLf = {1, {'\n'}};
1720 static const string_constant_t vbNullChar = {1};
1721 static const string_constant_t vbNullString = {0};
1722 static const string_constant_t vbTab = {1, {'\t'}};
1723 static const string_constant_t vbVerticalTab = {1, {0xb}};
1725 static const builtin_prop_t global_props[] = {
1726 {DISPID_GLOBAL_VBUSESYSTEM, NULL, BP_GET, VT_I2, 0},
1727 {DISPID_GLOBAL_USESYSTEMDAYOFWEEK, NULL, BP_GET, VT_I2, 0},
1728 {DISPID_GLOBAL_VBSUNDAY, NULL, BP_GET, VT_I2, 1},
1729 {DISPID_GLOBAL_VBMONDAY, NULL, BP_GET, VT_I2, 2},
1730 {DISPID_GLOBAL_VBTUESDAY, NULL, BP_GET, VT_I2, 3},
1731 {DISPID_GLOBAL_VBWEDNESDAY, NULL, BP_GET, VT_I2, 4},
1732 {DISPID_GLOBAL_VBTHURSDAY, NULL, BP_GET, VT_I2, 5},
1733 {DISPID_GLOBAL_VBFRIDAY, NULL, BP_GET, VT_I2, 6},
1734 {DISPID_GLOBAL_VBSATURDAY, NULL, BP_GET, VT_I2, 7},
1735 {DISPID_GLOBAL_VBFIRSTJAN1, NULL, BP_GET, VT_I2, 1},
1736 {DISPID_GLOBAL_VBFIRSTFOURDAYS, NULL, BP_GET, VT_I2, 2},
1737 {DISPID_GLOBAL_VBFIRSTFULLWEEK, NULL, BP_GET, VT_I2, 3},
1738 {DISPID_GLOBAL_VBOKONLY, NULL, BP_GET, VT_I2, MB_OK},
1739 {DISPID_GLOBAL_VBOKCANCEL, NULL, BP_GET, VT_I2, MB_OKCANCEL},
1740 {DISPID_GLOBAL_VBABORTRETRYIGNORE, NULL, BP_GET, VT_I2, MB_ABORTRETRYIGNORE},
1741 {DISPID_GLOBAL_VBYESNOCANCEL, NULL, BP_GET, VT_I2, MB_YESNOCANCEL},
1742 {DISPID_GLOBAL_VBYESNO, NULL, BP_GET, VT_I2, MB_YESNO},
1743 {DISPID_GLOBAL_VBRETRYCANCEL, NULL, BP_GET, VT_I2, MB_RETRYCANCEL},
1744 {DISPID_GLOBAL_VBCRITICAL, NULL, BP_GET, VT_I2, MB_ICONHAND},
1745 {DISPID_GLOBAL_VBQUESTION, NULL, BP_GET, VT_I2, MB_ICONQUESTION},
1746 {DISPID_GLOBAL_VBEXCLAMATION, NULL, BP_GET, VT_I2, MB_ICONEXCLAMATION},
1747 {DISPID_GLOBAL_VBINFORMATION, NULL, BP_GET, VT_I2, MB_ICONASTERISK},
1748 {DISPID_GLOBAL_VBDEFAULTBUTTON1, NULL, BP_GET, VT_I2, MB_DEFBUTTON1},
1749 {DISPID_GLOBAL_VBDEFAULTBUTTON2, NULL, BP_GET, VT_I2, MB_DEFBUTTON2},
1750 {DISPID_GLOBAL_VBDEFAULTBUTTON3, NULL, BP_GET, VT_I2, MB_DEFBUTTON3},
1751 {DISPID_GLOBAL_VBDEFAULTBUTTON4, NULL, BP_GET, VT_I2, MB_DEFBUTTON4},
1752 {DISPID_GLOBAL_VBAPPLICATIONMODAL, NULL, BP_GET, VT_I2, MB_APPLMODAL},
1753 {DISPID_GLOBAL_VBSYSTEMMODAL, NULL, BP_GET, VT_I2, MB_SYSTEMMODAL},
1754 {DISPID_GLOBAL_VBOK, NULL, BP_GET, VT_I2, IDOK},
1755 {DISPID_GLOBAL_VBCANCEL, NULL, BP_GET, VT_I2, IDCANCEL},
1756 {DISPID_GLOBAL_VBABORT, NULL, BP_GET, VT_I2, IDABORT},
1757 {DISPID_GLOBAL_VBRETRY, NULL, BP_GET, VT_I2, IDRETRY},
1758 {DISPID_GLOBAL_VBIGNORE, NULL, BP_GET, VT_I2, IDIGNORE},
1759 {DISPID_GLOBAL_VBYES, NULL, BP_GET, VT_I2, IDYES},
1760 {DISPID_GLOBAL_VBNO, NULL, BP_GET, VT_I2, IDNO},
1761 {DISPID_GLOBAL_VBEMPTY, NULL, BP_GET, VT_I2, VT_EMPTY},
1762 {DISPID_GLOBAL_VBNULL, NULL, BP_GET, VT_I2, VT_NULL},
1763 {DISPID_GLOBAL_VBINTEGER, NULL, BP_GET, VT_I2, VT_I2},
1764 {DISPID_GLOBAL_VBLONG, NULL, BP_GET, VT_I2, VT_I4},
1765 {DISPID_GLOBAL_VBSINGLE, NULL, BP_GET, VT_I2, VT_R4},
1766 {DISPID_GLOBAL_VBDOUBLE, NULL, BP_GET, VT_I2, VT_R8},
1767 {DISPID_GLOBAL_VBCURRENCY, NULL, BP_GET, VT_I2, VT_CY},
1768 {DISPID_GLOBAL_VBDATE, NULL, BP_GET, VT_I2, VT_DATE},
1769 {DISPID_GLOBAL_VBSTRING, NULL, BP_GET, VT_I2, VT_BSTR},
1770 {DISPID_GLOBAL_VBOBJECT, NULL, BP_GET, VT_I2, VT_DISPATCH},
1771 {DISPID_GLOBAL_VBERROR, NULL, BP_GET, VT_I2, VT_ERROR},
1772 {DISPID_GLOBAL_VBBOOLEAN, NULL, BP_GET, VT_I2, VT_BOOL},
1773 {DISPID_GLOBAL_VBVARIANT, NULL, BP_GET, VT_I2, VT_VARIANT},
1774 {DISPID_GLOBAL_VBDATAOBJECT, NULL, BP_GET, VT_I2, VT_UNKNOWN},
1775 {DISPID_GLOBAL_VBDECIMAL, NULL, BP_GET, VT_I2, VT_DECIMAL},
1776 {DISPID_GLOBAL_VBBYTE, NULL, BP_GET, VT_I2, VT_UI1},
1777 {DISPID_GLOBAL_VBARRAY, NULL, BP_GET, VT_I2, VT_ARRAY},
1778 {DISPID_GLOBAL_VBTRUE, NULL, BP_GET, VT_I2, VARIANT_TRUE},
1779 {DISPID_GLOBAL_VBFALSE, NULL, BP_GET, VT_I2, VARIANT_FALSE},
1780 {DISPID_GLOBAL_VBUSEDEFAULT, NULL, BP_GET, VT_I2, -2},
1781 {DISPID_GLOBAL_VBBINARYCOMPARE, NULL, BP_GET, VT_I2, 0},
1782 {DISPID_GLOBAL_VBTEXTCOMPARE, NULL, BP_GET, VT_I2, 1},
1783 {DISPID_GLOBAL_VBDATABASECOMPARE, NULL, BP_GET, VT_I2, 2},
1784 {DISPID_GLOBAL_VBGENERALDATE, NULL, BP_GET, VT_I2, 0},
1785 {DISPID_GLOBAL_VBLONGDATE, NULL, BP_GET, VT_I2, 1},
1786 {DISPID_GLOBAL_VBSHORTDATE, NULL, BP_GET, VT_I2, 2},
1787 {DISPID_GLOBAL_VBLONGTIME, NULL, BP_GET, VT_I2, 3},
1788 {DISPID_GLOBAL_VBSHORTTIME, NULL, BP_GET, VT_I2, 4},
1789 {DISPID_GLOBAL_VBOBJECTERROR, NULL, BP_GET, VT_I4, 0x80040000},
1790 {DISPID_GLOBAL_VBBLACK, NULL, BP_GET, VT_I4, 0x000000},
1791 {DISPID_GLOBAL_VBBLUE, NULL, BP_GET, VT_I4, 0xff0000},
1792 {DISPID_GLOBAL_VBCYAN, NULL, BP_GET, VT_I4, 0xffff00},
1793 {DISPID_GLOBAL_VBGREEN, NULL, BP_GET, VT_I4, 0x00ff00},
1794 {DISPID_GLOBAL_VBMAGENTA, NULL, BP_GET, VT_I4, 0xff00ff},
1795 {DISPID_GLOBAL_VBRED, NULL, BP_GET, VT_I4, 0x0000ff},
1796 {DISPID_GLOBAL_VBWHITE, NULL, BP_GET, VT_I4, 0xffffff},
1797 {DISPID_GLOBAL_VBYELLOW, NULL, BP_GET, VT_I4, 0x00ffff},
1798 {DISPID_GLOBAL_VBCR, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbCr},
1799 {DISPID_GLOBAL_VBCRLF, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbCrLf},
1800 {DISPID_GLOBAL_VBNEWLINE, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNewLine},
1801 {DISPID_GLOBAL_VBFORMFEED, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbFormFeed},
1802 {DISPID_GLOBAL_VBLF, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbLf},
1803 {DISPID_GLOBAL_VBNULLCHAR, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNullChar},
1804 {DISPID_GLOBAL_VBNULLSTRING, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbNullString},
1805 {DISPID_GLOBAL_VBTAB, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbTab},
1806 {DISPID_GLOBAL_VBVERTICALTAB, NULL, BP_GET, VT_BSTR, (UINT_PTR)&vbVerticalTab},
1807 {DISPID_GLOBAL_CCUR, Global_CCur, 0, 1},
1808 {DISPID_GLOBAL_CINT, Global_CInt, 0, 1},
1809 {DISPID_GLOBAL_CLNG, Global_CLng, 0, 1},
1810 {DISPID_GLOBAL_CBOOL, Global_CBool, 0, 1},
1811 {DISPID_GLOBAL_CBYTE, Global_CByte, 0, 1},
1812 {DISPID_GLOBAL_CDATE, Global_CDate, 0, 1},
1813 {DISPID_GLOBAL_CDBL, Global_CDbl, 0, 1},
1814 {DISPID_GLOBAL_CSNG, Global_CSng, 0, 1},
1815 {DISPID_GLOBAL_CSTR, Global_CStr, 0, 1},
1816 {DISPID_GLOBAL_HEX, Global_Hex, 0, 1},
1817 {DISPID_GLOBAL_OCT, Global_Oct, 0, 1},
1818 {DISPID_GLOBAL_VARTYPE, Global_VarType, 0, 1},
1819 {DISPID_GLOBAL_ISDATE, Global_IsDate, 0, 1},
1820 {DISPID_GLOBAL_ISEMPTY, Global_IsEmpty, 0, 1},
1821 {DISPID_GLOBAL_ISNULL, Global_IsNull, 0, 1},
1822 {DISPID_GLOBAL_ISNUMERIC, Global_IsNumeric, 0, 1},
1823 {DISPID_GLOBAL_ISARRAY, Global_IsArray, 0, 1},
1824 {DISPID_GLOBAL_ISOBJECT, Global_IsObject, 0, 1},
1825 {DISPID_GLOBAL_ATN, Global_Ant, 0, 1},
1826 {DISPID_GLOBAL_COS, Global_Cos, 0, 1},
1827 {DISPID_GLOBAL_SIN, Global_Sin, 0, 1},
1828 {DISPID_GLOBAL_TAN, Global_Tan, 0, 1},
1829 {DISPID_GLOBAL_EXP, Global_Exp, 0, 1},
1830 {DISPID_GLOBAL_LOG, Global_Log, 0, 1},
1831 {DISPID_GLOBAL_SQR, Global_Sqr, 0, 1},
1832 {DISPID_GLOBAL_RANDOMIZE, Global_Randomize, 0, 1},
1833 {DISPID_GLOBAL_RND, Global_Rnd, 0, 1},
1834 {DISPID_GLOBAL_TIMER, Global_Timer, 0, 0},
1835 {DISPID_GLOBAL_LBOUND, Global_LBound, 0, 1},
1836 {DISPID_GLOBAL_UBOUND, Global_UBound, 0, 1},
1837 {DISPID_GLOBAL_RGB, Global_RGB, 0, 3},
1838 {DISPID_GLOBAL_LEN, Global_Len, 0, 1},
1839 {DISPID_GLOBAL_LENB, Global_LenB, 0, 1},
1840 {DISPID_GLOBAL_LEFT, Global_Left, 0, 2},
1841 {DISPID_GLOBAL_LEFTB, Global_LeftB, 0, 2},
1842 {DISPID_GLOBAL_RIGHT, Global_Right, 0, 2},
1843 {DISPID_GLOBAL_RIGHTB, Global_RightB, 0, 2},
1844 {DISPID_GLOBAL_MID, Global_Mid, 0, 2, 3},
1845 {DISPID_GLOBAL_MIDB, Global_MidB, 0, 2, 3},
1846 {DISPID_GLOBAL_STRCOMP, Global_StrComp, 0, 2, 3},
1847 {DISPID_GLOBAL_LCASE, Global_LCase, 0, 1},
1848 {DISPID_GLOBAL_UCASE, Global_UCase, 0, 1},
1849 {DISPID_GLOBAL_LTRIM, Global_LTrim, 0, 1},
1850 {DISPID_GLOBAL_RTRIM, Global_RTrim, 0, 1},
1851 {DISPID_GLOBAL_TRIM, Global_Trim, 0, 1},
1852 {DISPID_GLOBAL_SPACE, Global_Space, 0, 1},
1853 {DISPID_GLOBAL_STRING, Global_String, 0, 0, 2},
1854 {DISPID_GLOBAL_INSTR, Global_InStr, 0, 2, 4},
1855 {DISPID_GLOBAL_INSTRB, Global_InStrB, 0, 3, 4},
1856 {DISPID_GLOBAL_ASCB, Global_AscB, 0, 1},
1857 {DISPID_GLOBAL_CHRB, Global_ChrB, 0, 1},
1858 {DISPID_GLOBAL_ASC, Global_Asc, 0, 1},
1859 {DISPID_GLOBAL_CHR, Global_Chr, 0, 1},
1860 {DISPID_GLOBAL_ASCW, Global_AscW, 0, 1},
1861 {DISPID_GLOBAL_CHRW, Global_ChrW, 0, 1},
1862 {DISPID_GLOBAL_ABS, Global_Abs, 0, 1},
1863 {DISPID_GLOBAL_FIX, Global_Fix, 0, 1},
1864 {DISPID_GLOBAL_INT, Global_Int, 0, 1},
1865 {DISPID_GLOBAL_SGN, Global_Sgn, 0, 1},
1866 {DISPID_GLOBAL_NOW, Global_Now, 0, 0},
1867 {DISPID_GLOBAL_DATE, Global_Date, 0, 0},
1868 {DISPID_GLOBAL_TIME, Global_Time, 0, 0},
1869 {DISPID_GLOBAL_DAY, Global_Day, 0, 1},
1870 {DISPID_GLOBAL_MONTH, Global_Month, 0, 1},
1871 {DISPID_GLOBAL_WEEKDAY, Global_Weekday, 0, 1, 2},
1872 {DISPID_GLOBAL_YEAR, Global_Year, 0, 1},
1873 {DISPID_GLOBAL_HOUR, Global_Hour, 0, 1},
1874 {DISPID_GLOBAL_MINUTE, Global_Minute, 0, 1},
1875 {DISPID_GLOBAL_SECOND, Global_Second, 0, 1},
1876 {DISPID_GLOBAL_DATEVALUE, Global_DateValue, 0, 1},
1877 {DISPID_GLOBAL_TIMEVALUE, Global_TimeValue, 0, 1},
1878 {DISPID_GLOBAL_DATESERIAL, Global_DateSerial, 0, 3},
1879 {DISPID_GLOBAL_TIMESERIAL, Global_TimeSerial, 0, 3},
1880 {DISPID_GLOBAL_INPUTBOX, Global_InputBox, 0, 1, 7},
1881 {DISPID_GLOBAL_MSGBOX, Global_MsgBox, 0, 1, 5},
1882 {DISPID_GLOBAL_CREATEOBJECT, Global_CreateObject, 0, 1},
1883 {DISPID_GLOBAL_GETOBJECT, Global_GetObject, 0, 0, 2},
1884 {DISPID_GLOBAL_DATEADD, Global_DateAdd, 0, 3},
1885 {DISPID_GLOBAL_DATEDIFF, Global_DateDiff, 0, 3, 5},
1886 {DISPID_GLOBAL_DATEPART, Global_DatePart, 0, 2, 4},
1887 {DISPID_GLOBAL_TYPENAME, Global_TypeName, 0, 1},
1888 {DISPID_GLOBAL_ARRAY, Global_Array, 0, 1},
1889 {DISPID_GLOBAL_ERASE, Global_Erase, 0, 1},
1890 {DISPID_GLOBAL_FILTER, Global_Filter, 0, 2, 4},
1891 {DISPID_GLOBAL_JOIN, Global_Join, 0, 1, 2},
1892 {DISPID_GLOBAL_SPLIT, Global_Split, 0, 1, 4},
1893 {DISPID_GLOBAL_REPLACE, Global_Replace, 0, 3, 6},
1894 {DISPID_GLOBAL_STRREVERSE, Global_StrReverse, 0, 1},
1895 {DISPID_GLOBAL_INSTRREV, Global_InStrRev, 0, 2, 4},
1896 {DISPID_GLOBAL_LOADPICTURE, Global_LoadPicture, 0, 1},
1897 {DISPID_GLOBAL_SCRIPTENGINE, Global_ScriptEngine, 0, 0},
1898 {DISPID_GLOBAL_SCRIPTENGINEMAJORVERSION, Global_ScriptEngineMajorVersion, 0, 0},
1899 {DISPID_GLOBAL_SCRIPTENGINEMINORVERSION, Global_ScriptEngineMinorVersion, 0, 0},
1900 {DISPID_GLOBAL_SCRIPTENGINEBUILDVERSION, Global_ScriptEngineBuildVersion, 0, 0},
1901 {DISPID_GLOBAL_FORMATNUMBER, Global_FormatNumber, 0, 1, 5},
1902 {DISPID_GLOBAL_FORMATCURRENCY, Global_FormatCurrency, 0, 1, 5},
1903 {DISPID_GLOBAL_FORMATPERCENT, Global_FormatPercent, 0, 1, 5},
1904 {DISPID_GLOBAL_FORMATDATETIME, Global_FormatDateTime, 0, 1, 2},
1905 {DISPID_GLOBAL_WEEKDAYNAME, Global_WeekdayName, 0, 1, 3},
1906 {DISPID_GLOBAL_MONTHNAME, Global_MonthName, 0, 1, 2},
1907 {DISPID_GLOBAL_ROUND, Global_Round, 0, 1, 2},
1908 {DISPID_GLOBAL_ESCAPE, Global_Escape, 0, 1},
1909 {DISPID_GLOBAL_UNESCAPE, Global_Unescape, 0, 1},
1910 {DISPID_GLOBAL_EVAL, Global_Eval, 0, 1},
1911 {DISPID_GLOBAL_EXECUTE, Global_Execute, 0, 1},
1912 {DISPID_GLOBAL_EXECUTEGLOBAL, Global_ExecuteGlobal, 0, 1},
1913 {DISPID_GLOBAL_GETREF, Global_GetRef, 0, 1},
1914 {DISPID_GLOBAL_VBMSGBOXHELPBUTTON, NULL, BP_GET, VT_I4, MB_HELP},
1915 {DISPID_GLOBAL_VBMSGBOXSETFOREGROUND, NULL, BP_GET, VT_I4, MB_SETFOREGROUND},
1916 {DISPID_GLOBAL_VBMSGBOXRIGHT, NULL, BP_GET, VT_I4, MB_RIGHT},
1917 {DISPID_GLOBAL_VBMSGBOXRTLREADING, NULL, BP_GET, VT_I4, MB_RTLREADING}
1920 static HRESULT Err_Description(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1922 FIXME("\n");
1923 return E_NOTIMPL;
1926 static HRESULT Err_HelpContext(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1928 FIXME("\n");
1929 return E_NOTIMPL;
1932 static HRESULT Err_HelpFile(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1934 FIXME("\n");
1935 return E_NOTIMPL;
1938 static HRESULT Err_Number(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1940 HRESULT hres;
1942 TRACE("\n");
1944 if(!This->desc)
1945 return E_UNEXPECTED;
1947 if(args_cnt) {
1948 FIXME("setter not implemented\n");
1949 return E_NOTIMPL;
1952 hres = This->desc->ctx->err_number;
1953 return return_int(res, HRESULT_FACILITY(hres) == FACILITY_VBS ? HRESULT_CODE(hres) : hres);
1956 static HRESULT Err_Source(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1958 FIXME("\n");
1959 return E_NOTIMPL;
1962 static HRESULT Err_Clear(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1964 TRACE("\n");
1966 if(!This->desc)
1967 return E_UNEXPECTED;
1969 This->desc->ctx->err_number = S_OK;
1970 return S_OK;
1973 static HRESULT Err_Raise(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
1975 FIXME("\n");
1976 return E_NOTIMPL;
1979 static const builtin_prop_t err_props[] = {
1980 {DISPID_ERR_DESCRIPTION, Err_Description, BP_GETPUT},
1981 {DISPID_ERR_HELPCONTEXT, Err_HelpContext, BP_GETPUT},
1982 {DISPID_ERR_HELPFILE, Err_HelpFile, BP_GETPUT},
1983 {DISPID_ERR_NUMBER, Err_Number, BP_GETPUT},
1984 {DISPID_ERR_SOURCE, Err_Source, BP_GETPUT},
1985 {DISPID_ERR_CLEAR, Err_Clear},
1986 {DISPID_ERR_RAISE, Err_Raise, 0, 5},
1989 HRESULT init_global(script_ctx_t *ctx)
1991 HRESULT hres;
1993 ctx->global_desc.ctx = ctx;
1994 ctx->global_desc.builtin_prop_cnt = sizeof(global_props)/sizeof(*global_props);
1995 ctx->global_desc.builtin_props = global_props;
1997 hres = get_typeinfo(GlobalObj_tid, &ctx->global_desc.typeinfo);
1998 if(FAILED(hres))
1999 return hres;
2001 hres = create_vbdisp(&ctx->global_desc, &ctx->global_obj);
2002 if(FAILED(hres))
2003 return hres;
2005 hres = create_script_disp(ctx, &ctx->script_obj);
2006 if(FAILED(hres))
2007 return hres;
2009 ctx->err_desc.ctx = ctx;
2010 ctx->err_desc.builtin_prop_cnt = sizeof(err_props)/sizeof(*err_props);
2011 ctx->err_desc.builtin_props = err_props;
2013 hres = get_typeinfo(ErrObj_tid, &ctx->err_desc.typeinfo);
2014 if(FAILED(hres))
2015 return hres;
2017 return create_vbdisp(&ctx->err_desc, &ctx->err_obj);