The MASM Forum

General => The Campus => Topic started by: asmcoder on December 26, 2013, 12:33:42 PM

Title: trouble in unicode
Post by: asmcoder on December 26, 2013, 12:33:42 PM
Hello everyone,
I have a trouble when using unicode.
My system is Chinese Simplified (Mainland China) , the program attached works fine.
But when I run the program in Chinese traditional (HongKong, TaiWan...) system , something unexpected happened.

i use the same unicode text to show in a msgbox and the dialog title.
the msgbox works fine.
but the  dialog title has some "?"
Title: Re: trouble in unicode
Post by: MichaelW on December 26, 2013, 01:18:55 PM
What happens if you create the dialog with the Unicode version of the DialogBoxParam function?
Title: Re: trouble in unicode
Post by: dedndave on December 26, 2013, 01:20:58 PM
it's not a UNICODE window
i am surprised you got as far as you did

in the t2.asm file, comment out these lines
;.386
;.model flat, stdcall  ;32 bit memory model
;option casemap :none  ;case sensitive

include t2.inc


in the t2.inc file.....
__UNICODE__ EQU 1

include \masm32\include\masm32rt.inc
;include windows.inc
;include kernel32.inc
;include user32.inc
;include Comctl32.inc
;include shell32.inc

;includelib kernel32.lib
;includelib user32.lib
;includelib Comctl32.lib
;includelib shell32.lib

include String.inc


i can't tell if it works, because i don't have Traditional Chinese installed
Title: Re: trouble in unicode
Post by: asmcoder on December 26, 2013, 01:38:02 PM
i debug it with olly, found that __UNICODE__ don't work, still generate DialogBoxParamA

when i manually type DialogBoxParamW, the unicode text works
Title: Re: trouble in unicode
Post by: asmcoder on December 26, 2013, 01:54:20 PM
maybe my masm version is not 11 , i'll download it and try later.
Title: Re: trouble in unicode
Post by: MichaelW on December 26, 2013, 02:43:25 PM
There is also the  IsWindowUnicode (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633529(v=vs.85).aspx) function.
Title: Re: trouble in unicode
Post by: jj2007 on December 26, 2013, 07:13:28 PM
t2Dlg.rc is missing in your archive above.

In case you have MasmBasic (http://masm32.com/board/index.php?topic=94.0), attached a little test. I guess it's simplified Chinese.
Title: Re: trouble in unicode
Post by: asmcoder on December 26, 2013, 07:20:40 PM
Quote from: jj2007 on December 26, 2013, 07:13:28 PM
t2Dlg.rc is missing in your archive above.

In case you have MasmBasic (http://masm32.com/board/index.php?topic=94.0), attached a little test. I guess it's simplified Chinese.

Thanks jj
t2Dlg.rc is in the Res folder.  i created the project using radasm2. 



After download masm11, use __UNICODE__  ,the problem solved.
Title: Re: trouble in unicode
Post by: white on December 26, 2013, 10:30:40 PM
how to define a unicode string has chinese words? sorry my english is poor

how to define a unicode string has chinese words? sorry my english is poor

I edited this because it was displaying in Chinese characters.
Title: Re: trouble in unicode
Post by: hutch-- on December 26, 2013, 11:05:09 PM
White,

There are a couple of ways to display Chinese characters in MASM, normally source code for MASM must be written in ordinary ASCII characters but you can create an RC file in UNICODE where you can directly enter any UNICODE character including Chinese characters as resource strings. The other way is to make sequences in the .DATA section using the WORD data size (16 bit) and type the numbers for the UNICODE characters as an array of WORD size data elements.
Title: Re: trouble in unicode
Post by: jj2007 on December 26, 2013, 11:20:44 PM
With MasmBasic's RichMasm editor, you can even type your Unicode strings directly into the source, and display them using the wRes$() macro (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1105) (when hitting F6, the editor exports the part between the two Rsrc marks to filename.rc, then builds the project):
Title: Re: trouble in unicode
Post by: asmcoder on December 26, 2013, 11:45:17 PM
Hi, white.
you can download my attached files.
see string.inc

you can use $CTW0 ,  $TW0  , CCOUNTED_UNICODE_STRING  to define any unicode string, including Chinese

but you can not directly write Chinese in the source code, you need to write a translate program like this:

(http://bwpkb.img38.wal8.com/img38/397073_20131226203745/13880615918.jpg)

then
invoke MessageBoxW,0,$CTW0("\u4F60h\u597Dh\uFF0Ch\u6211h\u6765h\u81EAh\u4E2Dh\u56FDh\u0020h\u0068h\u0065h\u006Ch\u006Ch\u006Fh\u002Ch\u0069h\u0027h\u006Dh\u0020h\u0066h\u0072h\u006Fh\u006Dh\u0020h\u0043h\u0068h\u0069h\u006Eh\u0061h\u002Eh"),0,0

of course the english words need not to translate, also you can
invoke MessageBoxW,0,$CTW0("\u4F60h\u597Dh\uFF0Ch\u6211h\u6765h\u81EAh\u4E2Dh\u56FDh hello,i'm from China."),0,0

that means you can mix them