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
)
115 if((short)val
== val
)
116 return return_short(res
, val
);
126 static inline HRESULT
return_double(VARIANT
*res
, double val
)
136 static inline HRESULT
return_null(VARIANT
*res
)
143 static inline HRESULT
return_date(VARIANT
*res
, double date
)
152 HRESULT
to_int(VARIANT
*v
, int *ret
)
158 hres
= VariantChangeType(&r
, v
, 0, VT_I4
);
166 static HRESULT
to_double(VARIANT
*v
, double *ret
)
171 V_VT(&dst
) = VT_EMPTY
;
172 hres
= VariantChangeType(&dst
, v
, 0, VT_R8
);
180 static HRESULT
to_string(VARIANT
*v
, BSTR
*ret
)
185 V_VT(&dst
) = VT_EMPTY
;
186 hres
= VariantChangeType(&dst
, v
, VARIANT_LOCALBOOL
, VT_BSTR
);
194 static HRESULT
set_object_site(script_ctx_t
*ctx
, IUnknown
*obj
)
196 IObjectWithSite
*obj_site
;
200 hres
= IUnknown_QueryInterface(obj
, &IID_IObjectWithSite
, (void**)&obj_site
);
204 ax_site
= create_ax_site(ctx
);
206 hres
= IObjectWithSite_SetSite(obj_site
, ax_site
);
208 hres
= E_OUTOFMEMORY
;
209 IUnknown_Release(ax_site
);
210 IObjectWithSite_Release(obj_site
);
214 static IUnknown
*create_object(script_ctx_t
*ctx
, const WCHAR
*progid
)
216 IInternetHostSecurityManager
*secmgr
= NULL
;
217 struct CONFIRMSAFETY cs
;
218 IClassFactoryEx
*cfex
;
227 hres
= CLSIDFromProgID(progid
, &guid
);
231 TRACE("GUID %s\n", debugstr_guid(&guid
));
233 if(ctx
->safeopt
& INTERFACE_USES_SECURITY_MANAGER
) {
234 secmgr
= get_sec_mgr(ctx
);
239 hres
= IInternetHostSecurityManager_ProcessUrlAction(secmgr
, URLACTION_ACTIVEX_RUN
,
240 (BYTE
*)&policy
, sizeof(policy
), (BYTE
*)&guid
, sizeof(GUID
), 0, 0);
241 if(FAILED(hres
) || policy
!= URLPOLICY_ALLOW
)
245 hres
= CoGetClassObject(&guid
, CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, NULL
, &IID_IClassFactory
, (void**)&cf
);
249 hres
= IClassFactory_QueryInterface(cf
, &IID_IClassFactoryEx
, (void**)&cfex
);
250 if(SUCCEEDED(hres
)) {
251 FIXME("Use IClassFactoryEx\n");
252 IClassFactoryEx_Release(cfex
);
255 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IUnknown
, (void**)&obj
);
263 hres
= IInternetHostSecurityManager_QueryCustomPolicy(secmgr
, &GUID_CUSTOM_CONFIRMOBJECTSAFETY
,
264 &bpolicy
, &policy_size
, (BYTE
*)&cs
, sizeof(cs
), 0);
265 if(SUCCEEDED(hres
)) {
266 policy
= policy_size
>= sizeof(DWORD
) ? *(DWORD
*)bpolicy
: URLPOLICY_DISALLOW
;
267 CoTaskMemFree(bpolicy
);
270 if(FAILED(hres
) || policy
!= URLPOLICY_ALLOW
) {
271 IUnknown_Release(obj
);
276 hres
= set_object_site(ctx
, obj
);
278 IUnknown_Release(obj
);
285 static HRESULT
show_msgbox(script_ctx_t
*ctx
, BSTR prompt
, unsigned type
, BSTR orig_title
, VARIANT
*res
)
287 SCRIPTUICHANDLING uic_handling
= SCRIPTUICHANDLING_ALLOW
;
288 IActiveScriptSiteUIControl
*ui_control
;
289 IActiveScriptSiteWindow
*acts_window
;
290 WCHAR
*title_buf
= NULL
;
296 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IActiveScriptSiteUIControl
, (void**)&ui_control
);
297 if(SUCCEEDED(hres
)) {
298 hres
= IActiveScriptSiteUIControl_GetUIBehavior(ui_control
, SCRIPTUICITEM_MSGBOX
, &uic_handling
);
299 IActiveScriptSiteUIControl_Release(ui_control
);
301 uic_handling
= SCRIPTUICHANDLING_ALLOW
;
304 switch(uic_handling
) {
305 case SCRIPTUICHANDLING_ALLOW
:
307 case SCRIPTUICHANDLING_NOUIDEFAULT
:
308 return return_short(res
, 0);
314 hres
= IActiveScriptSite_QueryInterface(ctx
->site
, &IID_IActiveScriptSiteWindow
, (void**)&acts_window
);
316 FIXME("No IActiveScriptSiteWindow\n");
320 if(ctx
->safeopt
& INTERFACE_USES_SECURITY_MANAGER
) {
321 if(orig_title
&& *orig_title
) {
324 title
= title_buf
= heap_alloc(sizeof(vbscriptW
) + (strlenW(orig_title
)+2)*sizeof(WCHAR
));
326 return E_OUTOFMEMORY
;
328 memcpy(title_buf
, vbscriptW
, sizeof(vbscriptW
));
329 ptr
= title_buf
+ sizeof(vbscriptW
)/sizeof(WCHAR
)-1;
333 strcpyW(ptr
, orig_title
);
338 title
= orig_title
? orig_title
: emptyW
;
341 hres
= IActiveScriptSiteWindow_GetWindow(acts_window
, &hwnd
);
342 if(SUCCEEDED(hres
)) {
343 hres
= IActiveScriptSiteWindow_EnableModeless(acts_window
, FALSE
);
344 if(SUCCEEDED(hres
)) {
345 ret
= MessageBoxW(hwnd
, prompt
, title
, type
);
346 hres
= IActiveScriptSiteWindow_EnableModeless(acts_window
, TRUE
);
350 heap_free(title_buf
);
351 IActiveScriptSiteWindow_Release(acts_window
);
353 FIXME("failed: %08x\n", hres
);
357 return return_short(res
, ret
);
360 static HRESULT
Global_CCur(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
365 TRACE("%s\n", debugstr_variant(arg
));
367 assert(args_cnt
== 1);
370 hres
= VariantChangeType(&v
, arg
, 0, VT_CY
);
376 return DISP_E_BADVARTYPE
;
383 static HRESULT
Global_CInt(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
388 TRACE("%s\n", debugstr_variant(arg
));
390 assert(args_cnt
== 1);
393 hres
= VariantChangeType(&v
, arg
, 0, VT_I2
);
398 return DISP_E_BADVARTYPE
;
405 static HRESULT
Global_CLng(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
410 TRACE("%s\n", debugstr_variant(arg
));
412 assert(args_cnt
== 1);
414 hres
= to_int(arg
, &i
);
418 return DISP_E_BADVARTYPE
;
425 static HRESULT
Global_CBool(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
430 TRACE("%s\n", debugstr_variant(arg
));
432 assert(args_cnt
== 1);
435 hres
= VariantChangeType(&v
, arg
, VARIANT_LOCALBOOL
, VT_BOOL
);
446 static HRESULT
Global_CByte(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
451 TRACE("%s\n", debugstr_variant(arg
));
453 assert(args_cnt
== 1);
456 hres
= VariantChangeType(&v
, arg
, VARIANT_LOCALBOOL
, VT_UI1
);
462 return DISP_E_BADVARTYPE
;
469 static HRESULT
Global_CDate(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
475 static HRESULT
Global_CDbl(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
480 TRACE("%s\n", debugstr_variant(arg
));
482 assert(args_cnt
== 1);
485 hres
= VariantChangeType(&v
, arg
, 0, VT_R8
);
490 return DISP_E_BADVARTYPE
;
497 static HRESULT
Global_CSng(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
502 TRACE("%s\n", debugstr_variant(arg
));
504 assert(args_cnt
== 1);
507 hres
= VariantChangeType(&v
, arg
, 0, VT_R4
);
512 return DISP_E_BADVARTYPE
;
518 static HRESULT
Global_CStr(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
523 TRACE("%s\n", debugstr_variant(arg
));
525 hres
= to_string(arg
, &str
);
529 return return_bstr(res
, str
);
532 static inline WCHAR
hex_char(unsigned n
)
534 return n
< 10 ? '0'+n
: 'A'+n
-10;
537 static HRESULT
Global_Hex(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
542 TRACE("%s\n", debugstr_variant(arg
));
559 FIXME("unsupported type %s\n", debugstr_variant(arg
));
568 *ptr
-- = hex_char(n
& 0xf);
576 return return_string(res
, ptr
);
579 static HRESULT
Global_Oct(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
585 static HRESULT
Global_VarType(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
587 TRACE("(%s)\n", debugstr_variant(arg
));
589 assert(args_cnt
== 1);
591 if(V_VT(arg
) & ~VT_TYPEMASK
) {
592 FIXME("not supported %s\n", debugstr_variant(arg
));
596 return return_short(res
, V_VT(arg
));
599 static HRESULT
Global_IsDate(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
605 static HRESULT
Global_IsEmpty(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
607 TRACE("(%s)\n", debugstr_variant(arg
));
609 assert(args_cnt
== 1);
613 V_BOOL(res
) = V_VT(arg
) == VT_EMPTY
? VARIANT_TRUE
: VARIANT_FALSE
;
618 static HRESULT
Global_IsNull(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
620 TRACE("(%s)\n", debugstr_variant(arg
));
622 assert(args_cnt
== 1);
626 V_BOOL(res
) = V_VT(arg
) == VT_NULL
? VARIANT_TRUE
: VARIANT_FALSE
;
631 static HRESULT
Global_IsNumeric(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
636 TRACE("(%s)\n", debugstr_variant(arg
));
638 assert(args_cnt
== 1);
640 hres
= to_double(arg
, &d
);
642 return return_bool(res
, SUCCEEDED(hres
));
645 static HRESULT
Global_IsArray(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
651 static HRESULT
Global_IsObject(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
653 TRACE("(%s)\n", debugstr_variant(arg
));
655 assert(args_cnt
== 1);
659 V_BOOL(res
) = V_VT(arg
) == VT_DISPATCH
? VARIANT_TRUE
: VARIANT_FALSE
;
664 static HRESULT
Global_Ant(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
670 static HRESULT
Global_Cos(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
675 hres
= to_double(arg
, &d
);
679 return return_double(res
, cos(d
));
682 static HRESULT
Global_Sin(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
687 hres
= to_double(arg
, &d
);
691 return return_double(res
, sin(d
));
694 static HRESULT
Global_Tan(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
700 static HRESULT
Global_Exp(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
706 static HRESULT
Global_Log(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
712 static HRESULT
Global_Sqr(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
717 hres
= to_double(arg
, &d
);
722 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL
);
724 return return_double(res
, sqrt(d
));
727 static HRESULT
Global_Randomize(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
733 static HRESULT
Global_Rnd(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
739 static HRESULT
Global_Timer(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
745 static HRESULT
Global_LBound(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
751 static HRESULT
Global_UBound(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
757 static HRESULT
Global_RGB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
763 static HRESULT
Global_Len(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
768 TRACE("%s\n", debugstr_variant(arg
));
770 if(V_VT(arg
) == VT_NULL
)
771 return return_null(res
);
773 if(V_VT(arg
) != VT_BSTR
) {
776 hres
= to_string(arg
, &str
);
780 len
= SysStringLen(str
);
783 len
= SysStringLen(V_BSTR(arg
));
786 return return_int(res
, len
);
789 static HRESULT
Global_LenB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
795 static HRESULT
Global_Left(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
797 BSTR str
, ret
, conv_str
= NULL
;
801 TRACE("(%s %s)\n", debugstr_variant(args
+1), debugstr_variant(args
));
803 if(V_VT(args
) == VT_BSTR
) {
806 hres
= to_string(args
, &conv_str
);
812 hres
= to_int(args
+1, &len
);
817 FIXME("len = %d\n", len
);
821 str_len
= SysStringLen(str
);
825 ret
= SysAllocStringLen(str
, len
);
826 SysFreeString(conv_str
);
828 return E_OUTOFMEMORY
;
830 return return_bstr(res
, ret
);
833 static HRESULT
Global_LeftB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
839 static HRESULT
Global_Right(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
841 BSTR str
, ret
, conv_str
= NULL
;
845 TRACE("(%s %s)\n", debugstr_variant(args
), debugstr_variant(args
+1));
847 if(V_VT(args
+1) == VT_BSTR
) {
850 hres
= to_string(args
, &conv_str
);
856 hres
= to_int(args
+1, &len
);
861 FIXME("len = %d\n", len
);
865 str_len
= SysStringLen(str
);
869 ret
= SysAllocStringLen(str
+str_len
-len
, len
);
870 SysFreeString(conv_str
);
872 return E_OUTOFMEMORY
;
874 return return_bstr(res
, ret
);
877 static HRESULT
Global_RightB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
883 static HRESULT
Global_Mid(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
885 int len
= -1, start
, str_len
;
889 TRACE("(%s %s ...)\n", debugstr_variant(args
), debugstr_variant(args
+1));
891 assert(args_cnt
== 2 || args_cnt
== 3);
893 if(V_VT(args
) != VT_BSTR
) {
894 FIXME("args[0] = %s\n", debugstr_variant(args
));
900 hres
= to_int(args
+1, &start
);
905 hres
= to_int(args
+2, &len
);
910 FIXME("len = %d\n", len
);
916 str_len
= SysStringLen(str
);
923 else if(len
> str_len
-start
)
928 V_BSTR(res
) = SysAllocStringLen(str
+start
, len
);
930 return E_OUTOFMEMORY
;
936 static HRESULT
Global_MidB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
942 static HRESULT
Global_StrComp(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
948 static HRESULT
Global_LCase(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
953 TRACE("%s\n", debugstr_variant(arg
));
955 if(V_VT(arg
) == VT_NULL
) {
961 hres
= to_string(arg
, &str
);
968 for(ptr
= str
; *ptr
; ptr
++)
969 *ptr
= tolowerW(*ptr
);
979 static HRESULT
Global_UCase(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
984 TRACE("%s\n", debugstr_variant(arg
));
986 if(V_VT(arg
) == VT_NULL
) {
992 hres
= to_string(arg
, &str
);
999 for(ptr
= str
; *ptr
; ptr
++)
1000 *ptr
= toupperW(*ptr
);
1002 V_VT(res
) = VT_BSTR
;
1010 static HRESULT
Global_LTrim(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1012 BSTR str
, conv_str
= NULL
;
1016 TRACE("%s\n", debugstr_variant(arg
));
1018 if(V_VT(arg
) == VT_BSTR
) {
1021 hres
= to_string(arg
, &conv_str
);
1027 for(ptr
= str
; *ptr
&& isspaceW(*ptr
); ptr
++);
1029 str
= SysAllocString(ptr
);
1030 SysFreeString(conv_str
);
1032 return E_OUTOFMEMORY
;
1034 return return_bstr(res
, str
);
1037 static HRESULT
Global_RTrim(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1039 BSTR str
, conv_str
= NULL
;
1043 TRACE("%s\n", debugstr_variant(arg
));
1045 if(V_VT(arg
) == VT_BSTR
) {
1048 hres
= to_string(arg
, &conv_str
);
1054 for(ptr
= str
+SysStringLen(str
); ptr
-1 > str
&& isspaceW(*(ptr
-1)); ptr
--);
1056 str
= SysAllocStringLen(str
, ptr
-str
);
1057 SysFreeString(conv_str
);
1059 return E_OUTOFMEMORY
;
1061 return return_bstr(res
, str
);
1064 static HRESULT
Global_Trim(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1066 BSTR str
, conv_str
= NULL
;
1067 WCHAR
*begin_ptr
, *end_ptr
;
1070 TRACE("%s\n", debugstr_variant(arg
));
1072 if(V_VT(arg
) == VT_BSTR
) {
1075 hres
= to_string(arg
, &conv_str
);
1081 for(begin_ptr
= str
; *begin_ptr
&& isspaceW(*begin_ptr
); begin_ptr
++);
1082 for(end_ptr
= str
+SysStringLen(str
); end_ptr
-1 > begin_ptr
&& isspaceW(*(end_ptr
-1)); end_ptr
--);
1084 str
= SysAllocStringLen(begin_ptr
, end_ptr
-begin_ptr
);
1085 SysFreeString(conv_str
);
1087 return E_OUTOFMEMORY
;
1089 return return_bstr(res
, str
);
1092 static HRESULT
Global_Space(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1098 TRACE("%s\n", debugstr_variant(arg
));
1100 hres
= to_int(arg
, &n
);
1105 FIXME("n = %d\n", n
);
1112 str
= SysAllocStringLen(NULL
, n
);
1114 return E_OUTOFMEMORY
;
1119 V_VT(res
) = VT_BSTR
;
1124 static HRESULT
Global_String(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1130 static HRESULT
Global_InStr(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1132 VARIANT
*startv
, *str1v
, *str2v
;
1139 assert(2 <= args_cnt
&& args_cnt
<= 4);
1153 FIXME("unsupported compare argument %s\n", debugstr_variant(args
));
1155 DEFAULT_UNREACHABLE
;
1159 hres
= to_int(startv
, &start
);
1163 FIXME("start %d\n", start
);
1170 if(V_VT(str1v
) == VT_NULL
|| V_VT(str2v
) == VT_NULL
)
1171 return return_null(res
);
1173 if(V_VT(str1v
) != VT_BSTR
) {
1174 FIXME("Unsupported str1 type %s\n", debugstr_variant(str1v
));
1177 str1
= V_BSTR(str1v
);
1179 if(V_VT(str2v
) != VT_BSTR
) {
1180 FIXME("Unsupported str2 type %s\n", debugstr_variant(str2v
));
1183 str2
= V_BSTR(str2v
);
1185 if(start
< SysStringLen(str1
)) {
1188 ptr
= strstrW(str1
+start
, str2
);
1189 ret
= ptr
? ptr
-str1
+1 : 0;
1194 return return_int(res
, ret
);
1197 static HRESULT
Global_InStrB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1203 static HRESULT
Global_AscB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1209 static HRESULT
Global_ChrB(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1215 static HRESULT
Global_Asc(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1221 /* The function supports only single-byte and double-byte character sets. It
1222 * ignores language specified by IActiveScriptSite::GetLCID. The argument needs
1223 * to be in range of short or unsigned short. */
1224 static HRESULT
Global_Chr(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1232 TRACE("%s\n", debugstr_variant(arg
));
1234 hres
= to_int(arg
, &c
);
1239 if(!GetCPInfo(cp
, &cpi
))
1240 cpi
.MaxCharSize
= 1;
1242 if((c
!=(short)c
&& c
!=(unsigned short)c
) ||
1243 (unsigned short)c
>=(cpi
.MaxCharSize
>1 ? 0x10000 : 0x100)) {
1244 WARN("invalid arg %d\n", c
);
1245 return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL
);
1250 if(!len
|| IsDBCSLeadByteEx(cp
, buf
[0]))
1252 if(!MultiByteToWideChar(0, 0, buf
, len
, &ch
, 1)) {
1253 WARN("invalid arg %d, cp %d\n", c
, cp
);
1258 V_VT(res
) = VT_BSTR
;
1259 V_BSTR(res
) = SysAllocStringLen(&ch
, 1);
1261 return E_OUTOFMEMORY
;
1266 static HRESULT
Global_AscW(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1272 static HRESULT
Global_ChrW(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1278 static HRESULT
Global_Abs(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1283 TRACE("(%s)\n", debugstr_variant(arg
));
1285 assert(args_cnt
== 1);
1287 hres
= VarAbs(arg
, &dst
);
1299 static HRESULT
Global_Fix(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1304 TRACE("(%s)\n", debugstr_variant(arg
));
1306 assert(args_cnt
== 1);
1308 hres
= VarFix(arg
, &dst
);
1320 static HRESULT
Global_Int(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1325 TRACE("(%s)\n", debugstr_variant(arg
));
1327 assert(args_cnt
== 1);
1329 hres
= VarInt(arg
, &dst
);
1341 static HRESULT
Global_Sgn(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1347 TRACE("(%s)\n", debugstr_variant(arg
));
1349 assert(args_cnt
== 1);
1351 if(V_VT(arg
) == VT_NULL
)
1352 return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE
);
1354 hres
= to_double(arg
, &v
);
1358 val
= v
== 0 ? 0 : (v
> 0 ? 1 : -1);
1359 return return_short(res
, val
);
1362 static HRESULT
Global_Now(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1370 SystemTimeToVariantTime(<
, &date
);
1371 return return_date(res
, date
);
1374 static HRESULT
Global_Date(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1380 static HRESULT
Global_Time(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1386 static HRESULT
Global_Day(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1392 static HRESULT
Global_Month(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1398 static HRESULT
Global_Weekday(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1404 static HRESULT
Global_Year(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1410 static HRESULT
Global_Hour(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1416 static HRESULT
Global_Minute(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1422 static HRESULT
Global_Second(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1428 static HRESULT
Global_DateValue(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1434 static HRESULT
Global_TimeValue(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1440 static HRESULT
Global_DateSerial(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1446 static HRESULT
Global_TimeSerial(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1452 static HRESULT
Global_InputBox(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1458 static HRESULT
Global_MsgBox(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1460 BSTR prompt
, title
= NULL
;
1466 assert(1 <= args_cnt
&& args_cnt
<= 5);
1468 hres
= to_string(args
, &prompt
);
1473 hres
= to_int(args
+1, &type
);
1475 if(SUCCEEDED(hres
) && args_cnt
> 2)
1476 hres
= to_string(args
+2, &title
);
1478 if(SUCCEEDED(hres
) && args_cnt
> 3) {
1479 FIXME("unsupported arg_cnt %d\n", args_cnt
);
1484 hres
= show_msgbox(This
->desc
->ctx
, prompt
, type
, title
, res
);
1486 SysFreeString(prompt
);
1487 SysFreeString(title
);
1491 static HRESULT
Global_CreateObject(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1496 TRACE("(%s)\n", debugstr_variant(arg
));
1498 if(V_VT(arg
) != VT_BSTR
) {
1499 FIXME("non-bstr arg\n");
1500 return E_INVALIDARG
;
1503 obj
= create_object(This
->desc
->ctx
, V_BSTR(arg
));
1505 return VB_E_CANNOT_CREATE_OBJ
;
1508 hres
= IUnknown_QueryInterface(obj
, &IID_IDispatch
, (void**)&V_DISPATCH(res
));
1512 V_VT(res
) = VT_DISPATCH
;
1515 IUnknown_Release(obj
);
1519 static HRESULT
Global_GetObject(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1528 TRACE("%s %s\n", args_cnt
? debugstr_variant(args
) : "", args_cnt
> 1 ? debugstr_variant(args
+1) : "");
1530 if(args_cnt
!= 1 || V_VT(args
) != VT_BSTR
) {
1531 FIXME("unsupported args\n");
1535 if(This
->desc
->ctx
->safeopt
& (INTERFACE_USES_SECURITY_MANAGER
|INTERFACESAFE_FOR_UNTRUSTED_DATA
)) {
1536 WARN("blocked in current safety mode\n");
1537 return VB_E_CANNOT_CREATE_OBJ
;
1540 hres
= CreateBindCtx(0, &bind_ctx
);
1544 hres
= MkParseDisplayName(bind_ctx
, V_BSTR(args
), &eaten
, &mon
);
1545 if(SUCCEEDED(hres
)) {
1546 hres
= IMoniker_BindToObject(mon
, bind_ctx
, NULL
, &IID_IUnknown
, (void**)&obj_unk
);
1547 IMoniker_Release(mon
);
1551 IBindCtx_Release(bind_ctx
);
1555 hres
= set_object_site(This
->desc
->ctx
, obj_unk
);
1557 IUnknown_Release(obj_unk
);
1561 hres
= IUnknown_QueryInterface(obj_unk
, &IID_IDispatch
, (void**)&disp
);
1562 if(SUCCEEDED(hres
)) {
1564 V_VT(res
) = VT_DISPATCH
;
1565 V_DISPATCH(res
) = disp
;
1567 IDispatch_Release(disp
);
1570 FIXME("object does not support IDispatch\n");
1576 static HRESULT
Global_DateAdd(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1582 static HRESULT
Global_DateDiff(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1588 static HRESULT
Global_DatePart(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1594 static HRESULT
Global_TypeName(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1596 static const WCHAR ByteW
[] = {'B', 'y', 't', 'e', 0};
1597 static const WCHAR IntegerW
[] = {'I', 'n', 't', 'e', 'g', 'e', 'r', 0};
1598 static const WCHAR LongW
[] = {'L', 'o', 'n', 'g', 0};
1599 static const WCHAR SingleW
[] = {'S', 'i', 'n', 'g', 'l', 'e', 0};
1600 static const WCHAR DoubleW
[] = {'D', 'o', 'u', 'b', 'l', 'e', 0};
1601 static const WCHAR CurrencyW
[] = {'C', 'u', 'r', 'r', 'e', 'n', 'c', 'y', 0};
1602 static const WCHAR DecimalW
[] = {'D', 'e', 'c', 'i', 'm', 'a', 'l', 0};
1603 static const WCHAR DateW
[] = {'D', 'a', 't', 'e', 0};
1604 static const WCHAR StringW
[] = {'S', 't', 'r', 'i', 'n', 'g', 0};
1605 static const WCHAR BooleanW
[] = {'B', 'o', 'o', 'l', 'e', 'a', 'n', 0};
1606 static const WCHAR EmptyW
[] = {'E', 'm', 'p', 't', 'y', 0};
1607 static const WCHAR NullW
[] = {'N', 'u', 'l', 'l', 0};
1609 TRACE("(%s)\n", debugstr_variant(arg
));
1611 assert(args_cnt
== 1);
1615 return return_string(res
, ByteW
);
1617 return return_string(res
, IntegerW
);
1619 return return_string(res
, LongW
);
1621 return return_string(res
, SingleW
);
1623 return return_string(res
, DoubleW
);
1625 return return_string(res
, CurrencyW
);
1627 return return_string(res
, DecimalW
);
1629 return return_string(res
, DateW
);
1631 return return_string(res
, StringW
);
1633 return return_string(res
, BooleanW
);
1635 return return_string(res
, EmptyW
);
1637 return return_string(res
, NullW
);
1639 FIXME("arg %s not supported\n", debugstr_variant(arg
));
1644 static HRESULT
Global_Array(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1650 static HRESULT
Global_Erase(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1656 static HRESULT
Global_Filter(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1662 static HRESULT
Global_Join(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1668 static HRESULT
Global_Split(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1674 static HRESULT
Global_Replace(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1680 static HRESULT
Global_StrReverse(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1682 WCHAR
*ptr1
, *ptr2
, ch
;
1686 TRACE("%s\n", debugstr_variant(arg
));
1688 hres
= to_string(arg
, &ret
);
1693 ptr2
= ret
+ SysStringLen(ret
)-1;
1694 while(ptr1
< ptr2
) {
1700 return return_bstr(res
, ret
);
1703 static HRESULT
Global_InStrRev(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1709 static HRESULT
Global_LoadPicture(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1715 static HRESULT
Global_ScriptEngine(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1717 TRACE("%s\n", debugstr_variant(arg
));
1719 assert(args_cnt
== 0);
1721 return return_string(res
, vbscriptW
);
1724 static HRESULT
Global_ScriptEngineMajorVersion(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1726 TRACE("%s\n", debugstr_variant(arg
));
1728 assert(args_cnt
== 0);
1732 V_I4(res
) = VBSCRIPT_MAJOR_VERSION
;
1738 static HRESULT
Global_ScriptEngineMinorVersion(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1740 TRACE("%s\n", debugstr_variant(arg
));
1742 assert(args_cnt
== 0);
1746 V_I4(res
) = VBSCRIPT_MINOR_VERSION
;
1752 static HRESULT
Global_ScriptEngineBuildVersion(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1754 TRACE("%s\n", debugstr_variant(arg
));
1756 assert(args_cnt
== 0);
1760 V_I4(res
) = VBSCRIPT_BUILD_VERSION
;
1766 static HRESULT
Global_FormatNumber(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1772 static HRESULT
Global_FormatCurrency(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1778 static HRESULT
Global_FormatPercent(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1784 static HRESULT
Global_FormatDateTime(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1790 static HRESULT
Global_WeekdayName(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1792 int weekday
, first_day
= 1, abbrev
= 0;
1798 assert(1 <= args_cnt
&& args_cnt
<= 3);
1800 hres
= to_int(args
, &weekday
);
1805 hres
= to_int(args
+1, &abbrev
);
1810 hres
= to_int(args
+2, &first_day
);
1816 hres
= VarWeekdayName(weekday
, abbrev
, first_day
, 0, &ret
);
1820 return return_bstr(res
, ret
);
1823 static HRESULT
Global_MonthName(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
1825 int month
, abbrev
= 0;
1831 assert(args_cnt
== 1 || args_cnt
== 2);
1833 hres
= to_int(args
, &month
);
1838 hres
= to_int(args
+1, &abbrev
);
1843 hres
= VarMonthName(month
, abbrev
, 0, &ret
);
1847 return return_bstr(res
, ret
);
1850 static HRESULT
Global_Round(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1855 TRACE("%s\n", debugstr_variant(arg
));
1870 hres
= to_double(arg
, &n
);
1875 return return_double(res
, round(n
));
1878 static HRESULT
Global_Escape(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1884 static HRESULT
Global_Unescape(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1890 static HRESULT
Global_Eval(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1896 static HRESULT
Global_Execute(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1902 static HRESULT
Global_ExecuteGlobal(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1908 static HRESULT
Global_GetRef(vbdisp_t
*This
, VARIANT
*arg
, unsigned args_cnt
, VARIANT
*res
)
1914 static const string_constant_t vbCr
= {1, {'\r'}};
1915 static const string_constant_t vbCrLf
= {2, {'\r','\n'}};
1916 static const string_constant_t vbNewLine
= {2, {'\r','\n'}};
1917 static const string_constant_t vbFormFeed
= {1, {0xc}};
1918 static const string_constant_t vbLf
= {1, {'\n'}};
1919 static const string_constant_t vbNullChar
= {1};
1920 static const string_constant_t vbNullString
= {0};
1921 static const string_constant_t vbTab
= {1, {'\t'}};
1922 static const string_constant_t vbVerticalTab
= {1, {0xb}};
1924 static const builtin_prop_t global_props
[] = {
1925 {DISPID_GLOBAL_VBUSESYSTEM
, NULL
, BP_GET
, VT_I2
, 0},
1926 {DISPID_GLOBAL_USESYSTEMDAYOFWEEK
, NULL
, BP_GET
, VT_I2
, 0},
1927 {DISPID_GLOBAL_VBSUNDAY
, NULL
, BP_GET
, VT_I2
, 1},
1928 {DISPID_GLOBAL_VBMONDAY
, NULL
, BP_GET
, VT_I2
, 2},
1929 {DISPID_GLOBAL_VBTUESDAY
, NULL
, BP_GET
, VT_I2
, 3},
1930 {DISPID_GLOBAL_VBWEDNESDAY
, NULL
, BP_GET
, VT_I2
, 4},
1931 {DISPID_GLOBAL_VBTHURSDAY
, NULL
, BP_GET
, VT_I2
, 5},
1932 {DISPID_GLOBAL_VBFRIDAY
, NULL
, BP_GET
, VT_I2
, 6},
1933 {DISPID_GLOBAL_VBSATURDAY
, NULL
, BP_GET
, VT_I2
, 7},
1934 {DISPID_GLOBAL_VBFIRSTJAN1
, NULL
, BP_GET
, VT_I2
, 1},
1935 {DISPID_GLOBAL_VBFIRSTFOURDAYS
, NULL
, BP_GET
, VT_I2
, 2},
1936 {DISPID_GLOBAL_VBFIRSTFULLWEEK
, NULL
, BP_GET
, VT_I2
, 3},
1937 {DISPID_GLOBAL_VBOKONLY
, NULL
, BP_GET
, VT_I2
, MB_OK
},
1938 {DISPID_GLOBAL_VBOKCANCEL
, NULL
, BP_GET
, VT_I2
, MB_OKCANCEL
},
1939 {DISPID_GLOBAL_VBABORTRETRYIGNORE
, NULL
, BP_GET
, VT_I2
, MB_ABORTRETRYIGNORE
},
1940 {DISPID_GLOBAL_VBYESNOCANCEL
, NULL
, BP_GET
, VT_I2
, MB_YESNOCANCEL
},
1941 {DISPID_GLOBAL_VBYESNO
, NULL
, BP_GET
, VT_I2
, MB_YESNO
},
1942 {DISPID_GLOBAL_VBRETRYCANCEL
, NULL
, BP_GET
, VT_I2
, MB_RETRYCANCEL
},
1943 {DISPID_GLOBAL_VBCRITICAL
, NULL
, BP_GET
, VT_I2
, MB_ICONHAND
},
1944 {DISPID_GLOBAL_VBQUESTION
, NULL
, BP_GET
, VT_I2
, MB_ICONQUESTION
},
1945 {DISPID_GLOBAL_VBEXCLAMATION
, NULL
, BP_GET
, VT_I2
, MB_ICONEXCLAMATION
},
1946 {DISPID_GLOBAL_VBINFORMATION
, NULL
, BP_GET
, VT_I2
, MB_ICONASTERISK
},
1947 {DISPID_GLOBAL_VBDEFAULTBUTTON1
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON1
},
1948 {DISPID_GLOBAL_VBDEFAULTBUTTON2
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON2
},
1949 {DISPID_GLOBAL_VBDEFAULTBUTTON3
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON3
},
1950 {DISPID_GLOBAL_VBDEFAULTBUTTON4
, NULL
, BP_GET
, VT_I2
, MB_DEFBUTTON4
},
1951 {DISPID_GLOBAL_VBAPPLICATIONMODAL
, NULL
, BP_GET
, VT_I2
, MB_APPLMODAL
},
1952 {DISPID_GLOBAL_VBSYSTEMMODAL
, NULL
, BP_GET
, VT_I2
, MB_SYSTEMMODAL
},
1953 {DISPID_GLOBAL_VBOK
, NULL
, BP_GET
, VT_I2
, IDOK
},
1954 {DISPID_GLOBAL_VBCANCEL
, NULL
, BP_GET
, VT_I2
, IDCANCEL
},
1955 {DISPID_GLOBAL_VBABORT
, NULL
, BP_GET
, VT_I2
, IDABORT
},
1956 {DISPID_GLOBAL_VBRETRY
, NULL
, BP_GET
, VT_I2
, IDRETRY
},
1957 {DISPID_GLOBAL_VBIGNORE
, NULL
, BP_GET
, VT_I2
, IDIGNORE
},
1958 {DISPID_GLOBAL_VBYES
, NULL
, BP_GET
, VT_I2
, IDYES
},
1959 {DISPID_GLOBAL_VBNO
, NULL
, BP_GET
, VT_I2
, IDNO
},
1960 {DISPID_GLOBAL_VBEMPTY
, NULL
, BP_GET
, VT_I2
, VT_EMPTY
},
1961 {DISPID_GLOBAL_VBNULL
, NULL
, BP_GET
, VT_I2
, VT_NULL
},
1962 {DISPID_GLOBAL_VBINTEGER
, NULL
, BP_GET
, VT_I2
, VT_I2
},
1963 {DISPID_GLOBAL_VBLONG
, NULL
, BP_GET
, VT_I2
, VT_I4
},
1964 {DISPID_GLOBAL_VBSINGLE
, NULL
, BP_GET
, VT_I2
, VT_R4
},
1965 {DISPID_GLOBAL_VBDOUBLE
, NULL
, BP_GET
, VT_I2
, VT_R8
},
1966 {DISPID_GLOBAL_VBCURRENCY
, NULL
, BP_GET
, VT_I2
, VT_CY
},
1967 {DISPID_GLOBAL_VBDATE
, NULL
, BP_GET
, VT_I2
, VT_DATE
},
1968 {DISPID_GLOBAL_VBSTRING
, NULL
, BP_GET
, VT_I2
, VT_BSTR
},
1969 {DISPID_GLOBAL_VBOBJECT
, NULL
, BP_GET
, VT_I2
, VT_DISPATCH
},
1970 {DISPID_GLOBAL_VBERROR
, NULL
, BP_GET
, VT_I2
, VT_ERROR
},
1971 {DISPID_GLOBAL_VBBOOLEAN
, NULL
, BP_GET
, VT_I2
, VT_BOOL
},
1972 {DISPID_GLOBAL_VBVARIANT
, NULL
, BP_GET
, VT_I2
, VT_VARIANT
},
1973 {DISPID_GLOBAL_VBDATAOBJECT
, NULL
, BP_GET
, VT_I2
, VT_UNKNOWN
},
1974 {DISPID_GLOBAL_VBDECIMAL
, NULL
, BP_GET
, VT_I2
, VT_DECIMAL
},
1975 {DISPID_GLOBAL_VBBYTE
, NULL
, BP_GET
, VT_I2
, VT_UI1
},
1976 {DISPID_GLOBAL_VBARRAY
, NULL
, BP_GET
, VT_I2
, VT_ARRAY
},
1977 {DISPID_GLOBAL_VBTRUE
, NULL
, BP_GET
, VT_I2
, VARIANT_TRUE
},
1978 {DISPID_GLOBAL_VBFALSE
, NULL
, BP_GET
, VT_I2
, VARIANT_FALSE
},
1979 {DISPID_GLOBAL_VBUSEDEFAULT
, NULL
, BP_GET
, VT_I2
, -2},
1980 {DISPID_GLOBAL_VBBINARYCOMPARE
, NULL
, BP_GET
, VT_I2
, 0},
1981 {DISPID_GLOBAL_VBTEXTCOMPARE
, NULL
, BP_GET
, VT_I2
, 1},
1982 {DISPID_GLOBAL_VBDATABASECOMPARE
, NULL
, BP_GET
, VT_I2
, 2},
1983 {DISPID_GLOBAL_VBGENERALDATE
, NULL
, BP_GET
, VT_I2
, 0},
1984 {DISPID_GLOBAL_VBLONGDATE
, NULL
, BP_GET
, VT_I2
, 1},
1985 {DISPID_GLOBAL_VBSHORTDATE
, NULL
, BP_GET
, VT_I2
, 2},
1986 {DISPID_GLOBAL_VBLONGTIME
, NULL
, BP_GET
, VT_I2
, 3},
1987 {DISPID_GLOBAL_VBSHORTTIME
, NULL
, BP_GET
, VT_I2
, 4},
1988 {DISPID_GLOBAL_VBOBJECTERROR
, NULL
, BP_GET
, VT_I4
, 0x80040000},
1989 {DISPID_GLOBAL_VBBLACK
, NULL
, BP_GET
, VT_I4
, 0x000000},
1990 {DISPID_GLOBAL_VBBLUE
, NULL
, BP_GET
, VT_I4
, 0xff0000},
1991 {DISPID_GLOBAL_VBCYAN
, NULL
, BP_GET
, VT_I4
, 0xffff00},
1992 {DISPID_GLOBAL_VBGREEN
, NULL
, BP_GET
, VT_I4
, 0x00ff00},
1993 {DISPID_GLOBAL_VBMAGENTA
, NULL
, BP_GET
, VT_I4
, 0xff00ff},
1994 {DISPID_GLOBAL_VBRED
, NULL
, BP_GET
, VT_I4
, 0x0000ff},
1995 {DISPID_GLOBAL_VBWHITE
, NULL
, BP_GET
, VT_I4
, 0xffffff},
1996 {DISPID_GLOBAL_VBYELLOW
, NULL
, BP_GET
, VT_I4
, 0x00ffff},
1997 {DISPID_GLOBAL_VBCR
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbCr
},
1998 {DISPID_GLOBAL_VBCRLF
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbCrLf
},
1999 {DISPID_GLOBAL_VBNEWLINE
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbNewLine
},
2000 {DISPID_GLOBAL_VBFORMFEED
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbFormFeed
},
2001 {DISPID_GLOBAL_VBLF
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbLf
},
2002 {DISPID_GLOBAL_VBNULLCHAR
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbNullChar
},
2003 {DISPID_GLOBAL_VBNULLSTRING
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbNullString
},
2004 {DISPID_GLOBAL_VBTAB
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbTab
},
2005 {DISPID_GLOBAL_VBVERTICALTAB
, NULL
, BP_GET
, VT_BSTR
, (UINT_PTR
)&vbVerticalTab
},
2006 {DISPID_GLOBAL_CCUR
, Global_CCur
, 0, 1},
2007 {DISPID_GLOBAL_CINT
, Global_CInt
, 0, 1},
2008 {DISPID_GLOBAL_CLNG
, Global_CLng
, 0, 1},
2009 {DISPID_GLOBAL_CBOOL
, Global_CBool
, 0, 1},
2010 {DISPID_GLOBAL_CBYTE
, Global_CByte
, 0, 1},
2011 {DISPID_GLOBAL_CDATE
, Global_CDate
, 0, 1},
2012 {DISPID_GLOBAL_CDBL
, Global_CDbl
, 0, 1},
2013 {DISPID_GLOBAL_CSNG
, Global_CSng
, 0, 1},
2014 {DISPID_GLOBAL_CSTR
, Global_CStr
, 0, 1},
2015 {DISPID_GLOBAL_HEX
, Global_Hex
, 0, 1},
2016 {DISPID_GLOBAL_OCT
, Global_Oct
, 0, 1},
2017 {DISPID_GLOBAL_VARTYPE
, Global_VarType
, 0, 1},
2018 {DISPID_GLOBAL_ISDATE
, Global_IsDate
, 0, 1},
2019 {DISPID_GLOBAL_ISEMPTY
, Global_IsEmpty
, 0, 1},
2020 {DISPID_GLOBAL_ISNULL
, Global_IsNull
, 0, 1},
2021 {DISPID_GLOBAL_ISNUMERIC
, Global_IsNumeric
, 0, 1},
2022 {DISPID_GLOBAL_ISARRAY
, Global_IsArray
, 0, 1},
2023 {DISPID_GLOBAL_ISOBJECT
, Global_IsObject
, 0, 1},
2024 {DISPID_GLOBAL_ATN
, Global_Ant
, 0, 1},
2025 {DISPID_GLOBAL_COS
, Global_Cos
, 0, 1},
2026 {DISPID_GLOBAL_SIN
, Global_Sin
, 0, 1},
2027 {DISPID_GLOBAL_TAN
, Global_Tan
, 0, 1},
2028 {DISPID_GLOBAL_EXP
, Global_Exp
, 0, 1},
2029 {DISPID_GLOBAL_LOG
, Global_Log
, 0, 1},
2030 {DISPID_GLOBAL_SQR
, Global_Sqr
, 0, 1},
2031 {DISPID_GLOBAL_RANDOMIZE
, Global_Randomize
, 0, 1},
2032 {DISPID_GLOBAL_RND
, Global_Rnd
, 0, 1},
2033 {DISPID_GLOBAL_TIMER
, Global_Timer
, 0, 0},
2034 {DISPID_GLOBAL_LBOUND
, Global_LBound
, 0, 1},
2035 {DISPID_GLOBAL_UBOUND
, Global_UBound
, 0, 1},
2036 {DISPID_GLOBAL_RGB
, Global_RGB
, 0, 3},
2037 {DISPID_GLOBAL_LEN
, Global_Len
, 0, 1},
2038 {DISPID_GLOBAL_LENB
, Global_LenB
, 0, 1},
2039 {DISPID_GLOBAL_LEFT
, Global_Left
, 0, 2},
2040 {DISPID_GLOBAL_LEFTB
, Global_LeftB
, 0, 2},
2041 {DISPID_GLOBAL_RIGHT
, Global_Right
, 0, 2},
2042 {DISPID_GLOBAL_RIGHTB
, Global_RightB
, 0, 2},
2043 {DISPID_GLOBAL_MID
, Global_Mid
, 0, 2, 3},
2044 {DISPID_GLOBAL_MIDB
, Global_MidB
, 0, 2, 3},
2045 {DISPID_GLOBAL_STRCOMP
, Global_StrComp
, 0, 2, 3},
2046 {DISPID_GLOBAL_LCASE
, Global_LCase
, 0, 1},
2047 {DISPID_GLOBAL_UCASE
, Global_UCase
, 0, 1},
2048 {DISPID_GLOBAL_LTRIM
, Global_LTrim
, 0, 1},
2049 {DISPID_GLOBAL_RTRIM
, Global_RTrim
, 0, 1},
2050 {DISPID_GLOBAL_TRIM
, Global_Trim
, 0, 1},
2051 {DISPID_GLOBAL_SPACE
, Global_Space
, 0, 1},
2052 {DISPID_GLOBAL_STRING
, Global_String
, 0, 0, 2},
2053 {DISPID_GLOBAL_INSTR
, Global_InStr
, 0, 2, 4},
2054 {DISPID_GLOBAL_INSTRB
, Global_InStrB
, 0, 3, 4},
2055 {DISPID_GLOBAL_ASCB
, Global_AscB
, 0, 1},
2056 {DISPID_GLOBAL_CHRB
, Global_ChrB
, 0, 1},
2057 {DISPID_GLOBAL_ASC
, Global_Asc
, 0, 1},
2058 {DISPID_GLOBAL_CHR
, Global_Chr
, 0, 1},
2059 {DISPID_GLOBAL_ASCW
, Global_AscW
, 0, 1},
2060 {DISPID_GLOBAL_CHRW
, Global_ChrW
, 0, 1},
2061 {DISPID_GLOBAL_ABS
, Global_Abs
, 0, 1},
2062 {DISPID_GLOBAL_FIX
, Global_Fix
, 0, 1},
2063 {DISPID_GLOBAL_INT
, Global_Int
, 0, 1},
2064 {DISPID_GLOBAL_SGN
, Global_Sgn
, 0, 1},
2065 {DISPID_GLOBAL_NOW
, Global_Now
, 0, 0},
2066 {DISPID_GLOBAL_DATE
, Global_Date
, 0, 0},
2067 {DISPID_GLOBAL_TIME
, Global_Time
, 0, 0},
2068 {DISPID_GLOBAL_DAY
, Global_Day
, 0, 1},
2069 {DISPID_GLOBAL_MONTH
, Global_Month
, 0, 1},
2070 {DISPID_GLOBAL_WEEKDAY
, Global_Weekday
, 0, 1, 2},
2071 {DISPID_GLOBAL_YEAR
, Global_Year
, 0, 1},
2072 {DISPID_GLOBAL_HOUR
, Global_Hour
, 0, 1},
2073 {DISPID_GLOBAL_MINUTE
, Global_Minute
, 0, 1},
2074 {DISPID_GLOBAL_SECOND
, Global_Second
, 0, 1},
2075 {DISPID_GLOBAL_DATEVALUE
, Global_DateValue
, 0, 1},
2076 {DISPID_GLOBAL_TIMEVALUE
, Global_TimeValue
, 0, 1},
2077 {DISPID_GLOBAL_DATESERIAL
, Global_DateSerial
, 0, 3},
2078 {DISPID_GLOBAL_TIMESERIAL
, Global_TimeSerial
, 0, 3},
2079 {DISPID_GLOBAL_INPUTBOX
, Global_InputBox
, 0, 1, 7},
2080 {DISPID_GLOBAL_MSGBOX
, Global_MsgBox
, 0, 1, 5},
2081 {DISPID_GLOBAL_CREATEOBJECT
, Global_CreateObject
, 0, 1},
2082 {DISPID_GLOBAL_GETOBJECT
, Global_GetObject
, 0, 0, 2},
2083 {DISPID_GLOBAL_DATEADD
, Global_DateAdd
, 0, 3},
2084 {DISPID_GLOBAL_DATEDIFF
, Global_DateDiff
, 0, 3, 5},
2085 {DISPID_GLOBAL_DATEPART
, Global_DatePart
, 0, 2, 4},
2086 {DISPID_GLOBAL_TYPENAME
, Global_TypeName
, 0, 1},
2087 {DISPID_GLOBAL_ARRAY
, Global_Array
, 0, 1},
2088 {DISPID_GLOBAL_ERASE
, Global_Erase
, 0, 1},
2089 {DISPID_GLOBAL_FILTER
, Global_Filter
, 0, 2, 4},
2090 {DISPID_GLOBAL_JOIN
, Global_Join
, 0, 1, 2},
2091 {DISPID_GLOBAL_SPLIT
, Global_Split
, 0, 1, 4},
2092 {DISPID_GLOBAL_REPLACE
, Global_Replace
, 0, 3, 6},
2093 {DISPID_GLOBAL_STRREVERSE
, Global_StrReverse
, 0, 1},
2094 {DISPID_GLOBAL_INSTRREV
, Global_InStrRev
, 0, 2, 4},
2095 {DISPID_GLOBAL_LOADPICTURE
, Global_LoadPicture
, 0, 1},
2096 {DISPID_GLOBAL_SCRIPTENGINE
, Global_ScriptEngine
, 0, 0},
2097 {DISPID_GLOBAL_SCRIPTENGINEMAJORVERSION
, Global_ScriptEngineMajorVersion
, 0, 0},
2098 {DISPID_GLOBAL_SCRIPTENGINEMINORVERSION
, Global_ScriptEngineMinorVersion
, 0, 0},
2099 {DISPID_GLOBAL_SCRIPTENGINEBUILDVERSION
, Global_ScriptEngineBuildVersion
, 0, 0},
2100 {DISPID_GLOBAL_FORMATNUMBER
, Global_FormatNumber
, 0, 1, 5},
2101 {DISPID_GLOBAL_FORMATCURRENCY
, Global_FormatCurrency
, 0, 1, 5},
2102 {DISPID_GLOBAL_FORMATPERCENT
, Global_FormatPercent
, 0, 1, 5},
2103 {DISPID_GLOBAL_FORMATDATETIME
, Global_FormatDateTime
, 0, 1, 2},
2104 {DISPID_GLOBAL_WEEKDAYNAME
, Global_WeekdayName
, 0, 1, 3},
2105 {DISPID_GLOBAL_MONTHNAME
, Global_MonthName
, 0, 1, 2},
2106 {DISPID_GLOBAL_ROUND
, Global_Round
, 0, 1, 2},
2107 {DISPID_GLOBAL_ESCAPE
, Global_Escape
, 0, 1},
2108 {DISPID_GLOBAL_UNESCAPE
, Global_Unescape
, 0, 1},
2109 {DISPID_GLOBAL_EVAL
, Global_Eval
, 0, 1},
2110 {DISPID_GLOBAL_EXECUTE
, Global_Execute
, 0, 1},
2111 {DISPID_GLOBAL_EXECUTEGLOBAL
, Global_ExecuteGlobal
, 0, 1},
2112 {DISPID_GLOBAL_GETREF
, Global_GetRef
, 0, 1},
2113 {DISPID_GLOBAL_VBMSGBOXHELPBUTTON
, NULL
, BP_GET
, VT_I4
, MB_HELP
},
2114 {DISPID_GLOBAL_VBMSGBOXSETFOREGROUND
, NULL
, BP_GET
, VT_I4
, MB_SETFOREGROUND
},
2115 {DISPID_GLOBAL_VBMSGBOXRIGHT
, NULL
, BP_GET
, VT_I4
, MB_RIGHT
},
2116 {DISPID_GLOBAL_VBMSGBOXRTLREADING
, NULL
, BP_GET
, VT_I4
, MB_RTLREADING
}
2119 static HRESULT
Err_Description(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2125 static HRESULT
Err_HelpContext(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2131 static HRESULT
Err_HelpFile(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2137 static HRESULT
Err_Number(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2144 return E_UNEXPECTED
;
2147 FIXME("setter not implemented\n");
2151 hres
= This
->desc
->ctx
->err_number
;
2152 return return_int(res
, HRESULT_FACILITY(hres
) == FACILITY_VBS
? HRESULT_CODE(hres
) : hres
);
2155 static HRESULT
Err_Source(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2161 static HRESULT
Err_Clear(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2166 return E_UNEXPECTED
;
2168 This
->desc
->ctx
->err_number
= S_OK
;
2172 static HRESULT
Err_Raise(vbdisp_t
*This
, VARIANT
*args
, unsigned args_cnt
, VARIANT
*res
)
2178 static const builtin_prop_t err_props
[] = {
2179 {DISPID_ERR_DESCRIPTION
, Err_Description
, BP_GETPUT
},
2180 {DISPID_ERR_HELPCONTEXT
, Err_HelpContext
, BP_GETPUT
},
2181 {DISPID_ERR_HELPFILE
, Err_HelpFile
, BP_GETPUT
},
2182 {DISPID_ERR_NUMBER
, Err_Number
, BP_GETPUT
},
2183 {DISPID_ERR_SOURCE
, Err_Source
, BP_GETPUT
},
2184 {DISPID_ERR_CLEAR
, Err_Clear
},
2185 {DISPID_ERR_RAISE
, Err_Raise
, 0, 5},
2188 HRESULT
init_global(script_ctx_t
*ctx
)
2192 ctx
->global_desc
.ctx
= ctx
;
2193 ctx
->global_desc
.builtin_prop_cnt
= sizeof(global_props
)/sizeof(*global_props
);
2194 ctx
->global_desc
.builtin_props
= global_props
;
2196 hres
= get_typeinfo(GlobalObj_tid
, &ctx
->global_desc
.typeinfo
);
2200 hres
= create_vbdisp(&ctx
->global_desc
, &ctx
->global_obj
);
2204 hres
= create_script_disp(ctx
, &ctx
->script_obj
);
2208 ctx
->err_desc
.ctx
= ctx
;
2209 ctx
->err_desc
.builtin_prop_cnt
= sizeof(err_props
)/sizeof(*err_props
);
2210 ctx
->err_desc
.builtin_props
= err_props
;
2212 hres
= get_typeinfo(ErrObj_tid
, &ctx
->err_desc
.typeinfo
);
2216 return create_vbdisp(&ctx
->err_desc
, &ctx
->err_obj
);