The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: dragonvn on March 27, 2007, 04:37:53 AM

Title: How to display a UNICODE string ???
Post by: dragonvn on March 27, 2007, 04:37:53 AM
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
Title: Re: How to display a UNICODE string ???
Post by: gabor on March 27, 2007, 05:10:23 AM
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
Title: Re: How to display a UNICODE string ???
Post by: hutch-- on March 27, 2007, 05:12:24 AM
dragonvn,

If you wish to display UNICODE you must select the UNICODE Windows API functions, not the ANSI ones that are more commonly used.
Title: Re: How to display a UNICODE string ???
Post by: dragonvn on March 27, 2007, 08:21:35 AM
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
Title: Re: How to display a UNICODE string ???
Post by: u on March 27, 2007, 10:04:34 AM
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.
Title: Re: How to display a UNICODE string ???
Post by: CoR on March 27, 2007, 05:50:31 PM
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?
Title: Re: How to display a UNICODE string ???
Post by: u on March 27, 2007, 07:35:01 PM
UTF8 is not very useful. Even with languages of the Basic Multilingual Plane, string manipulations are too hard.
UTF32 takes too much memory.
Title: Re: How to display a UNICODE string ???
Post by: CoR on March 27, 2007, 08:07:00 PM
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!
Title: Re: How to display a UNICODE string ???
Post by: u on March 27, 2007, 09:16:26 PM
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...).
Title: Re: How to display a UNICODE string ???
Post by: u on March 27, 2007, 09:40:14 PM
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.
Title: Re: How to display a UNICODE string ???
Post by: dragonvn on March 30, 2007, 03:51:23 AM
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 ?
Title: Re: How to display a UNICODE string ???
Post by: u on March 30, 2007, 09:45:20 AM
1) Put your string in the RSRC file.
2) Use LoadString
3) Use the W version of the function (currently MessageBoxW)
that's it
Title: Re: How to display a UNICODE string ???
Post by: dragonvn on March 30, 2007, 11:42:17 AM
thank you! Ultrano !
Title: Re: How to display a UNICODE string ???
Post by: CoR on March 30, 2007, 09:24:49 PM
dragonvn,

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