long title, short story: a rather old third-party library uses the following code to register its own edit control class:
staticconst TCHAR BASED_CODE szEdit = _T("GXEDIT");<br />
WNDCLASS wcls;<br />
// check to see if class already registered<br />if (!::GetClassInfo(hResource, szEdit, &wcls))<br />
// Use standard "edit" control as a template.<br />
VERIFY(::GetClassInfo(NULL, _T("edit"), &wcls));<br />
// set new values<br />
wcls.style |= GX_GLOBALCLASS;<br />
wcls.hInstance = hResource;<br />
wcls.lpszClassName = szEdit;<br />
This works fine unless XP themes are enabled.
If they are and I use GetWindowText(CString-variable) with this edit control, the CString destructor causes a heap corruption because ::GetWindowTextLength reports less bytes than ::GetWindowText actually receives, and thus CString::GetBufferSetLength allocates not enough memory.
Is there a simple solution to change the above code so that this GXEDIT works with XP themes?
I already tried rewriting it using WNDCLASSEX instead, but that didn't help.
Part of this third-party library is a grid control, and the problems occurs when a GXEDIT control is created in-place to edit the contents of a cell.
The cell contains a 4-digit number, and the value returned by GetWindowTextLength is 12.
But only if I discard this value and reserve 25 bytes or more in CString::GetBufferSetLength, the heap doesn't get corrupted.
It's strange, but I think this is only a side effect of some error in the class registration.
If I don't use the XP visual styles for this app (no manifest file), everything works fine.
Other edit controls that are of the systems standard "edit" class type, work ok with or without styles enabled...
The control does not use unicode, I have checked that. As I wrote, the problem only occurs if I enable XP visual styles and themes for the application by including a manifest file in the executables directory.
I already tried to write replacements for Get/SetWindowText:
This prevents the heap corruption, but then the edit control contains a lot of unreadable stuff like arabic letters even though the debugger shows that sW seems to contain a correct string like "1120".
The problem seems to be the registration process of the class GXEDIT.
In CGXEditControl::CreateControl, if I replace the class name "GXEDIT" with the standard "edit" class in the call to CEdit::Create, everything works!
But I don't know what side effects this will have for the rest of the library , so I want to avoid this workaround if possible.
BTW, this library is a very antique version of Stingray's Objective Grid, dated 1997 .
I have created a worker thread to connect to a data server. The thread needs to wait a few seconds and exit if no data arrives (i.e. server is not online). I need to trap the thread exit code so my main thread can know if the workher thread terminated with an error. I have the following code:
From the documentation I know I can use GetExitCodeThread to get the error code but where is the best place to put this? Should I post an exit message to the main thread and read the code there? Are there any other solutions that would be better?