09-17-2004, 10:09 PM | #1 (permalink) |
Banned from being Banned
Location: Donkey
|
Win32 API Question about SendMessage & GETTEXT
I'm doing this from .NET, but I'm sure this problem is in standard C/C++ as well.
I'm having a hard time pulling text back from an object that contains more than 65k of text. I believe the magic # is 65535. Here's the code I'm using (even if you don't know C#, it's still the same logic as in C/C++): Code:
IntPtr txtLen = SendMessage(childCtrl, Vortex.WM_GETTEXTLENGTH, zeroval, zeroval); StringBuilder text = new StringBuilder(txtLen.ToInt32() + 1); SendMessage(childCtrl, Vortex.WM_GETTEXT, txtLen.ToInt32(), text); System.Diagnostics.Debug.WriteLine(txtLen.ToString() + " - " + text.Length.ToString()); Say I'm pulling 65k of text back, once it gets past that, the "text" buffer seems to reset itself back to 0 and go from there. Once the thing is, say, 120k, the buffer, again, resets. When it resets, it will only pull the first x chars from the window instead of the whole thing.. How do I snag ALL of the text in the window, or is that text size a limitation in the API? I can watch the Debug.WriteLine section as the window's data gets bigger and bigger. The left number represents the size of data in the window while the right side is the size of the text after the API call. After the 65k, they no longer match and the right side resets.
__________________
I love lamp. Last edited by Stompy; 09-17-2004 at 10:11 PM.. |
09-18-2004, 07:32 AM | #2 (permalink) |
Banned from being Banned
Location: Donkey
|
What's even more strange is... I'm trying it in vb to see if it's just a limitation of .net or something, and the VB return value of WM_GETTEXTLENGTH is different (about 5k less) than what the .net SendMessage returns.
I'm completely baffled. How is this possible? How can one window return 66235 in .net but return 60123 in VB? It's the SAME handle, same function call, and same constant declarations.
__________________
I love lamp. |
09-18-2004, 07:00 PM | #3 (permalink) |
Tilted
|
Just a guess: the difference in length is probably from VB forcing it to Unicode; so it's adding buffer space in case there are double-byte characters in the text.
As for getting > 64k from WM_GETTEXT, I don't think it's possible. Isn't wparam defined as a uint (the actual API, I mean; not whatever it is in your declaration...)? 65535 should be the highest value you can give it. MSDN mentions getting > 64k back from Rich Edit Control using the EM_STREAMOUT message, but I don't think there's anything you can do for a TextBox. |
Tags |
api, gettext, question, sendmessage, win32 |
|
|