FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TextBox.text not correct on Windows 2000

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
Yasushi Nakajima



Joined: 05 Oct 2006
Posts: 3

PostPosted: Thu Oct 05, 2006 11:37 pm    Post subject: TextBox.text not correct on Windows 2000 Reply with quote

I'm developping a program with DFL 0.92/DMD 0.167 on Windows XP SP2. It uses TextBox controls. It runs correctly on XP but not correctly on Windows 2000 SP4. The error is that TextBox.text property value is diffrent with the value assignend to the property. This error occurs when the value includes Japanese character at the end of string.

I think that the cause exists in dfl.utf.fromAnsi() in dfl.utf.getWindowText(). So I have wrote the following code for test. The MyTextBox.textA provides correct value on Windows XP and 2000.

Code:

char[] getTextA(HWND hwnd)
{
   char* buf;
   size_t len;
   
   len = GetWindowTextLengthA(hwnd);
   if(!len)
      return null;
   len++;
   buf = new char[len];
   
   len = GetWindowTextA(hwnd, buf, len);
   return fromMBSz(buf);
}

class MyTextBox: TextBox
{
   char[] textA() { return getTextA(handle); }
}
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Oct 06, 2006 1:59 am    Post subject: Re: TextBox.text not correct on Windows 2000 Reply with quote

dfl.utf.fromAnsi() shouldn't even be used on Windows 2000/XP unless you specifically use the compile-time version DFL_ANSI.

Are you using the current DFL snapshot? If so, it might have to do with Windows 2000 not supporting updates to the Unicode standard. It would be terrible if the 'A' API functions support some characters that the 'W' ones do not; I don't know how I would handle that in DFL.

I'm not certain what the problem truly is.
Back to top
View user's profile Send private message
Yasushi Nakajima



Joined: 05 Oct 2006
Posts: 3

PostPosted: Fri Oct 06, 2006 6:45 am    Post subject: More test Reply with quote

Quote:
dfl.utf.fromAnsi() shouldn't even be used on Windows 2000/XP unless you specifically use the compile-time version DFL_ANSI.


I see.
Then, I have tested the following code.

Code:

char[] dump(char[] str)
{
   char[] result;
   foreach(char c; str) {
      result ~= std.string.format("?02x", c);
   }
   return result;
}

extern(Windows)
{
   alias int function(HWND hWnd) GetWindowTextLengthWProc;
   alias int function(HWND hWnd, LPCWSTR lpString, int nMaxCount) GetWindowTextWProc;
}

class TestForm: Form
{
   TextBox testBox;
   Button testBtn;
   RichTextBox disp;

   this()
   {
      with( testBox = new TextBox ) {
         parent = this;
         bounds = Rect(10, 10, 100, 20);
      }
      with( testBtn = new Button ) {
         parent = this;
         bounds = Rect(120, 10, 50, 20);
         text = "test";
         click ~= &clickTest;
      }
      with( disp = new RichTextBox ) {
         parent = this;
         bounds = Rect(10, 40, 250, 200);
      }
   }
   
   void print(char[] str)
   {
      disp.appendText(str ~ "\n");
   }
   
   char[] getTextA(HWND hwnd)
   {
      char* buf;
      size_t len;
      
      len = GetWindowTextLengthA(hwnd);
      if(!len)
         return null;
      len++;
      buf = new char[len];
      
      len = GetWindowTextA(hwnd, buf, len);
      print("GetWindowTextA: " ~ dump(cast(char[])buf[0..len]));
      return fromMBSz(buf);
   }
   
   char[] getTextW(HWND hwnd)
   {
      static GetWindowTextWProc proc = null;
      static GetWindowTextLengthWProc proclen = null;
      if(!proc)
      {
         proc = cast(GetWindowTextWProc)GetProcAddress(user32, "GetWindowTextW");
         proclen = cast(GetWindowTextLengthWProc)GetProcAddress(user32, "GetWindowTextLengthW");
      }
      wchar* buf;
      size_t len;
      
      len = proclen(hwnd);
      if(!len)
         return null;
      len++;
      buf = new wchar[len];
      len = proc(hwnd, buf, len);
      print("GetWindowTextW: " ~ dump(cast(char[])buf[0..len]));
      return fromUnicode(buf, len);
   }

   private void clickTest(Object sender, EventArgs ea)
   {
      char[] test = "\u30c6\u30b9\u30c8"; // "test" in Japanese
      testBox.text = test;
      print("test: " ~ dump(test));
      print("dfl.utf.getWindowText: " ~ dump(dfl.utf.getWindowText(testBox.handle)));
      print("getTextA: " ~ dump(getTextA(testBox.handle)));
      print("getTextW: " ~ dump(getTextW(testBox.handle)));
   }

}


The result on Windows XP:
test: e38386e382b9e38388
dfl.utf.getWindowText: e38386e382b9e38388
GetWindowTextA: 836583588367
getTextA: e38386e382b9e38388
GetWindowTextW: c630b930c830
getTextW: e38386e382b9e38388

The result on Windows 2000:
test: e38386e382b9e38388
dfl.utf.getWindowText: e38386e382b9e383bb
GetWindowTextA: 836583588367
getTextA: e38386e382b9e38388
GetWindowTextW: c630b930fb30
getTextW: e38386e382b9e383bb

Problem 1:
The utf8 sequence 'e383bb' on Windows 2000 is illegal. It is generated from the illegal Unicode \u30fb (correct code is \u30c8). This problem seems to be inside Windows.

Problem 2:
The getTextA() succeeds both in XP and 2000. But using 'fromAnsi(buf, len)' instead of 'fromMBSz(buf)' (as in dfl.utf.d) causes assertion failure.
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Oct 06, 2006 9:02 am    Post subject: Re: More test Reply with quote

I am using Windows 2000 and here are my results:

DFL 0.9.2:
test: e38386e382b9e38388
dfl.utf.getWindowText: 3f3f3f
GetWindowTextA: 3f3f3f
getTextA: 3f3f3f
GetWindowTextW: 3f003f003f00
getTextW: 3f3f3f

snapshot 20060930:
test: e38386e382b9e38388
dfl.utf.getWindowText: e38386e382b9e38388
GetWindowTextA: 3f3f3f
getTextA: 3f3f3f
GetWindowTextW: c630b930c830
getTextW: e38386e382b9e38388

Note that the 'A' versions give me "???", this is expected.

I don't see the problem except that you might not have the DFL snapshot that better supports Unicode internally.

Thank you for bringing the dfl.utf.fromAnsi() bug to my attention, it will be fixed shortly.
Back to top
View user's profile Send private message
Yasushi Nakajima



Joined: 05 Oct 2006
Posts: 3

PostPosted: Fri Oct 06, 2006 6:58 pm    Post subject: I will test with snapshot Reply with quote

Thank you. I will test with snapshot.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group