Re: Safely reading text from HWND
"Hans-J. Ude" <news@wolptec.de> wrote in message
news:0pg534tn1rnd5mll66tddg4901tkccqi83@4ax.com...
Some apps need to read the caption bars and other text of other app's
windows; sounds like the OP is trying to do that.
That's right. It runs from inside an injected DLL and seems to be
quite reliable, if not always 100% though. I don't want to crash
another application by buffer overruns. That's why I'm using CString,
it's reliable and easy to use.
If your DLL functions run on the app's primary UI thread, such as when you
inject using a Windows GetMessage hook, then the text cannot change while
your function is running. If you do something like CreateRemoteThread() and
run your DLL functions on that, then of course, it is not synchronized with
the app changing the UI.
I would check the implementation of the CWnd function you're using to get
the text. I have a feeling internally it is calling the
GetWindowTextLength() function in order to know what to call
CString::GetBuffer() with to get the buffer memory. So internally it is
doing exactly what the Win32 code I showed does... meaning it's not
thread-safe. IOW, just because it returns you a CString does not guarantee
it filled it correctly.
-- David