Problem with console output when I switched to unicode version Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
yenom
Posts: 3
Joined: 23 Jun 2017, 10:59

Problem with console output when I switched to unicode version

23 Jun 2017, 11:59

I am using these 2 function for debugging my script. When I switched to unicode version It started producing output with spaces after every char. For example instead of HELLO i would get H E L L O. In debug.txt which is another output it is ok. Any way to fix it?

Code: Select all

DebugMessage(tag, str)
{
 global h_stdout, DebugFile, DebugShow, debug

 DebugConsoleInitialize()  ; start console window if not yet started
 if instr(DebugShow, tag) && debug
{
 str .= "`n" ; add line feed
 FileAppend, %str%, debug.txt
 ;FileAppend, %line%`n, debug.txt
 DllCall("WriteFile", "uint", h_Stdout, "uint", &str, "uint", StrLen(str), "uint*", BytesWritten, "uint", NULL) ; write into the console
}
 WinSet, Bottom,, ahk_id %h_stout%  ; keep console on bottom
}

DebugConsoleInitialize()
{
   global h_Stdout     ; Handle for console
   static is_open = 0  ; toogle whether opened before
   if (is_open = 1)     ; yes, so don't open again
     return
	 
   is_open := 1	
   ; two calls to open, no error check (it's debug, so you know what you are doing)
   DllCall("AttachConsole", int, -1, int)
   DllCall("AllocConsole", int)

   dllcall("SetConsoleTitle", "str","Paddy Debug Console")    ; Set the name. Example. Probably could use a_scriptname here 
   h_Stdout := DllCall("GetStdHandle", "int", -11) ; get the handle
   WinSet, Bottom,, ahk_id %h_stout%      ; make sure it's on the bottom

      WinMove, ahk_id %h_stout% , , , , -800, 800 ;, %cwidth%, %cheight%
   WinActivate,Lightroom   ; Application specific; I need to make sure this application is running in the foreground. YMMV
  
   return
}
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Problem with console output when I switched to unicode version  Topic is solved

24 Jun 2017, 03:19

You are writing UTF-16 data now instead of the ANSI (8-bit) text expected by the console.

You can do this:
  1. Replace WriteFile with FileAppend % str, *
  2. Remove GetStdHandle and h_stdout. You don't need them anymore.
To get Unicode you can call DllCall("SetConsoleOutputCP", "uint", 65001) and use FileAppend % str, *, UTF-8, but you must also use an appropriate font.
yenom
Posts: 3
Joined: 23 Jun 2017, 10:59

Re: Problem with console output when I switched to unicode version

24 Jun 2017, 17:55

Thank you lexikos!

I did only this and it solved the problem
You can do this:
Replace WriteFile with FileAppend % str, *
Remove GetStdHandle and h_stdout. You don't need them anymore.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk, Spawnova, toddhere, USS_Sandhu and 303 guests