Edit box behaving strangely
-
My edit box code works just fine in debug mode, but it starts behaving very peculiar when I switch to release. Basically, I have a function that looks like this:
void CTerminalCtrl::GetCurrentLine(CString* strLine)
{
int nLines, nLineLength, nRes;
CString temp;nLines = GetLineCount() - 1; nLineLength = LineLength(); // Get length of current line strLine->Empty(); GetLine(nLines, strLine->GetBuffer(nLineLength)); strLine->ReleaseBuffer(); // yadda yadda...
}
LineLength returns the correct number of characters in the current line, but GetLine always returns zero in release mode, meaning it has copied nothing. strLine will thus be empty. What is going on here? Cheers,
/FredrikSonork ID: 100.11430:PhatBoy
-
My edit box code works just fine in debug mode, but it starts behaving very peculiar when I switch to release. Basically, I have a function that looks like this:
void CTerminalCtrl::GetCurrentLine(CString* strLine)
{
int nLines, nLineLength, nRes;
CString temp;nLines = GetLineCount() - 1; nLineLength = LineLength(); // Get length of current line strLine->Empty(); GetLine(nLines, strLine->GetBuffer(nLineLength)); strLine->ReleaseBuffer(); // yadda yadda...
}
LineLength returns the correct number of characters in the current line, but GetLine always returns zero in release mode, meaning it has copied nothing. strLine will thus be empty. What is going on here? Cheers,
/FredrikSonork ID: 100.11430:PhatBoy
The documentation of CEdit::GetLine says that you've got to write the size of the buffer passed on the first word of that buffer. Alternatively, you can use the overload
int GetLine(int nIndex,LPTSTR lpszBuffer,int nMaxLength)
which does that job for you. I guess this is what it is causing your problem (in debug mode you probably are being lucky and whatever it is written in the buffer when you callGetLine
makes the function satisfied). Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
My edit box code works just fine in debug mode, but it starts behaving very peculiar when I switch to release. Basically, I have a function that looks like this:
void CTerminalCtrl::GetCurrentLine(CString* strLine)
{
int nLines, nLineLength, nRes;
CString temp;nLines = GetLineCount() - 1; nLineLength = LineLength(); // Get length of current line strLine->Empty(); GetLine(nLines, strLine->GetBuffer(nLineLength)); strLine->ReleaseBuffer(); // yadda yadda...
}
LineLength returns the correct number of characters in the current line, but GetLine always returns zero in release mode, meaning it has copied nothing. strLine will thus be empty. What is going on here? Cheers,
/FredrikSonork ID: 100.11430:PhatBoy