CEdit::GetLine (MFC, VC++6) returns extra characters in Windows 7

1.4k Views Asked by At

m_editText is of type CEdit (from MFC). This has worked fine for years with hundreds of users in WinXP (32bit), but when the same executable file is on Win7 (64bit) some users are getting (in strText) extra weird (i.e. extended, i.e. garbage) characters appended to the text that they typed in the edit box control (m_editText). I can't reproduce problem. I verified that GetLine copied only the characters that are typed into edit box (at least on my machine).

TCHAR atchBuffer[256] = {0};  // initialize to all nulls
int nChrCount = m_editText.GetLine(0, atchBuffer, 255);
CString strText;
if (nChrCount!=0)
    strText = CString(atchBuffer);

This is compiled (debug build) in Visual C++ 6 on WinXP (32bit), MFC 5 statically linked. Any insight provided will be greatly appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

Change your code like this:

if (nChrCount!=0)
    strText = CString(atchBuffer, nChrCount);

to make sure that any garbage/uninitialized data does not get added to the CString, only the chars that are in the control.