The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on December 30, 2008, 12:10:18 PM

Title: Problem with unicode
Post by: Farabi on December 30, 2008, 12:10:18 PM
Im using invoke SendMessageW,hEdit,EM_GETLINE,0,addr buff to get the text from the RichEdit text box. The real value I should get is 0x0628 but I only get 0x0028. What is wrong with my code?
Title: Re: Problem with unicode
Post by: Tedd on December 30, 2008, 01:23:37 PM
First try it with SendMessage and see if it gives the same result.

Is the text in the rich-edit wrapped? If so, you'll only get the top line, none of the wrapped parts.
Title: Re: Problem with unicode
Post by: donkey on December 30, 2008, 05:10:33 PM
Have you tried using IsWindowUnicode to determine if the RE is actually Unicode and not MBCS ? In the case of ANSI MBCS the result would be what you have posted. Aslo, which version of the RichEdit are you using ? Version 1 supports MBCS but not Unicode, you should be using Version 2.0 or greater for Unicode.
Title: Re: Problem with unicode
Post by: Farabi on January 01, 2009, 05:31:02 AM
Quote from: Tedd on December 30, 2008, 01:23:37 PM
First try it with SendMessage and see if it gives the same result.

Is the text in the rich-edit wrapped? If so, you'll only get the top line, none of the wrapped parts.

I used SendMessage and the result is for example if the value are 28 06 28 06 (0x628 twice) it become 28 28 00 00.
Title: Re: Problem with unicode
Post by: Farabi on January 01, 2009, 05:35:48 AM
Quote from: donkey on December 30, 2008, 05:10:33 PM
Have you tried using IsWindowUnicode to determine if the RE is actually Unicode and not MBCS ? In the case of ANSI MBCS the result would be what you have posted. Aslo, which version of the RichEdit are you using ? Version 1 supports MBCS but not Unicode, you should be using Version 2.0 or greater for Unicode.

I think I used version 2.0
Here is the code
Quote
      invoke LoadLibrary,CADD("RICHED32.DLL")
      .if eax!=0
         mov dllhnd,eax
      .else
         invoke PERR
      .endif
invoke CreateWindowEx,WS_EX_CLIENTEDGE,CADD("RichEdit20A"),NULL,edx,0,0,400,200,hWnd,799,hInstance,NULL
Title: Re: Problem with unicode
Post by: Farabi on January 01, 2009, 05:38:38 AM
I tried the IsWindowUnicode and it seems the richedit is not Unicode version. Which version should I use?
Title: Re: Problem with unicode
Post by: MichaelW on January 01, 2009, 05:54:03 AM
RICHED32.DLL is version 1. RICHED20.DLL can be version 2 or 3 depending on your version of Windows. UNICODE support was added starting in version 2.

Title: Re: Problem with unicode
Post by: Farabi on January 01, 2009, 04:04:44 PM
Quote from: MichaelW on January 01, 2009, 05:54:03 AM
RICHED32.DLL is version 1. RICHED20.DLL can be version 2 or 3 depending on your version of Windows. UNICODE support was added starting in version 2.



Im using XP. Is it sufficient?
Title: Re: Problem with unicode
Post by: donkey on January 01, 2009, 06:27:00 PM
Quote from: Farabi on January 01, 2009, 04:04:44 PM
Im using XP. Is it sufficient?

RICHED32 is only for 1.x, you will have to use RichEd20.dll in order to use unicode. RICHED32 is available on all Windows versions for backward compatibility reasons, though I think it was only ever shipped as the primary rich edit control with Windows 95.
Title: Re: Problem with unicode
Post by: MichaelW on January 01, 2009, 07:45:48 PM
For Windows XP RICHED20.DLL is Rich Edit 3.0. Starting with SP1 there is also Rich Edit 4.1 (Msftedit.dll), but using it would break compatibility with Window 2000. For Windows 2000 and XP the available Rich Edit 1.0 is actually an emulator.
Title: Re: Problem with unicode
Post by: Farabi on January 02, 2009, 01:58:05 PM
I used the riched20 but it doesnot seems to support unicode. I upload the source.

[attachment deleted by admin]
Title: Re: Problem with unicode
Post by: donkey on January 02, 2009, 02:23:10 PM
Hi Farabi,

Tried to look at it but I don't have any of the macros or code libraries that you use with MASM, I will try to find them (like CADD or memfill) but I am sure they are in MASM32 which means that I will have to install it just to assemble the code, currently I have only a very minimal version of MASM32 on my system since I don't generally ever use it and certainly don't use any of the macros or code libraries that come with it (not that I have anything against them I just prefer my own). Perhaps later today I can take a look.
Title: Re: Problem with unicode
Post by: MichaelW on January 02, 2009, 05:43:54 PM
The first problem I see is that:

invoke CreateWindowEx,WS_EX_CLIENTEDGE,CADD("RichEdit20A"),...

Should be:

CreateWindowEx,WS_EX_CLIENTEDGE,CADD("RichEdit20W"),...

Or at least this will cause IsWindowUnicode to return true.

But something else is triggering an access violation exception, here:

        00401464 51           push ecx
        00401465 52           push edx
        00401466 8db500f4ffff lea esi,[ebp+0xfffff400] ss:0012f168=00000000
        0040146c 33c9         xor ecx,ecx
        0040146e 03b5ecf3ffff add esi,[ebp+0xfffff3ec] ss:0012f154=0000ee98
FAULT ->00401474 8a0e         mov cl,[esi]

Title: Re: Problem with unicode
Post by: Farabi on January 03, 2009, 12:56:40 AM
Quote from: MichaelW on January 02, 2009, 05:43:54 PM
The first problem I see is that:

invoke CreateWindowEx,WS_EX_CLIENTEDGE,CADD("RichEdit20A"),...

Should be:

CreateWindowEx,WS_EX_CLIENTEDGE,CADD("RichEdit20W"),...

Or at least this will cause IsWindowUnicode to return true.

But something else is triggering an access violation exception, here:

        00401464 51           push ecx
        00401465 52           push edx
        00401466 8db500f4ffff lea esi,[ebp+0xfffff400] ss:0012f168=00000000
        0040146c 33c9         xor ecx,ecx
        0040146e 03b5ecf3ffff add esi,[ebp+0xfffff3ec] ss:0012f154=0000ee98
FAULT ->00401474 8a0e         mov cl,[esi]



Thanks for the analysis. I think I know what causing the access violation exception.
Hm, thats weird, if I put all the buffer value to 0, I cant get any text, but if I fill the buffer with 0x20 it is working fine. Is it normal?
Title: Re: Problem with unicode
Post by: Farabi on January 03, 2009, 01:32:56 AM
Quote from: donkey on January 02, 2009, 02:23:10 PM
Hi Farabi,

Tried to look at it but I don't have any of the macros or code libraries that you use with MASM, I will try to find them (like CADD or memfill) but I am sure they are in MASM32 which means that I will have to install it just to assemble the code, currently I have only a very minimal version of MASM32 on my system since I don't generally ever use it and certainly don't use any of the macros or code libraries that come with it (not that I have anything against them I just prefer my own). Perhaps later today I can take a look.

CADD is placed above the include section. And memfill is on MASM32 library.
Title: Re: Problem with unicode
Post by: MichaelW on January 03, 2009, 07:07:54 AM
QuoteHm, thats weird, if I put all the buffer value to 0, I cant get any text, but if I fill the buffer with 0x20 it is working fine. Is it normal?

If the method that you are using to set the control text expects a null-terminated string, then yes, it would be normal. A null-terminated string that starts with a null has a length of zero.