flat assembler
Message board for the users of flat assembler.

Index > Windows > How do I print unicode string using printf

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Flier-Mate



Joined: 26 May 2023
Posts: 88
Flier-Mate 10 Jun 2023, 09:28
Thanks for the file, bitRAKE.

So it confirms that only Windows 11 is able to display multi-lingual string in UTF-8 codepage. Mine is Windows 10 and only Greek is OK.

I have to shut down my Windows Defender or else it refused to download your attachment.

Another user from local forum reports "works fine with Windows termincal, fonts cascadia mono, lucida console" to display Hindi on his/her Windows 11 (Windows 10.0.22631.1830). So I think font rendering in Windows 11 is automatic.


Description: Output of multi-lingual string on my Windows 10 console
Filesize: 7.85 KB
Viewed: 1561 Time(s)

Screenshot 2023-06-10 172412.png


Description:
Filesize: 2.35 KB
Viewed: 1561 Time(s)

Screenshot 2023-06-10 170854.png


Post 10 Jun 2023, 09:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20210
Location: In your JS exploiting you and your system
revolution 10 Jun 2023, 10:18
Your screenshot shows it working fine, with the only issue that your chosen font doesn't have the glyphs to render the characters. Those squares are what most font renderers will show when the glyph isn't found in the font.

Win7 could do this when you have the right font available, so I see no reason that Win10 can't. All you need to do is choose a different font with the glyphs you use.
Post 10 Jun 2023, 10:18
View user's profile Send private message Visit poster's website Reply with quote
moistMaven



Joined: 02 Jun 2023
Posts: 9
moistMaven 11 Jun 2023, 10:36
Flier-Mate wrote:
I use the same code that I posted above, but no luck seeing Hindi characters in my Windows 10 console.

I typed "chcp 65001" then run hindi.exe , a program that uses WriteConsoleW API function.

Does anybody know why?


Setting the Code Pages inside of assembly works but not directly in console, I don't know why?
Code:
format PE console 
entry start

include "win32a.inc"
include "encoding\utf8.inc"

section ".data" data readable writeable

hindi du "हिन्दी",13,10,0
_len  = $ - hindi

section ".code" code executable readable

start:
ccall   [SetConsoleOutputCP], 65001
push -11
call [GetStdHandle]
push 0
push 0
push _len
push hindi
push eax
call [WriteConsoleW]



push 0
call [ExitProcess]

;====================================
section '.idata' import data readable
;====================================

library kernel,'kernel32.dll',        msvcrt,'msvcrt.dll'

import  kernel,      SetConsoleOutputCP, 'SetConsoleOutputCP', \
              GetStdHandle, "GetStdHandle", \
       WriteConsoleW, "WriteConsoleW", \
       ExitProcess, "ExitProcess"

import  msvcrt,        printf,'printf',        getchar,'_fgetchar'
    
Post 11 Jun 2023, 10:36
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3976
Location: vpcmipstrm
bitRAKE 11 Jun 2023, 12:36
Code:
include "encoding\utf8.inc"    
... the encoding file determines how fasm[g] interprets bytes when forming WCHAR characters and defines macros for DU type string composed of WCHARs.

Which is completely unrelated to SetConsoleOutputCP.
Microsoft wrote:
UTF-8 formatted text can be sent to the A family of console APIs after ensuring the code page is first set to 65001 (CP_UTF8) with the SetConsoleCP and SetConsoleOutputCP functions.
... setting the code page has no effect when using the W family of console APIs.

Using include "encoding\utf8.inc" is not needed when using the A family of console APIs with UTF-8 encoding characters.

They are mutually exclusive. Either one is sending bytes to the A family of console APIs with UTF-8 encoding characters, or one is sending WCHARs to the W family of console APIs.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 11 Jun 2023, 12:36
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.