News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

wprintf

Started by Magnum, January 30, 2011, 12:19:39 PM

Previous topic - Next topic

FORTRANS

Hi,

QuoteUncertain is why it works when I assemble & link & run it from RichMasm or when I run it from a DOS prompt, but not from Explorer or from Start Run...

   Not sure if this is relevant, but in reading a newsgroup, a
thread was discussing something similar.  The environment
was inherited from the command processor when started
from the command line.  But when started with a START
command, or some other ways, the environment, including
file handles, were different.  So querying the environments
might show what is different?

Regards,

Steve

jj2007

Quote from: Magnum on January 30, 2011, 10:02:09 PM
I would like to enter some Korean text and send in via email.

Korean doesn't work on my system. Chinese, Thai, Japanese yes, Korean no...

Antariy

Quote from: jj2007 on January 30, 2011, 04:05:17 PM
Quote from: dedndave on January 30, 2011, 03:38:08 PM
Jochen - i think, in a console window, you have to select a code page
try the dos CHCP command
there is a way to do it in the environment table, too - if you want it to be permanent

Dave, I have tested dozens already... crt_printf just prints an empty string for anything that is not plain abc. Win XP consoles don't like Russian, Chinese and other exotic characters.

MSVCRT converts Unicode text to ASCII before output to console for simpler and unified console/file output.

Try to do:

invoke crt__setmbcp,CodePage


before output.

Still, this will limit output by one extended ASCII language.

For Russian, CodePage is: 1251

jj2007

Quote from: Antariy on January 30, 2011, 11:41:29 PM
For Russian, CodePage is: 1251

Alex,

Russian prints fine with CodePage CP_UTF8 (65001). The other languages behave a bit erratically, although they do work from the cmd DOS prompt.

Antariy

Quote from: jj2007 on January 30, 2011, 11:54:15 PM
Quote from: Antariy on January 30, 2011, 11:41:29 PM
For Russian, CodePage is: 1251

Alex,

Russian prints fine with CodePage CP_UTF8 (65001). The other languages behave a bit erratically, although they do work from the cmd DOS prompt.

How about UTF7 (65000) ? That's joke :lol

jj2007

Quote from: Antariy on January 30, 2011, 11:59:47 PM
How about UTF7 (65000) ? That's joke :lol

Why joke? It works, actually, likewise 1200 and 1201. This is because a true Unicode (2-byte) strings gets translated to a "multibyte" string that WriteConsoleA can interpret.

Other codepages work partially, for Russian only.

The source is included in reply #12 (you have the MB package, I suppose).

GregL

I'm no expert in this area, but don't you have to set the correct CodePage and the correct font for the language you want to display.  They will be different for each language.

Some relevant links:

Keep your eye on the code page

Why are console windows limited to Lucida Console and raster fonts?

Consolas can also be used for the console font. It first came with Windows Vista.



Antariy

Quote from: jj2007 on January 31, 2011, 07:49:57 AM
Quote from: Antariy on January 30, 2011, 11:59:47 PM
How about UTF7 (65000) ? That's joke :lol

Why joke? It works, actually, likewise 1200 and 1201. This is because a true Unicode (2-byte) strings gets translated to a "multibyte" string that WriteConsoleA can interpret.

Other codepages work partially, for Russian only.

The source is included in reply #12 (you have the MB package, I suppose).

Actually "codepages" 1200 and 1201 does not exist. This is just "shortcut name", but you'll not find codapage file with encoding table for these sets. The same as UTF8 - it is just conversion from Unicode UTF-16 (UCS2) (there is some simple rules).

redskull

Quote from: jj2007 on January 30, 2011, 09:57:35 PMUncertain is why it works when I assemble & link & run it from RichMasm or when I run it from a DOS prompt, but not from Explorer or from Start Run...

This problem vexes me... I wish i could reproduce the problem, but am having no luck (now, or before in the previous thread).  Whether running from the shell or cmd.exe, i get the same results every time (English, Russian?, Arabic, Boxes, using DejaVu sans Mono).  I really think the weak link in the chain is the actual font that you use, and not the function, but as of now I have nothing to back it up.  What is the copy/paste behavior?  When I mark/copy and paste into notepad++ (with encoding set to UTF-8), i see all perfectly, and the boxes change to asian.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Red,

Have you tried the Feb 1 build of MB? Test this snippet with the attached resource file...
I see Russian, Arabic and Chinese:
Test: Введите текст  здесь
Test: أدخل النص هنا
Test: 在這裡輸入文字


Quoteinclude \masm32\MasmBasic\MasmBasic.inc
   
Init [/color]
   wPrint wChr$("Test: "), wRes$(401), wCrLf$
   wPrint wChr$("Test: "), wRes$(801), wCrLf$
   wInkey wChr$("Test: "), wRes$(1201)
   
Exit
end start

dedndave

#25




the attachment is the above image

hutch--

All 3 languages show up OK here. I keep the east asian fonts loaded.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

Quoteimage.zip (1.79 KB - downloaded 17 times.)

:lol

jj2007

Quote from: redskull on February 02, 2011, 02:38:03 AM
This problem vexes me...

Red,

To give you one more element: The first wPrint invokes SetConsoleOutputCP, CP_UTF8 (no surprise) and SetConsoleTextAttribute. Without the latter call, Russian displays fine but Arabic and Chinese don't...

@Dave & Hutch: Thanks for your feedback!

dgkimpton

What do you mean by an Assembly equivalent?

I just invoke WSPrintF directly... only trick is to explicitly call the unicode version by appending W to it.


.586
.model flat, stdcall   
option casemap :none   

; To get unicode support
include \masm32\macros\ucmacros.asm

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

wsprintfW PROTO C :VARARG

.data
WSTR FormatString, "Some String with a number"
ptrFinalString dd 0

.code
main:

; Make space
invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, 1024; 1024 is enough bytes I think for this example
mov ptrFinalString, eax

; Sprintf
invoke wsprintfW, ptrFinalString, ADDR FormatString, DWORD PTR [eax]

; Show result
invoke MessageBoxW, NULL, ptrFinalString, ptrFinalString, MB_OK

invoke ExitProcess, 0
end main