Jump to content

Is there a reason ConsoleWrite converts everything to ANSI and doesn't support Unicode?


VAN0
 Share

Recommended Posts

I guess it's for historic reasons.

BTW, I use my function CW() instead, which works in compiled programs as well:

Func CW($s = "")
    If @Compiled Then
        _CUI_ConsoleWrite($s)
    Else
        _ConsoleWrite($s)
    EndIf
EndFunc   ;==>CW


Func _CUI_ConsoleWrite(ByRef $s)
    Local Static $hDll = DllOpen("kernel32.dll")
    Local Static $hCon = __CUI_ConsoleInit($hDll)
    DllCall($hDll, "bool", "WriteConsoleW", "handle", $hCon, "wstr", $s & @LF, "dword", StringLen($s) + 1, "dword*", 0, "ptr", 0)
    Return
EndFunc   ;==>_CUI_ConsoleWrite


; internal use only
Func __CUI_ConsoleInit(ByRef $hDll)
    DllCall($hDll, "bool", "AllocConsole")
    Return DllCall($hDll, "handle", "GetStdHandle", "int", -11)[0]
EndFunc   ;==>__CUI_ConsoleInit


; Unicode-aware ConsoleWrite
Func _ConsoleWrite(ByRef $s)
    ConsoleWrite(BinaryToString(StringToBinary($s & @LF, 4), 1))
EndFunc   ;==>_ConsoleWrite

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

$s = BinaryToString(StringToBinary(ChrW(0x2705), $SB_UTF8), $SB_UTF8)
CW($s)

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

OK, so my console writes this

>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\AutoIt\unicode\write_unicode.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
✅
+>08:45:57 AutoIt3.exe ended.rc:0
+>08:45:57 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.032

Now I am guessing that the console output and file EXE may display different results...

 

So (a) should I change the Console output? Or should I just test with display (like in msgbox)

My Msgbox displays 0

MsgBox(0,"Unicode",CW($s))

 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

To display Unicode in the Scite console you need to switch it to UTF8 and select a Unicode-aware display font. I recommend DéjàVu Sans Mono: it's very unambiguous and covers a fair part of Unicode. No available font covers all of Unicode!

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • 2 years later...

How can another program executed by the compiled script change the script's output into proper UTF8 encoding?

For example using magick.exe from this package

#AutoIt3Wrapper_Change2CUI=y

Local $s = ChrW(0x2190) & @LF

ConsoleWrite(BinaryToString(StringToBinary("Before " & $s, 4), 1))

Local $iPID = Run("magick.exe", "", @SW_HIDE, 8)
If @error Then ConsoleWrite("error")
While ProcessExists($iPID)
WEnd

ConsoleWrite(BinaryToString(StringToBinary("After  " & $s, 4), 1))

; leave window open
sleep(5000)

I'm getting:

image.png.86ef5d491f18b4a960da1dca98f5e9d3.png

Link to comment
Share on other sites

I don't know why. It would take to dig inside the source code to find the answer, or maybe ask on their support forum (if any).

None of the win64 versions installs correctly here.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

11 hours ago, VAN0 said:

How can another program executed by the compiled script change the script's output into proper UTF8 encoding?

Not sure how CMD works but *nix terminals support "terminal codes" which can change the behaviour of the terminal... something like changing the terminal's text interpreter's encoding option ;)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...