Ticket #3896: Bug in BinaryToString for single non-ANSI character.au3

File Bug in BinaryToString for single non-ANSI character.au3, 2.1 KB (added by anonymous, 2 years ago)
Line 
1#include <WinAPIConv.au3>
2
3;~ Global Const $CP = 0 ; CP_ACP default copepage
4;~ Global Const $CP = GetACP() ; current codeoage
5;~ Global Const $CP = 65001 ; UTF-8 certainly the best value
6Global Const $CP = 65001 ; CP_SHIFT_JIS
7
8Local $sText = 0x99c599c5
9$a = BinaryToString($sText,4)
10ConsoleWrite(StringLen($a))
11FileWrite("wkdfb.txt",$a)
12MsgBox(0,"",$a)
13Exit
14Local $sOutput = @TAB & @TAB & "Copepage =" & $CP & @CRLF & @CRLF
15$sOutput &= @TAB & "String[" & StringLen($sText) & "] = " & $sText & @CRLF & @CRLF
16
17; ============== _WinAPI_WideCharToMultiByte Test ==============
18
19Local $sTest = _WinAPI_WideCharToMultiByte($sText, $CP, True, False)
20$sOutput &= "WideChar to String (MultiByte)" & @TAB & VarGetType($sTest) & " " & StringLen($sTest) & " :" & @CRLF & $sTest & @CRLF & @CRLF
21
22$sTest = _WinAPI_WideCharToMultiByte($sText, $CP, True, True)
23$sOutput &= "WideChar to Binary" & @TAB & VarGetType($sTest) & " " & BinaryLen($sTest) & " :" & @CRLF & $sTest & @CRLF & @CRLF
24
25; ============== _WinAPI_MultiByteToWideChar Test ==============
26
27Local $sMultiByte = _WinAPI_WideCharToMultiByte($sText, $CP, True, False)
28$sOutput &= @CRLF & @TAB & "MultiByte[" & StringLen($sMultiByte) & "] = " & $sMultiByte & @CRLF & @CRLF
29
30Local $tStruct = _WinAPI_MultiByteToWideChar($sMultiByte, $CP, 0, False)
31$sOutput &= "MultiByte to Struct" & @TAB & @TAB & VarGetType($tStruct) & " " & DllStructGetSize($tStruct) & " :" & @CRLF & DllStructGetData($tStruct, 1) & @CRLF & @CRLF
32
33$sTest = _WinAPI_MultiByteToWideChar($sMultiByte, $CP, 0, True)
34$sOutput &= "MultiByte to String" & @TAB & VarGetType($sTest) & " " & StringLen($sTest) & " :" & @CRLF & $sTest & @CRLF & @CRLF
35
36Local $iMB_TYPE = 0
37If $sTest == $sText Then
38        $sOutput &= @CRLF & @TAB & @TAB & "Conversion OK"
39Else
40        $sOutput &= @CRLF & @TAB & @TAB & " !!! Erreur de Conversion !!!"
41        $iMB_TYPE = $MB_ICONERROR
42EndIf
43
44MsgBox($MB_SYSTEMMODAL + $iMB_TYPE, "Results", $sOutput)
45
46Func GetACP()
47        Local $aResult = DllCall("kernel32.dll", "int", "GetACP")
48        If @error Or Not $aResult[0] Then Return SetError(@error + 20, @extended, "")
49        Return $aResult[0]
50EndFunc   ;==>GetACP