The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: xandaz on January 10, 2012, 03:47:00 PM

Title: UNICODE and OEM ... very few spoken words....
Post by: xandaz on January 10, 2012, 03:47:00 PM
   I decided that from now on everything i do should be in unicode. Now, i was working on an list view animated thingy and used Window enumeration to fill the control. I had some trouble getting the the window bar to show the unicode string with its name and i tried to use CharToOemW and it worked. It shows. The problem is that when i run lva the window's name shows all these japaneese characters. Why is this? and why does the window Title show all but the first character when its format is of the kind:WndName db  'W',0,'i',0,'n',0,0 ????
   Thanks ... i'll check later to see if there was replying.
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: evlncrn8 on January 10, 2012, 06:22:21 PM

WndName db 'W',0,'i',0,'n',0,0


is missing a terminator.. unicode.. double null termination


WndName db 'W',0,'i',0,'n',0,0,0
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: WYVERN666 on January 10, 2012, 06:30:23 PM
Hi xandaz. Looks more easy to write:


WndName dw 'W','i','n',0


:bg
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: jj2007 on January 10, 2012, 07:40:59 PM
include \masm32\include\masm32rt.inc
include UcInData.asm

.data
uctest uc$("This is a test", 13, 10, "with two lines", 0)

.code
start: invoke MessageBoxW, 0, addr uctest, 0, MB_OK
exit
end start

(but MasmBasic (http://www.masm32.com/board/index.php?topic=13663.0) wChr$ is much easier too use  :bg)
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: xandaz on January 11, 2012, 08:03:30 AM
   Have you tried that for a window jj? i used WSTR with a MessageBoxW and it worked fine. The problem is that with CreateWindowExW, the Title only shows the first character. With ChartoOemW it works but WinEnum fails to present the Window's name decentelly.
   Thanks
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: donkey on January 11, 2012, 08:40:32 AM
Quote from: xandaz on January 11, 2012, 08:03:30 AM
   Have you tried that for a window jj? i used WSTR with a MessageBoxW and it worked fine. The problem is that with CreateWindowExW, the Title only shows the first character. With ChartoOemW it works but WinEnum fails to present the Window's name decentelly.
   Thanks

You should try the IsWindowUnicode (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633529%28v=vs.85%29.aspx) to see if your window is actually unicode, sounds like it isn't. If it isn't then perhaps the CreateWindowExW function is being redefined at some point, who knows, somewhere there may be a CreateWindowExW equ CreateWindowExA definition. To check this get a disassembly of your program and check to make sure that the right function is called, OllyDbg will do that for you. If your window is actually Unicode then you have to take a look at the string that your generating. You can verify that by looking at a HEX dump of the string you are sending to CreateWindowExW and checking it against one that has been created using MultiByteToWideChar (http://msdn.microsoft.com/en-us/library/windows/desktop/dd319072%28v=vs.85%29.aspx) which will generate the proper Unicode string. Be sure to examine them using a HEX dump, simply trying to output the string will not help you to find the source of the problem, vKim's debug macros are one tool you can use for this. If there is a discrepancy between the two strings then you have found your problem. These are the only three things I can think of that might cause the problem you are describing so I would start with them.

Edgar
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: sinsi on January 11, 2012, 08:43:36 AM
I left out the ChartoOemW and made sure that api calls were all unicode and it works fine (I assume). You have a few SendMessage calls, changing them to SendMessageW works.
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: donkey on January 11, 2012, 08:47:49 AM
Quote from: sinsi on January 11, 2012, 08:43:36 AM
I left out the ChartoOemW and made sure that api calls were all unicode and it works fine (I assume). You have a few SendMessage calls, changing them to SendMessageW works.

Wouldn't have even thought to look for that, too used to GoAsm I guess, it and the headers do Unicode natively so two quick defines and everything switches over:

STRINGS UNICODE
#DEFINE UNICODE

After that every inline string and every function is unicode by default. I was looking for a much more complex problem because the simple ones would never have occured to me.

Edgar
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: jj2007 on January 11, 2012, 10:09:48 AM
Quote from: xandaz on January 11, 2012, 08:03:30 AM
Have you tried that for a window jj?

Frequently. To make it work, you only need
invoke SetWindowTextW, handle, pString
and your edit control should be created along these lines (wChr$ is MB syntax, but you know what it means):

Quote        if UseUnicode
         invoke CreateWindowExW, WS_EX_CLIENTEDGE, wChr$("
edit"), NULL,
            WS_CHILD or WS_VISIBLE or WS_BORDER\
            or ES_LEFT or ES_AUTOHSCROLL or ES_MULTILINE, 0, 0, 0, 0,
            hWnd, IdEdit, hInstance, NULL
         mov hEdit, eax                     ; we have created an edit window
   ;      sm eax, WM_SETFONT, hButFnt, 1      ; you may choose the small font here
         invoke SetWindowLongW, hEdit,      ; we subclass the edit control
         GWL_WNDPROC, SubEdit
[/color]
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: xandaz on January 11, 2012, 03:21:01 PM
   What if you try this:
.data
.
.
WSTR MainWindowName,"Some Win"

.code
       start:
             inv. GetModuleHandle,0...
             .
             .
             inv. WinMain....
WinMain PROC....
   
    CreateWindowExW,0,addr MainClass,addr MainWindowName,...
...
...
endp
end start

   Will it show the full name of the window or just the first character?
   See the example
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: xandaz on January 11, 2012, 03:54:39 PM
   Alright. I think this new example shows better what i mean - and yes i checked with olly to see if the unicode version of the functions was being called, and also those not-wide messages where changed to wide tho it didn't seem to make a difference at that point. In this example clicking the static control will toggle both the window's title and the static text from unicode to oem(unicode) and you'll see that one is different from the other? Can someone explain this ?
   Thanks.
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: dedndave on January 11, 2012, 04:03:29 PM
xandaz,
just a thought, here
Hutch is working hard on the next release of the Masm32 package
it appears to have numerous improvements with regard to Unicode support
in fact, the thread in the MASM32 sub-forum has a few macros etc, like those by qWord   :U
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: jj2007 on January 11, 2012, 04:16:05 PM
Xandaz,

__UNICODE__ equ <1>
include \masm32\include\windows.inc

... and everything works fine.
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: qWord on January 11, 2012, 04:34:13 PM
what version of MASM32 are you using?
The WSTR-macro in version 11beta is not correct: it switch back to code segment, thus all data declared after the call are read-only.

EDIT: you must replace DefWindowProc by DefWindowProcW
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: xandaz on January 11, 2012, 05:58:33 PM
   Damn... i was thinking on my way home after picking up my baby that that it was going to be some slight detail i had overlook as usual and it was. Qw... man you really master it all. Thanks a lot guys.
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: xandaz on January 11, 2012, 06:01:29 PM
    jj.... i must put __UNICODE__ equ <1> and then all the functions run are the Wide version right? even if i do SendMessage it calls SendMessageW?
   I must put it in the source file?
   Thanks
Title: Re: UNICODE and OEM ... very few spoken words....
Post by: jj2007 on January 11, 2012, 07:02:23 PM
Quote from: xandaz on January 11, 2012, 06:01:29 PM
    jj.... i must put __UNICODE__ equ <1> and then all the functions run are the Wide version right? even if i do SendMessage it calls SendMessageW?
   I must put it in the source file?

Yes, as shown above before include wininc. At least that solved the problem on my office puter, where I have Hutch' beta installed. Now I am at home, and the trick doesn't work - instead you have to use DefWindowProcW as already posted by qWord.