Hi everybody interested in Console apps, especially Russians.
I'm trying to display Russian strings in my WriteConsole code.
It works fine in Win2k Russian but I have garbage caracters in other Windows (FR,German).

The other question is how to write true Unicode apps in Masm32(here I'm using Elicz macro iWin32 to get WriteConsoleW working.


extact:

Ascii2Unicode addr TextBuffer, addr szPo_Ruski, 128
iWin32@ WriteConsoleW,esi, offset TextBuffer,23,0,0
Posted on 2003-06-15 15:57:39 by Prahogi
It seems to me that you are experiencing what frustrated me in the past. You follow what PSDK says is necessary and you still don't get the result. I know the pain.

In my experience, chcp or SetConsoleCP() does not recognize all code pages installed on the system. Interestingly, they recognize some code pages (which are supposed to be installed separately but were not installed by me) as valid code pages. At that point I gave up, so I really don't have a solution to your problem.

I don't know about WinXP, but upto Win2k, Windows is not an internationalized OS, especially on console. (Don't let the NLS support in the menu fool you.) So, abandon your hope in writing an internationalized app for console. That helped improving my mental condition and hair count. :grin:


After post, it struck me that it might be a font problem in your case. Have you tried to change the font for the console window?
Posted on 2003-06-15 23:54:04 by Starless
Hi!

Why only russian? You can do the same using any national alphabet - polish, greek or arabian. You need only fresh version of fonts (because there a lot of rare using languages). Without correctly installed fonts you can do nothing.

Mike
Posted on 2003-06-16 05:22:21 by Mike
Prahogi

The console window needs to be switched to Lucinda Console font, then you can use WriteConsoleW to write any Unicode character to the console, I believe. Certainly Russian ones anyway which I have tried with English characters still coming out correctly. Using this mthod you are no longer reliant on code pages.

One problem is getting the Unicode strings in the first place, and this can be done by storing them as resources (all resource strings are stored as Unicode). However I am expanding my assembler, GoAsm, to read Unicode files (UTF-8 and UTF-16). Then you will be able to write your source code in Unicode and keep Unicode strings in the data section, which is easier than using resources.
Posted on 2003-06-16 10:16:49 by jorgon
You are right. Some problems I had in Pan European Windows'98 with russian messages. Later when I change font version all problems were disappeared. The same problems was 2 monthes ago with greek and azerbaijan languages and now OK too.

Mike
Posted on 2003-06-16 10:33:36 by Mike
Thank you for replying,guys.
It seems that there are only 2 "real solutions" to the problem":
- modify the registry keys and ask the user to reboot

for SetConsoleTitleW:


"ACP"="1251"
"OEMCP"="866"
- for WriteConsoleW ?

- write a gui replacement for cmd.exe and
subclass all windows and send them WM_SETFONT message.
I use this proc, made out of masm32 MakeFont


MakeRussianFont proc hgt:DWORD,wid:DWORD,weight:DWORD,italic:DWORD,lpFontName:DWORD

invoke CreateFont,hgt,wid,NULL,NULL,weight,italic,NULL,NULL,
RUSSIAN_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,DEFAULT_PITCH or FF_DONTCARE,
lpFontName
ret

MakeFont endp


Does anyone knows how to Apply Registry Changes without rebooting Windows ?
Posted on 2003-06-17 15:40:43 by Prahogi


- write a gui replacement for cmd.exe and
subclass all windows and send them WM_SETFONT message.


You mean, console window, not cmd.exe itself, right? If so, this approach works only for NT series, but not for 9x series. And, for NT series, there is an implementation of such idea: "Console". Last time I saw it, it was at sourceforge.net. It's written in C++, but may have some helpful hints.
Posted on 2003-06-18 00:48:26 by Starless
>Starless

Good idea about console project at sourceforge, I'll study it. Here is the link :
http://www.asmcommunity.net/board/showthread.php?postid=107189.msg107189

>Jeremy Gordon

(First of all, your assembler looks very proffessionnel, please don't stop working on it ! )


I like the trick for setting the font to Lucida Console but I have at least 2 questions:

- How to do it in code (It's not likely that console apps accept WM_SETFONT message, do they ?!)

- I don't want to go for the Unicode in Ressource tip. I'd prefer converting it at runtime via MultyBitetoWideChar,
(it makes my exe smaller)

The other question I have to ask is generaly about coding on Nt.
You stated in your GOASM tutorial that any ANSI Call on NT ends up in an Unicode version.
I can't see in Ollydbg and I'm wondering if any app that is targeted for NT(2k or XP) should use Unicode calls every time since it's the native system ?

I've recently found a way to do it in MASM32 with fodder's protoized libraries (kernel32w.lib) but I'm sure I can find a way to do it with standard MASM32 libs...
Posted on 2003-06-19 17:22:51 by Prahogi
Sorry, I don't know a way to set a console to a particular font using code. I wish I did as it would be useful for my tools. If no one on this forum knows you could try the MSDN international newsgroup

>Should any app that is targeted for NT(2k or XP) use Unicode calls every time since it's the native system ?

Well, I suppose, preferably yes, since they will run more quickly (no translation required by the system from ansi to Unicode). If you want to display non-Roman characters in NT/2000/XP without bothering with code pages, yes definitely.
Posted on 2003-06-19 17:55:21 by jorgon
It works but Cyrillic support must be installed in the control panel. I will include a c_855.nls in the RC or make it downloadable at run-time. I can't see any other option.
.386

.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\advapi32.lib
include \masm32\lib\gdi32.inc
include \masm32\include\advapi32.inc

include kernel32W.inc ;generated by fodder's protoize.exe
include user32W.inc ;generated by fodder's protoize.exe

time EQU 100
PROGRAM_IMAGE_BASE EQU 400000h

.data
TextBuffer db 128 dup (?)
Temp db 128 dup (?)
szSubkey db "Console", 0
szKeyname db "FaceName",0
szLucidaConsole db 34,"Lucida Console",34, 0
szCyrillic db "c:\winnt\system32\c_855.nls",0
szSetup db "Please install the Cyrillic support in the control panel, keyboard,regionnal settings",0
hRegKey DWORD ?
hTemp DWORD ?
.code


Main PROC

LOCAL sbi :CONSOLE_SCREEN_BUFFER_INFO
LOCAL InputBuffer[128]:BYTE

invoke exist,ADDR szCyrillic
.if !eax
invoke MessageBox,0,ADDR szSetup,ADDR szSetup,MB_OK
.endif
invoke RegCreateKeyEx, HKEY_CURRENT_USER,addr szSubkey, NULL, NULL, REG_OPTION_NON_VOLATILE,KEY_WRITE, NULL, ADDR hRegKey, ADDR hTemp
invoke RegSetValueEx, hRegKey, ADDR szKeyname,NULL, REG_SZ, ADDR szLucidaConsole, SIZEOF szLucidaConsole
invoke RegCloseKey, hRegKey

invoke GetStdHandle,STD_OUTPUT_HANDLE ;GetStdHandle = esi
mov esi, eax
invoke GetConsoleScreenBufferInfo,esi,ADDR sbi
mov eax, sbi.dwSize
push ax
rol eax, 16
mov cx, ax
pop ax
mul cx
cwde
mov ebx, eax
invoke FillConsoleOutputCharacterW,esi,32,eax,NULL,edi
mov ecx, 0
mov eax, 0
shl eax, 16
mov ax, cx
invoke SetConsoleCursorPosition,esi,eax
invoke SetConsoleTextAttribute, esi, FOREGROUND_GREEN OR FOREGROUND_INTENSITY
mov edi,1
.repeat
invoke LoadStringW,PROGRAM_IMAGE_BASE,edi,ADDR TextBuffer,sizeof TextBuffer
invoke SetConsoleTitleW,ADDR TextBuffer
invoke Sleep, time
inc edi
.until edi==13
invoke LoadStringW,PROGRAM_IMAGE_BASE,13,ADDR TextBuffer,sizeof TextBuffer
invoke locate, 2,2
invoke WriteConsoleW,esi, ADDR TextBuffer,60,0,0
invoke Sleep, 8000
invoke SetConsoleTextAttribute, esi, FOREGROUND_RED OR FOREGROUND_GREEN OR FOREGROUND_BLUE
invoke locate,2,4
ret
Main ENDP

end Main
Posted on 2003-06-20 10:13:53 by Prahogi
Heh. :)
?? ????
Posted on 2003-06-20 12:47:00 by comrade
Brilliant work, Prahogi
Posted on 2003-06-21 02:13:32 by jorgon
> Tovarischu

A konkretnee ?


>Jeremy Gordon

Thanks you. It motivates me to go on.

However, I'm still wondering how do it when cyrrilic support was'nt installed. Of course, I won't ask anybody here about this because it has nothing to do with the assembler :).

By the way, has anybody played with the WriteConsoleOutputW and the WriteConsoleInputW from the Wincon.h ?

http://doc.ddart.net/msdn/header/include/wincon.h.html

The WriteConsoleOutputW function accepts
LPCWSTR characters whereas WriteConsoleW - just a pointer
lpBuffer
I will give it a try tomorrow.
Posted on 2003-06-21 15:53:26 by Prahogi