Maps a character string to a wide-character (Unicode) string
#include <WinAPIConv.au3>
_WinAPI_MultiByteToWideChar ( $vText [, $iCodePage = 0 [, $iFlags = 0 [, $bRetString = False]]] )
$vText | Text or DllStruct containing multibyte text to be converted |
$iCodePage | [optional] Specifies the code page to be used to perform the conversion: 0 - ANSI code page 1 - OEM code page 2 - Macintosh code page 3 - The Windows ANSI code page for the current thread 42 - Symbol code page 65000 - UTF-7 65001 - UTF-8 |
$iFlags | [optional] Flags that indicate whether to translate to precomposed or composite wide characters: $MB_PRECOMPOSED - Always use precomposed characters $MB_COMPOSITE - Always use composite characters $MB_USEGLYPHCHARS - Use glyph characters instead of control characters |
$bRetString | [optional] Flags that indicate whether to return a String or a DllStruct (default False : Structure) |
Success: | String or DllStruct that contains the Unicode character string |
Failure: | Sets the @error flag to non-zero, call _WinAPI_GetLastError() to get extended error information |
No conversion of $vText to String will be done, the function will fail with @error = 1.
_WinAPI_MultiByteToWideCharEx, _WinAPI_WideCharToMultiByte
Search MultiByteToWideChar in MSDN Library.
#include <WinAPIConv.au3>
;~ Global Const $CP = 0 ; CP_ACP default copepage
;~ Global Const $CP = GetACP() ; current codeoage
;~ Global Const $CP = 65001 ; UTF-8 certainly the best value
Global Const $CP = 932 ; CP_SHIFT_JIS
Local $sText = "データのダウンロードに失敗しました。"
;~ Local $sText = "abcdefg 1234567890"
Local $sOutput = @TAB & @TAB & "Copepage =" & $CP & @CRLF & @CRLF
$sOutput &= @TAB & "String[" & StringLen($sText) & "] = " & $sText & @CRLF & @CRLF
; ============== _WinAPI_WideCharToMultiByte Test ==============
Local $sTest = _WinAPI_WideCharToMultiByte($sText, $CP, True, False)
$sOutput &= "WideChar to String (MultiByte)" & @TAB & VarGetType($sTest) & " " & StringLen($sTest) & " :" & @CRLF & $sTest & @CRLF & @CRLF
$sTest = _WinAPI_WideCharToMultiByte($sText, $CP, True, True)
$sOutput &= "WideChar to Binary" & @TAB & VarGetType($sTest) & " " & BinaryLen($sTest) & " :" & @CRLF & $sTest & @CRLF & @CRLF
; ============== _WinAPI_MultiByteToWideChar Test ==============
Local $sMultiByte = _WinAPI_WideCharToMultiByte($sText, $CP, True, False)
$sOutput &= @CRLF & @TAB & "MultiByte[" & StringLen($sMultiByte) & "] = " & $sMultiByte & @CRLF & @CRLF
Local $tStruct = _WinAPI_MultiByteToWideChar($sMultiByte, $CP, 0, False)
$sOutput &= "MultiByte to Struct" & @TAB & @TAB & VarGetType($tStruct) & " " & DllStructGetSize($tStruct) & " :" & @CRLF & DllStructGetData($tStruct, 1) & @CRLF & @CRLF
$sTest = _WinAPI_MultiByteToWideChar($sMultiByte, $CP, 0, True)
$sOutput &= "MultiByte to String" & @TAB & VarGetType($sTest) & " " & StringLen($sTest) & " :" & @CRLF & $sTest & @CRLF & @CRLF
Local $iMB_TYPE = 0
If $sTest == $sText Then
$sOutput &= @CRLF & @TAB & @TAB & "Conversion OK"
Else
$sOutput &= @CRLF & @TAB & @TAB & " !!! Erreur de Conversion !!!"
$iMB_TYPE = $MB_ICONERROR
EndIf
MsgBox($MB_SYSTEMMODAL + $iMB_TYPE, "Results", $sOutput)
Func GetACP()
Local $aResult = DllCall("kernel32.dll", "int", "GetACP")
If @error Or Not $aResult[0] Then Return SetError(@error + 20, @extended, "")
Return $aResult[0]
EndFunc ;==>GetACP