End Google Ads 201810 - BS.net 01 --> I wrote the below function to read the contents of a single line CEdit control when the enter key is pressed.

void CCommandBox::ProcessEnterKey()
{
int dLineLen = LineLength();
char* szCommand = new char[dLineLen()+1];
GetLine(0, szCommand);
szCommand[dLineLen] = '\0';

E.m_pcpCmdParser->ProcessCommand(szCommand, false);
SetWindowText("");
delete[] szCommand;
}
It works perfectly when running in debug mode but when I build a release version szCommand just gets filled with junk. I had this exact same problem last time I tried to do something similar and in end I had to switch to a CRichEdit and use StreamOut() but I'd rather not do that again.

What's the correct way to read a line from a CEdit control so that it works in a release build?