News:

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

How to display a UNICODE string ???

Started by dragonvn, March 27, 2007, 04:37:53 AM

Previous topic - Next topic

dragonvn

How to display a UNICODE string ???
Help me please ???
I use MASM32 9.0
I type a unicode string but it not dipslay truely...
please help me !
thanks

gabor

Hello!

Again, some more information would be usefull.
How would you like to display the string? In messageBoxes? Or in console output?
What do you mean by not display truely? Are there corrupted characters? Or the whole string is not appearing?
In windows, there are items that can display unicode text, though (as I could experience) unicode text must be converted via WideCharToMultiBye in most cases.
Please, describe your problem more precisely!

Greets, Gábor

hutch--

dragonvn,

If you wish to display UNICODE you must select the UNICODE Windows API functions, not the ANSI ones that are more commonly used.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dragonvn

Thanks to you reply!
I want to display a unicode string ( Vietnamese) in a messagebox (i am from Vietnam).
can you help me ?
+ gabor !: I can type unicode directly in MASM32 and compile it ?
(for you: you must convert by WideCharToMultiBye...)

+hutch !: can you tell me more detail?
thanks

u

Masm can't support real unicode (unless your language's characters can be fit in 1 byte each). You'll have to put strings in the resource-file.
Then displaying that string is done via MessageBoxW() . The MessageBox() is actually renamed to MessageBoxA(). "A" stands for ASCII, "W" stands for WideChar. WideChar uses 2 bytes per character. All WindowsAPI functions, that have strings as parameters, have their "A" and "W" versions. The "A" versions simply convert the ASCII to WideChar, and then internally call the W version of the API function.
Please use a smaller graphic in your signature.

CoR

Here's the link of UNICODE types: http://en.wikipedia.org/wiki/Unicode

If I understood correctly function with W can only process UFT16 txt format, right? If that's true, what about UTF8 or 32?

u

UTF8 is not very useful. Even with languages of the Basic Multilingual Plane, string manipulations are too hard.
UTF32 takes too much memory.
Please use a smaller graphic in your signature.

CoR

Ok, are saying that Win functionsW  are made ONLY for UTF-16? And if I have some UTF-8 encoded txt I have to encode it again to UTF-16?

Win32Hlp states that TextOut is Unicode ready in WinNT and Win95. But it really means UTF-16 ready!

u

Plane 0:  0000 - FFFF (16-bit): All languages
Plane 1: 10000 – 1FFFF : obsolete symbols (not used nowadays), musical symbols, mathematical symbols
Plane 2: used for 40000 rare/obsolete Chinese symbols

UTF16 is variable-width, so if the first WORD is special, it means that the next character is from the other planes (not plane 0).


Soooo.. WindowsNT's WideChar is really unicode, and you can safely bet that 1 WORD = 1 character (except for if your customers start using those 40000 rare/obsolete Chinese symbols...).
Please use a smaller graphic in your signature.

u

P.S.
You can convert UTF8 to UTF16 via
MultiByteToWideChar(CP_UTF8,0,pInputUTF8String,-1,pOutUTF16String,MaxSizeOfOutUTF16String);
and 16-to-8 via WideCharToMultiByte(....)

If UTF8 was used directly in WinAPI, it would probably slow-down parts of the OS. Because each handled character would have to be remapped, and procs like strlen16, strcpy16 and so on would always have to remap. I.e if you wanted to get the 10000th character, you'd have to decompress the 9999 characters before it.
Please use a smaller graphic in your signature.

dragonvn

hi Ultrano.
Could you tell me more detail code in MASM32 ?
for example: i want to display a message box with a unicode string(:Việt nam là đất nước tôi) on it.
???
help me ?

u

1) Put your string in the RSRC file.
2) Use LoadString
3) Use the W version of the function (currently MessageBoxW)
that's it
Please use a smaller graphic in your signature.

dragonvn


CoR

dragonvn,

When you are finished, if it's not too much trouble, could you post the full source code please.