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

Magnum

Is there an assembly version of wsprint?

  wprintf(L"GetMessageResources failed.\n");

; wprintf is a wide-character version of printf; format is a wide-character string.
; wprintf and printf behave identically if the stream is opened in ANSI mode.
; printf does not currently support output into a UNICODE stream.

I found some wprintf statements in msvcrt.inc.
Have a great day,
                         Andy

Vortex

Hi Magnum,

Here is an example for you :


.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc
include     \masm32\macros\ucmacros.asm

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib


.data

WSTR        str1,"Simple calculation"
WSTR        format1,"%s : 7 + 3 = %d"

.data?

.code

start:

    invoke  crt_wprintf,ADDR format1,ADDR str1,10
         
    invoke  ExitProcess,0

END start


MichaelW

At least for the Microsoft CRT, you don't need to use the wide-character version of printf to display Unicode strings, you just need to use the right type character in the format string.

;====================================================================
    include \masm32\include\masm32rt.inc
    include \masm32\macros\ucmacros.asm
;====================================================================
    .data
        WSTR buffer,"my other brother darryl"
    .code
;====================================================================
start:
;====================================================================
    invoke crt_printf, cfm$("%s\n%S\n"), ADDR buffer, ADDR buffer
    inkey "Press any key to exit..."
    exit
;====================================================================
end start


m
my other brother darryl


http://msdn.microsoft.com/en-us/library/hf4y5e3w(VS.71).aspx
eschew obfuscation

jj2007

invoke crt_printf, chr$("%S"), wChr$("TheString")
; %S: When used with printf functions, specifies a wide-character string


That works perfectly. But I cannot convince printf to produce output with a real Unicode example, i.e. Russian or Chinese text that otherwise displays fine in a wide message box... which, by the way, is a mystery that has been treated already in the WriteConsoleW thread, unsuccessfully.

MichaelW

It works with strings returned by the API:

;====================================================================
    include \masm32\include\masm32rt.inc
    include \masm32\macros\ucmacros.asm
;====================================================================
    .data
        buffer db 1024 dup(0)
    .code
;====================================================================
start:
;====================================================================
    invoke GetCurrentDirectoryW, 512, ADDR buffer
    invoke crt_printf, cfm$("%S\n"), ADDR buffer

    inkey "Press any key to exit..."
    exit
;====================================================================
end start
eschew obfuscation

dedndave

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

jj2007

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.

   invoke crt_printf, chr$("%S"), wChr$("TheString", 13, 10)   ; %S: When used with printf functions, specifies a wide-character string
   wLet esi=wRes$(001)  ; "Enter text here"
   invoke crt_printf, chr$("%S%S"), esi, wChr$(" - OK?", 13, 10)
   invoke SetConsoleOutputCP, 50000   ; 50000 associated with Lucida Console
   invoke crt_printf, chr$("%S%S"), esi, wChr$(" - OK?", 13, 10)
   wLet esi=wRes$(401)  ; "Enter text here" in Russian
   invoke crt_printf, chr$("%S%S"), esi, wChr$(" - OK?", 13, 10)
   wLet esi=wRes$(801)  ; "Enter text here" in Chinese
   invoke crt_printf, chr$("%S%S"), esi, wChr$(" - OK?", 13, 10)
   wLet esi=wRes$(1201)
   invoke crt_printf, chr$("%S%S"), esi, wChr$(" - OK?", 13, 10)

TheString
Enter text here - OK?
Enter text here - OK?
- OK?
- OK?
- OK?

dedndave

ok, Jochen....

name one language you would like to see (Chinese, Arabic - whatever)
give me a console-mode program that should display text in that language
i will see if i can make it work   :U

keep in mind that i do not read Chinese or Arabic - lol

Russian would be a good choice, as we have a few Russian members
i don't read Russian, either   :P

Magnum

wprintf(L"GetMessageResources failed.\n");

I can't see that I need wprintf just to print a text string.

Is there something that I don't understand ?

In the code sections there are a lot of goto statements.

Isn't that inefficient?

Maybe that why C code is often times bloated.  :U
Have a great day,
                         Andy

dedndave

well - that's a good assessment - lol
but - they grab wprintf because the function is in msvcrt, which already exists on all computers
there is something to be said for that, too
the msvcrt functions are, for the most part, flexible, fast and reliable

Magnum

Computers in general or those with a Windows O.S. ?

 
Have a great day,
                         Andy

dedndave

sorry about that
essentially all windows OS computers have msvcrt of some form or another on them

jj2007

Quote from: dedndave on January 30, 2011, 05:51:22 PM
ok, Jochen....

name one language you would like to see (Chinese, Arabic - whatever)


Dave,
QuoteEnter text here
Click on this button
Welcome

Введите текст здесь
Нажмите на эту кнопку
Добро пожаловать

أدخل النص هنا
دفع هذا الزر
مرحبا بكم

在這裡輸入文字
按一下這個按鈕
歡迎
... seeing the text in a console is not really the problem. What bogs me down is that under certain, hardly predictable circumstances it works, under others not. Certain is that the user must set Lucida Console under console properties. Uncertain 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...

Here is the full code, using a resource string table with IDs 1-3, 401-403, 801-803, 1201-1203 for the respective languages:

Quote   MyCP=CP_UTF8
   
invoke SetConsoleOutputCP, MyCP   ; CP_UTF8 aka 65001 WORKS...!!
   ConsoleColor cWhite, cBlue         ; normal CP is 1252 for Western text; user must set console properties to Lucida Console
   For_ Lang=0 To 3
      imul edi, Lang, 400
      For_ n=1 To 3
         wLet esi=wRes$(n+edi)+wCrLf$   ; get a Unicode string from the resource stringtable
         push ecx
         invoke WideCharToMultiByte, MyCP, 0, esi, -1, 0, 0, NULL, NULL   ; 0, 0: get buffer size
         inc eax
         push eax
         Let ebx=New$(eax)            ; create a buffer for the multibyte string
         pop eax
         invoke WideCharToMultiByte, MyCP, 0, esi, -1, ebx, eax, NULL, NULL
         pop ecx
         
Print ebx
      Next
      Print
   Next

Magnum

I would like to enter some Korean text and send in via email.

Have a great day,
                         Andy

Magnum

I am working on this now.

Am I on the right track?



; DWORD GetLastRecordNumber(HANDLE hEventLog, DWORD* pdwMarker);
;
; BOOL GetOldestEventLogRecord(
;
;     HANDLE hEventLog,   // handle to event log
;     PDWORD OldestRecord    // buffer for number of oldest record 
;    );
GetLastRecordNumber PROC hFile:DWORD,

invoke GetOldestEventLogRecord, hFile,
ret

GetLastRecordNumber endp
Have a great day,
                         Andy