Index: Include/basic/function.sbp
===================================================================
--- Include/basic/function.sbp	(revision 119)
+++ Include/basic/function.sbp	(revision 121)
@@ -290,5 +290,5 @@
 End Function
 
-Function IsNaN(ByVal x As Double) As BOOL
+Function IsNaN(ByVal x As Double) As Boolean
 	Dim p As *DWord
 	p = VarPtr(x) As *DWord
@@ -296,5 +296,5 @@
 	If (p[1] And &H7FF00000) = &H7FF00000 Then
 		If (p[0] <> 0) Or ((p[1] And &HFFFFF) <> 0) Then
-			IsNaN = TRUE
+			IsNaN = True
 		End If
 	End If
@@ -303,5 +303,5 @@
 End Function
 
-Function IsInf(x As Double) As BOOL
+Function IsInf(x As Double) As Boolean
 	Dim p As *DWord, nan As Double
 	p = VarPtr(x) As *DWord
@@ -311,9 +311,9 @@
 End Function
 
-Function IsNaNOrInf(x As Double) As BOOL
+Function IsNaNOrInf(x As Double) As Boolean
 	IsNaNOrInf = IsFinite(x)
 End Function
 
-Function IsFinite(x As Double) As BOOL
+Function IsFinite(x As Double) As Boolean
 	Dim p As *DWord, nan As Double
 	p = VarPtr(x) As *DWord
@@ -322,5 +322,5 @@
 	p[0] = 0
 	nan = _System_GetInf(/*x,*/ FALSE)
-	IsNaNOrInf = (memcmp(p As BytePtr, VarPtr(nan), SizeOf (Double)) = 0)
+	IsFinite = (memcmp(p As BytePtr, VarPtr(nan), SizeOf (Double)) = 0)
 End Function
 
@@ -349,11 +349,37 @@
 
 Function Chr$(code As Char) As String
-	Chr$=ZeroString(1)
-	Chr$[0]=code
-End Function
+	Chr$ = ZeroString(1)
+	Chr$[0] = code
+End Function
+
+#ifdef UNICODE
+Function AscW(s As String) As UCSCHAR
+	If s.Length = 0 Then
+		AscW = 0
+	Else
+		If _System_IsSurrogatePair(s[0], s[1]) Then
+			AscW = ((s[0] And &h3FF) As DWord << 10) Or (s[1] And &h3FF)
+		Else
+			AscW = s[0]
+		End If
+	End If
+End Function
+
+Function ChrW(c As UCSCHAR) As String
+	If c <= &hFFFF Then
+		ChrW.ReSize(1)
+		ChrW[0] = c As WCHAR
+	ElseIf c < &h10FFFF Then
+		ChrW.ReSize(2)
+		ChrW[0] = &hD800 Or (c >> 10)
+		ChrW[1] = &hDC00 Or (c And &h3FF)
+	Else
+		' OutOfRangeException
+	End If
+End Function
+#endif
 
 Function Date$() As String
 	Dim st As SYSTEMTIME
-
 	GetLocalTime(st)
 
@@ -378,16 +404,22 @@
 End Function
 
-Function Hex$(num As DWord) As String
-	Dim length As Long
-	Hex$=ZeroString(8)
-	length=wsprintf(Hex$, "%X", num)
-	Hex$=Left$(Hex$,length)
-End Function
-
-Function Hex$(num As QWord) As String
-	Dim length As Long
-	Hex$=ZeroString(16)
-	length=wsprintf(Hex$, "%X%X", num)
-	Hex$=Left$(Hex$,length)
+Dim _System_HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
+
+Function Hex$(x As DWord) As String
+	Dim i = 0
+	Hex$ = ZeroString(8)
+	While (x And &hf0000000) = 0
+		x <<= 4
+	Wend
+	While x <> 0
+		Hex$[i] = _System_HexadecimalTable[(x And &hf0000000) >> 28] As Char
+		x <<= 4
+		i++
+	Wend
+	Hex$.ReSize(i)
+End Function
+
+Function Hex$(x As QWord) As String
+	Hex$ = Hex$((x >> 32) As DWord) + Hex$((x And &hffffffff) As DWord)
 End Function
 
@@ -429,9 +461,6 @@
 
 Function Left$(buf As String, length As Long) As String
-	Left$=ZeroString(length)
-	memcpy(
-		StrPtr(Left$),
-		StrPtr(buf),
-		length)
+	Left$ = ZeroString(length)
+	memcpy(StrPtr(Left$), StrPtr(buf), SizeOf (Char) * length)
 End Function
 
@@ -458,5 +487,5 @@
 
 	Mid$=ZeroString(ReadLength)
-	memcpy(StrPtr(Mid$),StrPtr(buf)+StartPos,ReadLength)
+	memcpy(StrPtr(Mid$), VarPtr(buf[StartPos]), SizeOf (Char) * ReadLength)
 End Function
 
@@ -486,5 +515,5 @@
 	If i>length Then
 		Right$=ZeroString(length)
-		memcpy(StrPtr(Right$),StrPtr(buf)+i-length,length)
+		memcpy(StrPtr(Right$), VarPtr(buf[i-length]), SizeOf (Char) * length)
 	Else
 		Right$=buf
@@ -665,6 +694,10 @@
 Function Str$(value As LONG_PTR) As String
 	Dim temp[255] As Char
-	wsprintf(temp,"%d",value)
-	Str$=MakeStr(temp)
+#ifdef _WIN64
+	_sntprintf(temp, Len (temp) / SizeOf (Char), "%I64d", value)
+#else
+	_sntprintf(temp, Len (temp) / SizeOf (Char), "%d", value)
+#endif
+	Str$ = temp
 End Function
 
@@ -681,5 +714,5 @@
 	Dim i As Long
 	For i=0 To num-1
-		memcpy(StrPtr(String$)+i*length,StrPtr(buf),length)
+		memcpy(VarPtr(String$[i*length]),StrPtr(buf),SizeOf (Char) * length)
 	Next
 End Function
@@ -727,6 +760,5 @@
 
 	If buf[0]=Asc("&") Then
-		temporary=ZeroString(lstrlen(buf))
-		lstrcpy(temporary,buf)
+		temporary=buf
 		TempPtr=StrPtr(temporary)
 		CharUpper(TempPtr)
