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
23 #include "vbscript_defs.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
;
54 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IServiceProvider
, (void**)&sp
);
58 hres
= IServiceProvider_QueryService(sp
, &SID_SInternetHostSecurityManager
, &IID_IInternetHostSecurityManager
,
60 IServiceProvider_Release(sp
);
64 return ctx
->secmgr
= secmgr
;
67 static HRESULT
return_string(VARIANT
*res
, const WCHAR
*str
)
74 ret
= SysAllocString(str
);
83 static HRESULT
return_bstr(VARIANT
*res
, BSTR str
)
94 static HRESULT
return_bool(VARIANT
*res
, BOOL val
)
98 V_BOOL(res
) = val
? VARIANT_TRUE
: VARIANT_FALSE
;
103 static HRESULT
return_short(VARIANT
*res
, short val
)
113 static HRESULT
return_int(VARIANT
*res
, int val
)
123 static inline HRESULT
return_double(VARIANT
*res
, double val
)
133 static inline HRESULT
return_float(VARIANT
*res
, float val
)
143 static inline HRESULT
return_null(VARIANT
*res
)
150 static inline HRESULT
return_date(VARIANT
*res
, double date
)
159 HRESULT
to_int(VARIANT
*v
, int *ret
)
165 hres
= VariantChangeType(&r
, v
, 0, VT_I4
);
173 static HRESULT
to_double(VARIANT
*v
, double *ret
)
178 V_VT(&dst
) = VT_EMPTY
;
179 hres
= VariantChangeType(&dst
, v
, 0, VT_R8
);
187 static HRESULT
to_string(VARIANT
*v
, BSTR
*ret
)
192 V_VT(&dst
) = VT_EMPTY
;
193 hres
= VariantChangeType(&dst
, v
, VARIANT_LOCALBOOL
, VT_BSTR
);
201 static HRESULT
set_object_site(script_ctx_t
*ctx
, IUnknown
*obj
)
203 IObjectWithSite
*obj_site
;
207 hres
= IUnknown_QueryInterface(obj
, &IID_IObjectWithSite
, (void**)&obj_site
);
211 ax_site
= create_ax_site(ctx
);
213 hres
= IObjectWithSite_SetSite(obj_site
, ax_site
);
214 IUnknown_Release(ax_site
);
217 hres
= E_OUTOFMEMORY
;
218 IObjectWithSite_Release(obj_site
);
222 static IUnknown
*create_object(script_ctx_t
*ctx
, const WCHAR
*progid
)
224 IInternetHostSecurityManager
*secmgr
= NULL
;
225 struct CONFIRMSAFETY cs
;
226 IClassFactoryEx
*cfex
;
235 hres
= CLSIDFromProgID(progid
, &guid
);
239 TRACE("GUID %s\n", debugstr_guid(&guid
));
241 if(ctx
->safeopt
& INTERFACE_USES_SECURITY_MANAGER
) {
242 secmgr
= get_sec_mgr(ctx
);
247 hres
= IInternetHostSecurityManager_ProcessUrlAction(secmgr
, URLACTION_ACTIVEX_RUN
,
248 (BYTE
*)&policy
, sizeof(policy
), (BYTE
*)&guid
, sizeof(GUID
), 0, 0);
249 if(FAILED(hres
) || policy
!= URLPOLICY_ALLOW
)
253 hres
= CoGetClassObject(&guid
, CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, NULL
, &IID_IClassFactory
, (void**)&cf
);
257 hres
= IClassFactory_QueryInterface(cf
, &IID_IClassFactoryEx
, (void**)&cfex
);
258 if(SUCCEEDED(hres
)) {
259 FIXME("Use IClassFactoryEx\n");
260 IClassFactoryEx_Release(cfex
);
263 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IUnknown
, (void**)&obj
);
271 hres
= IInternetHostSecurityManager_QueryCustomPolicy(secmgr
, &GUID_CUSTOM_CONFIRMOBJECTSAFETY
,
272 &bpolicy
, &policy_size
, (BYTE
*)&cs
, sizeof(cs
), 0);
273 if(SUCCEEDED(hres
)) {
274 policy
= policy_size
>= sizeof(DWORD
) ? *(DWORD
*)bpolicy
: URLPOLICY_DISALLOW
;
275 CoTaskMemFree(bpolicy
);
278 if(FAILED(hres
) || policy
!= URLPOLICY_ALLOW
) {
279 IUnknown_Release(obj
);
284 hres
= set_object_site(ctx
, obj
);
286 IUnknown_Release(obj
);
293 static HRESULT
show_msgbox(script_ctx_t
*ctx
, BSTR prompt
, unsigned type
, BSTR orig_title
, VARIANT
*res
)
295 SCRIPTUICHANDLING uic_handling
= SCRIPTUICHANDLING_ALLOW
;
296 IActiveScriptSiteUIControl
*ui_control
;
297 IActiveScriptSiteWindow
*acts_window
;
298 WCHAR
*title_buf
= NULL
;
304 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IActiveScriptSiteUIControl
, (void**)&ui_control
);
305 if(SUCCEEDED(hres
)) {
306 hres
= IActiveScriptSiteUIControl_GetUIBehavior(ui_control
, SCRIPTUICITEM_MSGBOX
, &uic_handling
);
307 IActiveScriptSiteUIControl_Release(ui_control
);
309 uic_handling
= SCRIPTUICHANDLING_ALLOW
;
312 switch(uic_handling
) {
313 case SCRIPTUICHANDLING_ALLOW
:
315 case SCRIPTUICHANDLING_NOUIDEFAULT
:
316 return return_short(res
, 0);
322 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IActiveScriptSiteWindow
, (void**)&acts_window
);
324 FIXME("No IActiveScriptSiteWindow\n");
328 if(ctx
->safeopt
& INTERFACE_USES_SECURITY_MANAGER
) {
329 if(orig_title
&& *orig_title
) {
332 title
= title_buf
= heap_alloc(sizeof(vbscriptW
) + (strlenW(orig_title
)+2)*sizeof(WCHAR
));
334 return E_OUTOFMEMORY
;
336 memcpy(title_buf
, vbscriptW
, sizeof(vbscriptW
));
337 ptr
= title_buf
+ sizeof(vbscriptW
)/sizeof(WCHAR
)-1;
341 strcpyW(ptr
, orig_title
);
346 title
= orig_title
? orig_title
: emptyW
;
349 hres
= IActiveScriptSiteWindow_GetWindow(acts_window
, &hwnd
);
350 if(SUCCEEDED(hres
)) {
351 hres
= IActiveScriptSiteWindow_EnableModeless(acts_window
, FALSE
);
352 if(SUCCEEDED(hres
)) {
353 ret
= MessageBoxW(hwnd
, prompt
, title
, type
);
354 hres
= IActiveScriptSiteWindow_EnableModeless(acts_window
, TRUE
);
358 heap_free(title_buf
);
359 IActiveScriptSiteWindow_Release(acts_window
);
361 FIXME("failed: %08x\n", hres
);
365 return return_short(res
, ret
);
368 static HRESULT
Global_CCur(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
373 TRACE("%s\n", debugstr_variant(arg
));
375 assert(args_cnt
== 1);
378 hres
= VariantChangeType(&v
, arg
, 0, VT_CY
);
384 return DISP_E_BADVARTYPE
;
391 static HRESULT
Global_CInt(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
396 TRACE("%s\n", debugstr_variant(arg
));
398 assert(args_cnt
== 1);
401 hres
= VariantChangeType(&v
, arg
, 0, VT_I2
);
406 return DISP_E_BADVARTYPE
;
413 static HRESULT
Global_CLng(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
418 TRACE("%s\n", debugstr_variant(arg
));
420 assert(args_cnt
== 1);
422 hres
= to_int(arg
, &i
);
426 return DISP_E_BADVARTYPE
;
428 return return_int(res
, i
);
431 static HRESULT
Global_CBool(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
436 TRACE("%s\n", debugstr_variant(arg
));
438 assert(args_cnt
== 1);
441 hres
= VariantChangeType(&v
, arg
, VARIANT_LOCALBOOL
, VT_BOOL
);
452 static HRESULT
Global_CByte(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
457 TRACE("%s\n", debugstr_variant(arg
));
459 assert(args_cnt
== 1);
462 hres
= VariantChangeType(&v
, arg
, VARIANT_LOCALBOOL
, VT_UI1
);
468 return DISP_E_BADVARTYPE
;
475 static HRESULT
Global_CDate(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
481 static HRESULT
Global_CDbl(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
486 TRACE("%s\n", debugstr_variant(arg
));
488 assert(args_cnt
== 1);
491 hres
= VariantChangeType(&v
, arg
, 0, VT_R8
);
496 return DISP_E_BADVARTYPE
;
503 static HRESULT
Global_CSng(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
508 TRACE("%s\n", debugstr_variant(arg
));
510 assert(args_cnt
== 1);
513 hres
= VariantChangeType(&v
, arg
, 0, VT_R4
);
518 return DISP_E_BADVARTYPE
;
524 static HRESULT
Global_CStr(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
529 TRACE("%s\n", debugstr_variant(arg
));
531 hres
= to_string(arg
, &str
);
535 return return_bstr(res
, str
);
538 static inline WCHAR
hex_char(unsigned n
)
540 return n
< 10 ? '0'+n
: 'A'+n
-10;
543 static HRESULT
Global_Hex(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
550 TRACE("%s\n", debugstr_variant(arg
));
561 hres
= to_int(arg
, &ret
);
573 *ptr
-- = hex_char(n
& 0xf);
581 return return_string(res
, ptr
);
584 static HRESULT
Global_Oct(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
591 TRACE("%s\n", debugstr_variant(arg
));
602 hres
= to_int(arg
, &ret
);
614 *ptr
-- = '0' + (n
& 0x7);
622 return return_string(res
, ptr
);
625 static HRESULT
Global_VarType(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
627 TRACE("(%s)\n", debugstr_variant(arg
));
629 assert(args_cnt
== 1);
631 if(V_VT(arg
) & ~VT_TYPEMASK
) {
632 FIXME("not supported %s\n", debugstr_variant(arg
));
636 return return_short(res
, V_VT(arg
));
639 static HRESULT
Global_IsDate(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
645 static HRESULT
Global_IsEmpty(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
647 TRACE("(%s)\n", debugstr_variant(arg
));
649 assert(args_cnt
== 1);
653 V_BOOL(res
) = V_VT(arg
) == VT_EMPTY
? VARIANT_TRUE
: VARIANT_FALSE
;
658 static HRESULT
Global_IsNull(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
660 TRACE("(%s)\n", debugstr_variant(arg
));
662 assert(args_cnt
== 1);
666 V_BOOL(res
) = V_VT(arg
) == VT_NULL
? VARIANT_TRUE
: VARIANT_FALSE
;
671 static HRESULT
Global_IsNumeric(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
676 TRACE("(%s)\n", debugstr_variant(arg
));
678 assert(args_cnt
== 1);
680 hres
= to_double(arg
, &d
);
682 return return_bool(res
, SUCCEEDED(hres
));
685 static HRESULT
Global_IsArray(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
691 static HRESULT
Global_IsObject(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
693 TRACE("(%s)\n", debugstr_variant(arg
));
695 assert(args_cnt
== 1);
699 V_BOOL(res
) = V_VT(arg
) == VT_DISPATCH
? VARIANT_TRUE
: VARIANT_FALSE
;
704 static HRESULT
Global_Atn(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
709 hres
= to_double(arg
, &d
);
713 return return_double(res
, atan(d
));
716 static HRESULT
Global_Cos(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
721 hres
= to_double(arg
, &d
);
725 return return_double(res
, cos(d
));
728 static HRESULT
Global_Sin(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
733 hres
= to_double(arg
, &d
);
737 return return_double(res
, sin(d
));
740 static HRESULT
Global_Tan(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
745 hres
= to_double(arg
, &d
);
749 return return_double(res
, tan(d
));
752 static HRESULT
Global_Exp(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
757 hres
= to_double(arg
, &d
);
761 return return_double(res
, exp(d
));
764 static HRESULT
Global_Log(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
769 hres
= to_double(arg
, &d
);
774 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL
);
776 return return_double(res
, log(d
));
779 static HRESULT
Global_Sqr(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
784 hres
= to_double(arg
, &d
);
789 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL
);
791 return return_double(res
, sqrt(d
));
794 static HRESULT
Global_Randomize(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
800 static HRESULT
Global_Rnd(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
806 static HRESULT
Global_Timer(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
812 sec
= lt
.wHour
* 3600 + lt
.wMinute
* 60 + lt
.wSecond
+ lt
.wMilliseconds
/ 1000.0;
813 return return_float(res
, sec
);
817 static HRESULT
Global_LBound(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
823 static HRESULT
Global_UBound(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
829 static HRESULT
Global_RGB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
834 TRACE("%s %s %s\n", debugstr_variant(arg
), debugstr_variant(arg
+ 1), debugstr_variant(arg
+ 2));
836 assert(args_cnt
== 3);
838 for(i
= 0; i
< 3; i
++) {
839 hres
= to_int(arg
+ i
, color
+ i
);
845 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL
);
848 return return_int(res
, RGB(color
[0], color
[1], color
[2]));
851 static HRESULT
Global_Len(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
856 TRACE("%s\n", debugstr_variant(arg
));
858 if(V_VT(arg
) == VT_NULL
)
859 return return_null(res
);
861 if(V_VT(arg
) != VT_BSTR
) {
864 hres
= to_string(arg
, &str
);
868 len
= SysStringLen(str
);
871 len
= SysStringLen(V_BSTR(arg
));
874 return return_int(res
, len
);
877 static HRESULT
Global_LenB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
883 static HRESULT
Global_Left(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
885 BSTR str
, ret
, conv_str
= NULL
;
889 TRACE("(%s %s)\n", debugstr_variant(args
+1), debugstr_variant(args
));
891 if(V_VT(args
) == VT_BSTR
) {
894 hres
= to_string(args
, &conv_str
);
900 hres
= to_int(args
+1, &len
);
905 FIXME("len = %d\n", len
);
909 str_len
= SysStringLen(str
);
913 ret
= SysAllocStringLen(str
, len
);
914 SysFreeString(conv_str
);
916 return E_OUTOFMEMORY
;
918 return return_bstr(res
, ret
);
921 static HRESULT
Global_LeftB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
927 static HRESULT
Global_Right(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
929 BSTR str
, ret
, conv_str
= NULL
;
933 TRACE("(%s %s)\n", debugstr_variant(args
), debugstr_variant(args
+1));
935 if(V_VT(args
+1) == VT_BSTR
) {
938 hres
= to_string(args
, &conv_str
);
944 hres
= to_int(args
+1, &len
);
949 FIXME("len = %d\n", len
);
953 str_len
= SysStringLen(str
);
957 ret
= SysAllocStringLen(str
+str_len
-len
, len
);
958 SysFreeString(conv_str
);
960 return E_OUTOFMEMORY
;
962 return return_bstr(res
, ret
);
965 static HRESULT
Global_RightB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
971 static HRESULT
Global_Mid(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
973 int len
= -1, start
, str_len
;
977 TRACE("(%s %s ...)\n", debugstr_variant(args
), debugstr_variant(args
+1));
979 assert(args_cnt
== 2 || args_cnt
== 3);
981 if(V_VT(args
) != VT_BSTR
) {
982 FIXME("args[0] = %s\n", debugstr_variant(args
));
988 hres
= to_int(args
+1, &start
);
993 hres
= to_int(args
+2, &len
);
998 FIXME("len = %d\n", len
);
1004 str_len
= SysStringLen(str
);
1010 len
= str_len
-start
;
1011 else if(len
> str_len
-start
)
1012 len
= str_len
-start
;
1015 V_VT(res
) = VT_BSTR
;
1016 V_BSTR(res
) = SysAllocStringLen(str
+start
, len
);
1018 return E_OUTOFMEMORY
;
1024 static HRESULT
Global_MidB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1030 static HRESULT
Global_StrComp(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1037 TRACE("(%s %s ...)\n", debugstr_variant(args
), debugstr_variant(args
+1));
1039 assert(args_cnt
== 2 || args_cnt
== 3);
1041 if (args_cnt
== 3) {
1042 hres
= to_int(args
+2, &mode
);
1046 if (mode
!= 0 && mode
!= 1) {
1047 FIXME("unknown compare mode = %d\n", mode
);
1054 hres
= to_string(args
, &left
);
1058 hres
= to_string(args
+1, &right
);
1061 SysFreeString(left
);
1065 ret
= mode
? strcmpiW(left
, right
) : strcmpW(left
, right
);
1066 val
= ret
< 0 ? -1 : (ret
> 0 ? 1 : 0);
1068 SysFreeString(left
);
1069 SysFreeString(right
);
1070 return return_short(res
, val
);
1073 static HRESULT
Global_LCase(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1078 TRACE("%s\n", debugstr_variant(arg
));
1080 if(V_VT(arg
) == VT_NULL
) {
1082 V_VT(res
) = VT_NULL
;
1086 hres
= to_string(arg
, &str
);
1093 for(ptr
= str
; *ptr
; ptr
++)
1094 *ptr
= tolowerW(*ptr
);
1096 V_VT(res
) = VT_BSTR
;
1104 static HRESULT
Global_UCase(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1109 TRACE("%s\n", debugstr_variant(arg
));
1111 if(V_VT(arg
) == VT_NULL
) {
1113 V_VT(res
) = VT_NULL
;
1117 hres
= to_string(arg
, &str
);
1124 for(ptr
= str
; *ptr
; ptr
++)
1125 *ptr
= toupperW(*ptr
);
1127 V_VT(res
) = VT_BSTR
;
1135 static HRESULT
Global_LTrim(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1137 BSTR str
, conv_str
= NULL
;
1141 TRACE("%s\n", debugstr_variant(arg
));
1143 if(V_VT(arg
) == VT_BSTR
) {
1146 hres
= to_string(arg
, &conv_str
);
1152 for(ptr
= str
; *ptr
&& isspaceW(*ptr
); ptr
++);
1154 str
= SysAllocString(ptr
);
1155 SysFreeString(conv_str
);
1157 return E_OUTOFMEMORY
;
1159 return return_bstr(res
, str
);
1162 static HRESULT
Global_RTrim(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1164 BSTR str
, conv_str
= NULL
;
1168 TRACE("%s\n", debugstr_variant(arg
));
1170 if(V_VT(arg
) == VT_BSTR
) {
1173 hres
= to_string(arg
, &conv_str
);
1179 for(ptr
= str
+SysStringLen(str
); ptr
-1 > str
&& isspaceW(*(ptr
-1)); ptr
--);
1181 str
= SysAllocStringLen(str
, ptr
-str
);
1182 SysFreeString(conv_str
);
1184 return E_OUTOFMEMORY
;
1186 return return_bstr(res
, str
);
1189 static HRESULT
Global_Trim(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1191 BSTR str
, conv_str
= NULL
;
1192 WCHAR
*begin_ptr
, *end_ptr
;
1195 TRACE("%s\n", debugstr_variant(arg
));
1197 if(V_VT(arg
) == VT_BSTR
) {
1200 hres
= to_string(arg
, &conv_str
);
1206 for(begin_ptr
= str
; *begin_ptr
&& isspaceW(*begin_ptr
); begin_ptr
++);
1207 for(end_ptr
= str
+SysStringLen(str
); end_ptr
-1 > begin_ptr
&& isspaceW(*(end_ptr
-1)); end_ptr
--);
1209 str
= SysAllocStringLen(begin_ptr
, end_ptr
-begin_ptr
);
1210 SysFreeString(conv_str
);
1212 return E_OUTOFMEMORY
;
1214 return return_bstr(res
, str
);
1217 static HRESULT
Global_Space(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1223 TRACE("%s\n", debugstr_variant(arg
));
1225 hres
= to_int(arg
, &n
);
1230 FIXME("n = %d\n", n
);
1237 str
= SysAllocStringLen(NULL
, n
);
1239 return E_OUTOFMEMORY
;
1244 V_VT(res
) = VT_BSTR
;
1249 static HRESULT
Global_String(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1255 static HRESULT
Global_InStr(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1257 VARIANT
*startv
, *str1v
, *str2v
;
1264 assert(2 <= args_cnt
&& args_cnt
<= 4);
1278 FIXME("unsupported compare argument %s\n", debugstr_variant(args
));
1280 DEFAULT_UNREACHABLE
;
1284 hres
= to_int(startv
, &start
);
1288 FIXME("start %d\n", start
);
1295 if(V_VT(str1v
) == VT_NULL
|| V_VT(str2v
) == VT_NULL
)
1296 return return_null(res
);
1298 if(V_VT(str1v
) != VT_BSTR
) {
1299 FIXME("Unsupported str1 type %s\n", debugstr_variant(str1v
));
1302 str1
= V_BSTR(str1v
);
1304 if(V_VT(str2v
) != VT_BSTR
) {
1305 FIXME("Unsupported str2 type %s\n", debugstr_variant(str2v
));
1308 str2
= V_BSTR(str2v
);
1310 if(start
< SysStringLen(str1
)) {
1313 ptr
= strstrW(str1
+start
, str2
);
1314 ret
= ptr
? ptr
-str1
+1 : 0;
1319 return return_int(res
, ret
);
1322 static HRESULT
Global_InStrB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1328 static HRESULT
Global_AscB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1334 static HRESULT
Global_ChrB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1340 static HRESULT
Global_Asc(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1346 /* The function supports only single-byte and double-byte character sets. It
1347 * ignores language specified by IActiveScriptSite::GetLCID. The argument needs
1348 * to be in range of short or unsigned short. */
1349 static HRESULT
Global_Chr(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1357 TRACE("%s\n", debugstr_variant(arg
));
1359 hres
= to_int(arg
, &c
);
1364 if(!GetCPInfo(cp
, &cpi
))
1365 cpi
.MaxCharSize
= 1;
1367 if((c
!=(short)c
&& c
!=(unsigned short)c
) ||
1368 (unsigned short)c
>=(cpi
.MaxCharSize
>1 ? 0x10000 : 0x100)) {
1369 WARN("invalid arg %d\n", c
);
1370 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL
);
1375 if(!len
|| IsDBCSLeadByteEx(cp
, buf
[0]))
1377 if(!MultiByteToWideChar(CP_ACP
, 0, buf
, len
, &ch
, 1)) {
1378 WARN("invalid arg %d, cp %d\n", c
, cp
);
1383 V_VT(res
) = VT_BSTR
;
1384 V_BSTR(res
) = SysAllocStringLen(&ch
, 1);
1386 return E_OUTOFMEMORY
;
1391 static HRESULT
Global_AscW(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1397 static HRESULT
Global_ChrW(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1403 static HRESULT
Global_Abs(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1408 TRACE("(%s)\n", debugstr_variant(arg
));
1410 assert(args_cnt
== 1);
1412 hres
= VarAbs(arg
, &dst
);
1424 static HRESULT
Global_Fix(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1429 TRACE("(%s)\n", debugstr_variant(arg
));
1431 assert(args_cnt
== 1);
1433 hres
= VarFix(arg
, &dst
);
1445 static HRESULT
Global_Int(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1450 TRACE("(%s)\n", debugstr_variant(arg
));
1452 assert(args_cnt
== 1);
1454 hres
= VarInt(arg
, &dst
);
1466 static HRESULT
Global_Sgn(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1472 TRACE("(%s)\n", debugstr_variant(arg
));
1474 assert(args_cnt
== 1);
1476 if(V_VT(arg
) == VT_NULL
)
1477 return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE
);
1479 hres
= to_double(arg
, &v
);
1483 val
= v
== 0 ? 0 : (v
> 0 ? 1 : -1);
1484 return return_short(res
, val
);
1487 static HRESULT
Global_Now(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1495 SystemTimeToVariantTime(<
, &date
);
1496 return return_date(res
, date
);
1499 static HRESULT
Global_Date(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1511 hres
= VarDateFromUdateEx(&ud
, 0, VAR_DATEVALUEONLY
, &date
);
1514 return return_date(res
, date
);
1517 static HRESULT
Global_Time(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1529 hres
= VarDateFromUdateEx(&ud
, 0, VAR_TIMEVALUEONLY
, &time
);
1532 return return_date(res
, time
);
1535 static HRESULT
Global_Day(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1541 static HRESULT
Global_Month(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1547 static HRESULT
Global_Weekday(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1553 static HRESULT
Global_Year(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1559 static HRESULT
Global_Hour(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1565 static HRESULT
Global_Minute(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1571 static HRESULT
Global_Second(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1577 static HRESULT
Global_DateValue(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1583 static HRESULT
Global_TimeValue(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1589 static HRESULT
Global_DateSerial(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1595 static HRESULT
Global_TimeSerial(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1601 static HRESULT
Global_InputBox(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1607 static HRESULT
Global_MsgBox(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1609 BSTR prompt
, title
= NULL
;
1615 assert(1 <= args_cnt
&& args_cnt
<= 5);
1617 hres
= to_string(args
, &prompt
);
1622 hres
= to_int(args
+1, &type
);
1624 if(SUCCEEDED(hres
) && args_cnt
> 2)
1625 hres
= to_string(args
+2, &title
);
1627 if(SUCCEEDED(hres
) && args_cnt
> 3) {
1628 FIXME("unsupported arg_cnt %d\n", args_cnt
);
1633 hres
= show_msgbox(This
->desc
->ctx
, prompt
, type
, title
, res
);
1635 SysFreeString(prompt
);
1636 SysFreeString(title
);
1640 static HRESULT
Global_CreateObject(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1645 TRACE("(%s)\n", debugstr_variant(arg
));
1647 if(V_VT(arg
) != VT_BSTR
) {
1648 FIXME("non-bstr arg\n");
1649 return E_INVALIDARG
;
1652 obj
= create_object(This
->desc
->ctx
, V_BSTR(arg
));
1654 return VB_E_CANNOT_CREATE_OBJ
;
1657 hres
= IUnknown_QueryInterface(obj
, &IID_IDispatch
, (void**)&V_DISPATCH(res
));
1661 V_VT(res
) = VT_DISPATCH
;
1664 IUnknown_Release(obj
);
1668 static HRESULT
Global_GetObject(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1677 TRACE("%s %s\n", args_cnt
? debugstr_variant(args
) : "", args_cnt
> 1 ? debugstr_variant(args
+1) : "");
1679 if(args_cnt
!= 1 || V_VT(args
) != VT_BSTR
) {
1680 FIXME("unsupported args\n");
1684 if(This
->desc
->ctx
->safeopt
& (INTERFACE_USES_SECURITY_MANAGER
|INTERFACESAFE_FOR_UNTRUSTED_DATA
)) {
1685 WARN("blocked in current safety mode\n");
1686 return VB_E_CANNOT_CREATE_OBJ
;
1689 hres
= CreateBindCtx(0, &bind_ctx
);
1693 hres
= MkParseDisplayName(bind_ctx
, V_BSTR(args
), &eaten
, &mon
);
1694 if(SUCCEEDED(hres
)) {
1695 hres
= IMoniker_BindToObject(mon
, bind_ctx
, NULL
, &IID_IUnknown
, (void**)&obj_unk
);
1696 IMoniker_Release(mon
);
1700 IBindCtx_Release(bind_ctx
);
1704 hres
= set_object_site(This
->desc
->ctx
, obj_unk
);
1706 IUnknown_Release(obj_unk
);
1710 hres
= IUnknown_QueryInterface(obj_unk
, &IID_IDispatch
, (void**)&disp
);
1711 if(SUCCEEDED(hres
)) {
1713 V_VT(res
) = VT_DISPATCH
;
1714 V_DISPATCH(res
) = disp
;
1716 IDispatch_Release(disp
);
1719 FIXME("object does not support IDispatch\n");
1725 static HRESULT
Global_DateAdd(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1731 static HRESULT
Global_DateDiff(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1737 static HRESULT
Global_DatePart(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1743 static HRESULT
Global_TypeName(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1745 static const WCHAR ByteW
[] = {'B', 'y', 't', 'e', 0};
1746 static const WCHAR IntegerW
[] = {'I', 'n', 't', 'e', 'g', 'e', 'r', 0};
1747 static const WCHAR LongW
[] = {'L', 'o', 'n', 'g', 0};
1748 static const WCHAR SingleW
[] = {'S', 'i', 'n', 'g', 'l', 'e', 0};
1749 static const WCHAR DoubleW
[] = {'D', 'o', 'u', 'b', 'l', 'e', 0};
1750 static const WCHAR CurrencyW
[] = {'C', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 0};
1751 static const WCHAR DecimalW
[] = {'D', 'e', 'c', 'i', 'm', 'a', 'l', 0};
1752 static const WCHAR DateW
[] = {'D', 'a', 't', 'e', 0};
1753 static const WCHAR StringW
[] = {'S', 't', 'r', 'i', 'n', 'g', 0};
1754 static const WCHAR BooleanW
[] = {'B', 'o', 'o', 'l', 'e', 'a', 'n', 0};
1755 static const WCHAR EmptyW
[] = {'E', 'm', 'p', 't', 'y', 0};
1756 static const WCHAR NullW
[] = {'N', 'u', 'l', 'l', 0};
1758 TRACE("(%s)\n", debugstr_variant(arg
));
1760 assert(args_cnt
== 1);
1764 return return_string(res
, ByteW
);
1766 return return_string(res
, IntegerW
);
1768 return return_string(res
, LongW
);
1770 return return_string(res
, SingleW
);
1772 return return_string(res
, DoubleW
);
1774 return return_string(res
, CurrencyW
);
1776 return return_string(res
, DecimalW
);
1778 return return_string(res
, DateW
);
1780 return return_string(res
, StringW
);
1782 return return_string(res
, BooleanW
);
1784 return return_string(res
, EmptyW
);
1786 return return_string(res
, NullW
);
1788 FIXME("arg %s not supported\n", debugstr_variant(arg
));
1793 static HRESULT
Global_Array(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1799 static HRESULT
Global_Erase(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1805 static HRESULT
Global_Filter(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1811 static HRESULT
Global_Join(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1817 static HRESULT
Global_Split(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1823 static HRESULT
Global_Replace(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1829 static HRESULT
Global_StrReverse(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1831 WCHAR
*ptr1
, *ptr2
, ch
;
1835 TRACE("%s\n", debugstr_variant(arg
));
1837 hres
= to_string(arg
, &ret
);
1842 ptr2
= ret
+ SysStringLen(ret
)-1;
1843 while(ptr1
< ptr2
) {
1849 return return_bstr(res
, ret
);
1852 static HRESULT
Global_InStrRev(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1858 TRACE("%s %s arg_cnt=%u\n", debugstr_variant(args
), debugstr_variant(args
+1), args_cnt
);
1861 FIXME("Unsupported args\n");
1865 assert(2 <= args_cnt
&& args_cnt
<= 4);
1867 if(V_VT(args
) == VT_NULL
|| V_VT(args
+1) == VT_NULL
|| (args_cnt
> 2 && V_VT(args
+2) == VT_NULL
))
1868 return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE
);
1870 hres
= to_string(args
, &str1
);
1874 hres
= to_string(args
+1, &str2
);
1875 if(SUCCEEDED(hres
)) {
1877 hres
= to_int(args
+2, &start
);
1878 if(SUCCEEDED(hres
) && start
<= 0) {
1879 FIXME("Unsupported start %d\n", start
);
1883 start
= SysStringLen(str1
);
1889 if(SUCCEEDED(hres
)) {
1893 len
= SysStringLen(str2
);
1894 if(start
>= len
&& start
<= SysStringLen(str1
)) {
1895 for(ptr
= str1
+start
-SysStringLen(str2
); ptr
>= str1
; ptr
--) {
1896 if(!memcmp(ptr
, str2
, len
*sizeof(WCHAR
))) {
1904 SysFreeString(str1
);
1905 SysFreeString(str2
);
1909 return return_int(res
, ret
);
1912 static HRESULT
Global_LoadPicture(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1918 static HRESULT
Global_ScriptEngine(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1920 TRACE("%s\n", debugstr_variant(arg
));
1922 assert(args_cnt
== 0);
1924 return return_string(res
, vbscriptW
);
1927 static HRESULT
Global_ScriptEngineMajorVersion(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1929 TRACE("%s\n", debugstr_variant(arg
));
1931 assert(args_cnt
== 0);
1933 return return_int(res
, VBSCRIPT_MAJOR_VERSION
);
1936 static HRESULT
Global_ScriptEngineMinorVersion(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1938 TRACE("%s\n", debugstr_variant(arg
));
1940 assert(args_cnt
== 0);
1942 return return_int(res
, VBSCRIPT_MINOR_VERSION
);
1945 static HRESULT
Global_ScriptEngineBuildVersion(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1947 TRACE("%s\n", debugstr_variant(arg
));
1949 assert(args_cnt
== 0);
1951 return return_int(res
, VBSCRIPT_BUILD_VERSION
);
1954 static HRESULT
Global_FormatNumber(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1960 static HRESULT
Global_FormatCurrency(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1966 static HRESULT
Global_FormatPercent(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1972 static HRESULT
Global_FormatDateTime(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1978 static HRESULT
Global_WeekdayName(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1980 int weekday
, first_day
= 1, abbrev
= 0;
1986 assert(1 <= args_cnt
&& args_cnt
<= 3);
1988 hres
= to_int(args
, &weekday
);
1993 hres
= to_int(args
+1, &abbrev
);
1998 hres
= to_int(args
+2, &first_day
);
2004 hres
= VarWeekdayName(weekday
, abbrev
, first_day
, 0, &ret
);
2008 return return_bstr(res
, ret
);
2011 static HRESULT
Global_MonthName(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2013 int month
, abbrev
= 0;
2019 assert(args_cnt
== 1 || args_cnt
== 2);
2021 hres
= to_int(args
, &month
);
2026 hres
= to_int(args
+1, &abbrev
);
2031 hres
= VarMonthName(month
, abbrev
, 0, &ret
);
2035 return return_bstr(res
, ret
);
2038 static HRESULT
Global_Round(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2043 TRACE("%s\n", debugstr_variant(arg
));
2058 hres
= to_double(arg
, &n
);
2063 return return_double(res
, round(n
));
2066 static HRESULT
Global_Escape(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2072 static HRESULT
Global_Unescape(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2078 static HRESULT
Global_Eval(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2084 static HRESULT
Global_Execute(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2090 static HRESULT
Global_ExecuteGlobal(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2096 static HRESULT
Global_GetRef(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
2102 static const string_constant_t vbCr
= {1, {'\r'}};
2103 static const string_constant_t vbCrLf
= {2, {'\r','\n'}};
2104 static const string_constant_t vbNewLine
= {2, {'\r','\n'}};
2105 static const string_constant_t vbFormFeed
= {1, {0xc}};
2106 static const string_constant_t vbLf
= {1, {'\n'}};
2107 static const string_constant_t vbNullChar
= {1};
2108 static const string_constant_t vbNullString
= {0};
2109 static const string_constant_t vbTab
= {1, {'\t'}};
2110 static const string_constant_t vbVerticalTab
= {1, {0xb}};
2112 static const builtin_prop_t global_props
[] = {
2113 {DISPID_GLOBAL_VBUSESYSTEM
, NULL
, BP_GET
, VT_I2
, 0},
2114 {DISPID_GLOBAL_USESYSTEMDAYOFWEEK
, NULL
, BP_GET
, VT_I2
, 0},
2115 {DISPID_GLOBAL_VBSUNDAY
, NULL
, BP_GET
, VT_I2
, 1},
2116 {DISPID_GLOBAL_VBMONDAY
, NULL
, BP_GET
, VT_I2
, 2},
2117 {DISPID_GLOBAL_VBTUESDAY
, NULL
, BP_GET
, VT_I2
, 3},
2118 {DISPID_GLOBAL_VBWEDNESDAY
, NULL
, BP_GET
, VT_I2
, 4},
2119 {DISPID_GLOBAL_VBTHURSDAY
, NULL
, BP_GET
, VT_I2
, 5},
2120 {DISPID_GLOBAL_VBFRIDAY
, NULL
, BP_GET
, VT_I2
, 6},
2121 {DISPID_GLOBAL_VBSATURDAY
, NULL
, BP_GET
, VT_I2
, 7},
2122 {DISPID_GLOBAL_VBFIRSTJAN1
, NULL
, BP_GET
, VT_I2
, 1},
2123 {DISPID_GLOBAL_VBFIRSTFOURDAYS
, NULL
, BP_GET
, VT_I2
, 2},
2124 {DISPID_GLOBAL_VBFIRSTFULLWEEK
, NULL
, BP_GET
, VT_I2
, 3},
2125 {DISPID_GLOBAL_VBOKONLY
, NULL
, BP_GET
, VT_I2
, MB_OK
},
2126 {DISPID_GLOBAL_VBOKCANCEL
, NULL
, BP_GET
, VT_I2
, MB_OKCANCEL
},
2127 {DISPID_GLOBAL_VBABORTRETRYIGNORE
, NULL
, BP_GET
, VT_I2
, MB_ABORTRETRYIGNORE
},
2128 {DISPID_GLOBAL_VBYESNOCANCEL
, NULL
, BP_GET
, VT_I2
, MB_YESNOCANCEL
},
2129 {DISPID_GLOBAL_VBYESNO
, NULL
, BP_GET
, VT_I2
, MB_YESNO
},
2130 {DISPID_GLOBAL_VBRETRYCANCEL
, NULL
, BP_GET
, VT_I2
, MB_RETRYCANCEL
},
2131 {DISPID_GLOBAL_VBCRITICAL
, NULL
, BP_GET
, VT_I2
, MB_ICONHAND
},
2132 {DISPID_GLOBAL_VBQUESTION
, NULL
, BP_GET
, VT_I2
, MB_ICONQUESTION
},
2133 {DISPID_GLOBAL_VBEXCLAMATION
, NULL
, BP_GET
, VT_I2
, MB_ICONEXCLAMATION
},
2134 {DISPID_GLOBAL_VBINFORMATION
, NULL
, BP_GET
, VT_I2
, MB_ICONASTERISK
},
2135 {DISPID_GLOBAL_VBDEFAULTBUTTON1
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON1
},
2136 {DISPID_GLOBAL_VBDEFAULTBUTTON2
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON2
},
2137 {DISPID_GLOBAL_VBDEFAULTBUTTON3
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON3
},
2138 {DISPID_GLOBAL_VBDEFAULTBUTTON4
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON4
},
2139 {DISPID_GLOBAL_VBAPPLICATIONMODAL
, NULL
, BP_GET
, VT_I2
, MB_APPLMODAL
},
2140 {DISPID_GLOBAL_VBSYSTEMMODAL
, NULL
, BP_GET
, VT_I2
, MB_SYSTEMMODAL
},
2141 {DISPID_GLOBAL_VBOK
, NULL
, BP_GET
, VT_I2
, IDOK
},
2142 {DISPID_GLOBAL_VBCANCEL
, NULL
, BP_GET
, VT_I2
, IDCANCEL
},
2143 {DISPID_GLOBAL_VBABORT
, NULL
, BP_GET
, VT_I2
, IDABORT
},
2144 {DISPID_GLOBAL_VBRETRY
, NULL
, BP_GET
, VT_I2
, IDRETRY
},
2145 {DISPID_GLOBAL_VBIGNORE
, NULL
, BP_GET
, VT_I2
, IDIGNORE
},
2146 {DISPID_GLOBAL_VBYES
, NULL
, BP_GET
, VT_I2
, IDYES
},
2147 {DISPID_GLOBAL_VBNO
, NULL
, BP_GET
, VT_I2
, IDNO
},
2148 {DISPID_GLOBAL_VBEMPTY
, NULL
, BP_GET
, VT_I2
, VT_EMPTY
},
2149 {DISPID_GLOBAL_VBNULL
, NULL
, BP_GET
, VT_I2
, VT_NULL
},
2150 {DISPID_GLOBAL_VBINTEGER
, NULL
, BP_GET
, VT_I2
, VT_I2
},
2151 {DISPID_GLOBAL_VBLONG
, NULL
, BP_GET
, VT_I2
, VT_I4
},
2152 {DISPID_GLOBAL_VBSINGLE
, NULL
, BP_GET
, VT_I2
, VT_R4
},
2153 {DISPID_GLOBAL_VBDOUBLE
, NULL
, BP_GET
, VT_I2
, VT_R8
},
2154 {DISPID_GLOBAL_VBCURRENCY
, NULL
, BP_GET
, VT_I2
, VT_CY
},
2155 {DISPID_GLOBAL_VBDATE
, NULL
, BP_GET
, VT_I2
, VT_DATE
},
2156 {DISPID_GLOBAL_VBSTRING
, NULL
, BP_GET
, VT_I2
, VT_BSTR
},
2157 {DISPID_GLOBAL_VBOBJECT
, NULL
, BP_GET
, VT_I2
, VT_DISPATCH
},
2158 {DISPID_GLOBAL_VBERROR
, NULL
, BP_GET
, VT_I2
, VT_ERROR
},
2159 {DISPID_GLOBAL_VBBOOLEAN
, NULL
, BP_GET
, VT_I2
, VT_BOOL
},
2160 {DISPID_GLOBAL_VBVARIANT
, NULL
, BP_GET
, VT_I2
, VT_VARIANT
},
2161 {DISPID_GLOBAL_VBDATAOBJECT
, NULL
, BP_GET
, VT_I2
, VT_UNKNOWN
},
2162 {DISPID_GLOBAL_VBDECIMAL
, NULL
, BP_GET
, VT_I2
, VT_DECIMAL
},
2163 {DISPID_GLOBAL_VBBYTE
, NULL
, BP_GET
, VT_I2
, VT_UI1
},
2164 {DISPID_GLOBAL_VBARRAY
, NULL
, BP_GET
, VT_I2
, VT_ARRAY
},
2165 {DISPID_GLOBAL_VBTRUE
, NULL
, BP_GET
, VT_I2
, VARIANT_TRUE
},
2166 {DISPID_GLOBAL_VBFALSE
, NULL
, BP_GET
, VT_I2
, VARIANT_FALSE
},
2167 {DISPID_GLOBAL_VBUSEDEFAULT
, NULL
, BP_GET
, VT_I2
, -2},
2168 {DISPID_GLOBAL_VBBINARYCOMPARE
, NULL
, BP_GET
, VT_I2
, 0},
2169 {DISPID_GLOBAL_VBTEXTCOMPARE
, NULL
, BP_GET
, VT_I2
, 1},
2170 {DISPID_GLOBAL_VBDATABASECOMPARE
, NULL
, BP_GET
, VT_I2
, 2},
2171 {DISPID_GLOBAL_VBGENERALDATE
, NULL
, BP_GET
, VT_I2
, 0},
2172 {DISPID_GLOBAL_VBLONGDATE
, NULL
, BP_GET
, VT_I2
, 1},
2173 {DISPID_GLOBAL_VBSHORTDATE
, NULL
, BP_GET
, VT_I2
, 2},
2174 {DISPID_GLOBAL_VBLONGTIME
, NULL
, BP_GET
, VT_I2
, 3},
2175 {DISPID_GLOBAL_VBSHORTTIME
, NULL
, BP_GET
, VT_I2
, 4},
2176 {DISPID_GLOBAL_VBOBJECTERROR
, NULL
, BP_GET
, VT_I4
, 0x80040000},
2177 {DISPID_GLOBAL_VBBLACK
, NULL
, BP_GET
, VT_I4
, 0x000000},
2178 {DISPID_GLOBAL_VBBLUE
, NULL
, BP_GET
, VT_I4
, 0xff0000},
2179 {DISPID_GLOBAL_VBCYAN
, NULL
, BP_GET
, VT_I4
, 0xffff00},
2180 {DISPID_GLOBAL_VBGREEN
, NULL
, BP_GET
, VT_I4
, 0x00ff00},
2181 {DISPID_GLOBAL_VBMAGENTA
, NULL
, BP_GET
, VT_I4
, 0xff00ff},
2182 {DISPID_GLOBAL_VBRED
, NULL
, BP_GET
, VT_I4
, 0x0000ff},
2183 {DISPID_GLOBAL_VBWHITE
, NULL
, BP_GET
, VT_I4
, 0xffffff},
2184 {DISPID_GLOBAL_VBYELLOW
, NULL
, BP_GET
, VT_I4
, 0x00ffff},
2185 {DISPID_GLOBAL_VBCR
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbCr
},
2186 {DISPID_GLOBAL_VBCRLF
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbCrLf
},
2187 {DISPID_GLOBAL_VBNEWLINE
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbNewLine
},
2188 {DISPID_GLOBAL_VBFORMFEED
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbFormFeed
},
2189 {DISPID_GLOBAL_VBLF
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbLf
},
2190 {DISPID_GLOBAL_VBNULLCHAR
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbNullChar
},
2191 {DISPID_GLOBAL_VBNULLSTRING
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbNullString
},
2192 {DISPID_GLOBAL_VBTAB
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbTab
},
2193 {DISPID_GLOBAL_VBVERTICALTAB
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbVerticalTab
},
2194 {DISPID_GLOBAL_CCUR
, Global_CCur
, 0, 1},
2195 {DISPID_GLOBAL_CINT
, Global_CInt
, 0, 1},
2196 {DISPID_GLOBAL_CLNG
, Global_CLng
, 0, 1},
2197 {DISPID_GLOBAL_CBOOL
, Global_CBool
, 0, 1},
2198 {DISPID_GLOBAL_CBYTE
, Global_CByte
, 0, 1},
2199 {DISPID_GLOBAL_CDATE
, Global_CDate
, 0, 1},
2200 {DISPID_GLOBAL_CDBL
, Global_CDbl
, 0, 1},
2201 {DISPID_GLOBAL_CSNG
, Global_CSng
, 0, 1},
2202 {DISPID_GLOBAL_CSTR
, Global_CStr
, 0, 1},
2203 {DISPID_GLOBAL_HEX
, Global_Hex
, 0, 1},
2204 {DISPID_GLOBAL_OCT
, Global_Oct
, 0, 1},
2205 {DISPID_GLOBAL_VARTYPE
, Global_VarType
, 0, 1},
2206 {DISPID_GLOBAL_ISDATE
, Global_IsDate
, 0, 1},
2207 {DISPID_GLOBAL_ISEMPTY
, Global_IsEmpty
, 0, 1},
2208 {DISPID_GLOBAL_ISNULL
, Global_IsNull
, 0, 1},
2209 {DISPID_GLOBAL_ISNUMERIC
, Global_IsNumeric
, 0, 1},
2210 {DISPID_GLOBAL_ISARRAY
, Global_IsArray
, 0, 1},
2211 {DISPID_GLOBAL_ISOBJECT
, Global_IsObject
, 0, 1},
2212 {DISPID_GLOBAL_ATN
, Global_Atn
, 0, 1},
2213 {DISPID_GLOBAL_COS
, Global_Cos
, 0, 1},
2214 {DISPID_GLOBAL_SIN
, Global_Sin
, 0, 1},
2215 {DISPID_GLOBAL_TAN
, Global_Tan
, 0, 1},
2216 {DISPID_GLOBAL_EXP
, Global_Exp
, 0, 1},
2217 {DISPID_GLOBAL_LOG
, Global_Log
, 0, 1},
2218 {DISPID_GLOBAL_SQR
, Global_Sqr
, 0, 1},
2219 {DISPID_GLOBAL_RANDOMIZE
, Global_Randomize
, 0, 1},
2220 {DISPID_GLOBAL_RND
, Global_Rnd
, 0, 1},
2221 {DISPID_GLOBAL_TIMER
, Global_Timer
, 0, 0},
2222 {DISPID_GLOBAL_LBOUND
, Global_LBound
, 0, 1},
2223 {DISPID_GLOBAL_UBOUND
, Global_UBound
, 0, 1},
2224 {DISPID_GLOBAL_RGB
, Global_RGB
, 0, 3},
2225 {DISPID_GLOBAL_LEN
, Global_Len
, 0, 1},
2226 {DISPID_GLOBAL_LENB
, Global_LenB
, 0, 1},
2227 {DISPID_GLOBAL_LEFT
, Global_Left
, 0, 2},
2228 {DISPID_GLOBAL_LEFTB
, Global_LeftB
, 0, 2},
2229 {DISPID_GLOBAL_RIGHT
, Global_Right
, 0, 2},
2230 {DISPID_GLOBAL_RIGHTB
, Global_RightB
, 0, 2},
2231 {DISPID_GLOBAL_MID
, Global_Mid
, 0, 2, 3},
2232 {DISPID_GLOBAL_MIDB
, Global_MidB
, 0, 2, 3},
2233 {DISPID_GLOBAL_STRCOMP
, Global_StrComp
, 0, 2, 3},
2234 {DISPID_GLOBAL_LCASE
, Global_LCase
, 0, 1},
2235 {DISPID_GLOBAL_UCASE
, Global_UCase
, 0, 1},
2236 {DISPID_GLOBAL_LTRIM
, Global_LTrim
, 0, 1},
2237 {DISPID_GLOBAL_RTRIM
, Global_RTrim
, 0, 1},
2238 {DISPID_GLOBAL_TRIM
, Global_Trim
, 0, 1},
2239 {DISPID_GLOBAL_SPACE
, Global_Space
, 0, 1},
2240 {DISPID_GLOBAL_STRING
, Global_String
, 0, 0, 2},
2241 {DISPID_GLOBAL_INSTR
, Global_InStr
, 0, 2, 4},
2242 {DISPID_GLOBAL_INSTRB
, Global_InStrB
, 0, 3, 4},
2243 {DISPID_GLOBAL_ASCB
, Global_AscB
, 0, 1},
2244 {DISPID_GLOBAL_CHRB
, Global_ChrB
, 0, 1},
2245 {DISPID_GLOBAL_ASC
, Global_Asc
, 0, 1},
2246 {DISPID_GLOBAL_CHR
, Global_Chr
, 0, 1},
2247 {DISPID_GLOBAL_ASCW
, Global_AscW
, 0, 1},
2248 {DISPID_GLOBAL_CHRW
, Global_ChrW
, 0, 1},
2249 {DISPID_GLOBAL_ABS
, Global_Abs
, 0, 1},
2250 {DISPID_GLOBAL_FIX
, Global_Fix
, 0, 1},
2251 {DISPID_GLOBAL_INT
, Global_Int
, 0, 1},
2252 {DISPID_GLOBAL_SGN
, Global_Sgn
, 0, 1},
2253 {DISPID_GLOBAL_NOW
, Global_Now
, 0, 0},
2254 {DISPID_GLOBAL_DATE
, Global_Date
, 0, 0},
2255 {DISPID_GLOBAL_TIME
, Global_Time
, 0, 0},
2256 {DISPID_GLOBAL_DAY
, Global_Day
, 0, 1},
2257 {DISPID_GLOBAL_MONTH
, Global_Month
, 0, 1},
2258 {DISPID_GLOBAL_WEEKDAY
, Global_Weekday
, 0, 1, 2},
2259 {DISPID_GLOBAL_YEAR
, Global_Year
, 0, 1},
2260 {DISPID_GLOBAL_HOUR
, Global_Hour
, 0, 1},
2261 {DISPID_GLOBAL_MINUTE
, Global_Minute
, 0, 1},
2262 {DISPID_GLOBAL_SECOND
, Global_Second
, 0, 1},
2263 {DISPID_GLOBAL_DATEVALUE
, Global_DateValue
, 0, 1},
2264 {DISPID_GLOBAL_TIMEVALUE
, Global_TimeValue
, 0, 1},
2265 {DISPID_GLOBAL_DATESERIAL
, Global_DateSerial
, 0, 3},
2266 {DISPID_GLOBAL_TIMESERIAL
, Global_TimeSerial
, 0, 3},
2267 {DISPID_GLOBAL_INPUTBOX
, Global_InputBox
, 0, 1, 7},
2268 {DISPID_GLOBAL_MSGBOX
, Global_MsgBox
, 0, 1, 5},
2269 {DISPID_GLOBAL_CREATEOBJECT
, Global_CreateObject
, 0, 1},
2270 {DISPID_GLOBAL_GETOBJECT
, Global_GetObject
, 0, 0, 2},
2271 {DISPID_GLOBAL_DATEADD
, Global_DateAdd
, 0, 3},
2272 {DISPID_GLOBAL_DATEDIFF
, Global_DateDiff
, 0, 3, 5},
2273 {DISPID_GLOBAL_DATEPART
, Global_DatePart
, 0, 2, 4},
2274 {DISPID_GLOBAL_TYPENAME
, Global_TypeName
, 0, 1},
2275 {DISPID_GLOBAL_ARRAY
, Global_Array
, 0, 1},
2276 {DISPID_GLOBAL_ERASE
, Global_Erase
, 0, 1},
2277 {DISPID_GLOBAL_FILTER
, Global_Filter
, 0, 2, 4},
2278 {DISPID_GLOBAL_JOIN
, Global_Join
, 0, 1, 2},
2279 {DISPID_GLOBAL_SPLIT
, Global_Split
, 0, 1, 4},
2280 {DISPID_GLOBAL_REPLACE
, Global_Replace
, 0, 3, 6},
2281 {DISPID_GLOBAL_STRREVERSE
, Global_StrReverse
, 0, 1},
2282 {DISPID_GLOBAL_INSTRREV
, Global_InStrRev
, 0, 2, 4},
2283 {DISPID_GLOBAL_LOADPICTURE
, Global_LoadPicture
, 0, 1},
2284 {DISPID_GLOBAL_SCRIPTENGINE
, Global_ScriptEngine
, 0, 0},
2285 {DISPID_GLOBAL_SCRIPTENGINEMAJORVERSION
, Global_ScriptEngineMajorVersion
, 0, 0},
2286 {DISPID_GLOBAL_SCRIPTENGINEMINORVERSION
, Global_ScriptEngineMinorVersion
, 0, 0},
2287 {DISPID_GLOBAL_SCRIPTENGINEBUILDVERSION
, Global_ScriptEngineBuildVersion
, 0, 0},
2288 {DISPID_GLOBAL_FORMATNUMBER
, Global_FormatNumber
, 0, 1, 5},
2289 {DISPID_GLOBAL_FORMATCURRENCY
, Global_FormatCurrency
, 0, 1, 5},
2290 {DISPID_GLOBAL_FORMATPERCENT
, Global_FormatPercent
, 0, 1, 5},
2291 {DISPID_GLOBAL_FORMATDATETIME
, Global_FormatDateTime
, 0, 1, 2},
2292 {DISPID_GLOBAL_WEEKDAYNAME
, Global_WeekdayName
, 0, 1, 3},
2293 {DISPID_GLOBAL_MONTHNAME
, Global_MonthName
, 0, 1, 2},
2294 {DISPID_GLOBAL_ROUND
, Global_Round
, 0, 1, 2},
2295 {DISPID_GLOBAL_ESCAPE
, Global_Escape
, 0, 1},
2296 {DISPID_GLOBAL_UNESCAPE
, Global_Unescape
, 0, 1},
2297 {DISPID_GLOBAL_EVAL
, Global_Eval
, 0, 1},
2298 {DISPID_GLOBAL_EXECUTE
, Global_Execute
, 0, 1},
2299 {DISPID_GLOBAL_EXECUTEGLOBAL
, Global_ExecuteGlobal
, 0, 1},
2300 {DISPID_GLOBAL_GETREF
, Global_GetRef
, 0, 1},
2301 {DISPID_GLOBAL_VBMSGBOXHELPBUTTON
, NULL
, BP_GET
, VT_I4
, MB_HELP
},
2302 {DISPID_GLOBAL_VBMSGBOXSETFOREGROUND
, NULL
, BP_GET
, VT_I4
, MB_SETFOREGROUND
},
2303 {DISPID_GLOBAL_VBMSGBOXRIGHT
, NULL
, BP_GET
, VT_I4
, MB_RIGHT
},
2304 {DISPID_GLOBAL_VBMSGBOXRTLREADING
, NULL
, BP_GET
, VT_I4
, MB_RTLREADING
}
2307 static HRESULT
Err_Description(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2313 static HRESULT
Err_HelpContext(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2319 static HRESULT
Err_HelpFile(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2325 static HRESULT
Err_Number(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2332 return E_UNEXPECTED
;
2335 FIXME("setter not implemented\n");
2339 hres
= This
->desc
->ctx
->err_number
;
2340 return return_int(res
, HRESULT_FACILITY(hres
) == FACILITY_VBS
? HRESULT_CODE(hres
) : hres
);
2343 static HRESULT
Err_Source(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2349 static HRESULT
Err_Clear(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2354 return E_UNEXPECTED
;
2356 This
->desc
->ctx
->err_number
= S_OK
;
2360 static HRESULT
Err_Raise(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2366 static const builtin_prop_t err_props
[] = {
2367 {DISPID_ERR_DESCRIPTION
, Err_Description
, BP_GETPUT
},
2368 {DISPID_ERR_HELPCONTEXT
, Err_HelpContext
, BP_GETPUT
},
2369 {DISPID_ERR_HELPFILE
, Err_HelpFile
, BP_GETPUT
},
2370 {DISPID_ERR_NUMBER
, Err_Number
, BP_GETPUT
},
2371 {DISPID_ERR_SOURCE
, Err_Source
, BP_GETPUT
},
2372 {DISPID_ERR_CLEAR
, Err_Clear
},
2373 {DISPID_ERR_RAISE
, Err_Raise
, 0, 5},
2376 HRESULT
init_global(script_ctx_t
*ctx
)
2380 ctx
->global_desc
.ctx
= ctx
;
2381 ctx
->global_desc
.builtin_prop_cnt
= sizeof(global_props
)/sizeof(*global_props
);
2382 ctx
->global_desc
.builtin_props
= global_props
;
2384 hres
= get_typeinfo(GlobalObj_tid
, &ctx
->global_desc
.typeinfo
);
2388 hres
= create_vbdisp(&ctx
->global_desc
, &ctx
->global_obj
);
2392 hres
= create_script_disp(ctx
, &ctx
->script_obj
);
2396 ctx
->err_desc
.ctx
= ctx
;
2397 ctx
->err_desc
.builtin_prop_cnt
= sizeof(err_props
)/sizeof(*err_props
);
2398 ctx
->err_desc
.builtin_props
= err_props
;
2400 hres
= get_typeinfo(ErrObj_tid
, &ctx
->err_desc
.typeinfo
);
2404 return create_vbdisp(&ctx
->err_desc
, &ctx
->err_obj
);