jd9288
asked on
wstring
I get memory access error every time I type more than 20 characters in the edit control.
Here's the code:
wstring to;
GetDlgItemText( hWnd, IDC_EDIT_TO, (LPSTR) to.c_str(), 150 );
Error occurs in dbgdel.cpp, line 52.
Please advise.
Here's the code:
wstring to;
GetDlgItemText( hWnd, IDC_EDIT_TO, (LPSTR) to.c_str(), 150 );
Error occurs in dbgdel.cpp, line 52.
Please advise.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent, but I have to cast the buffer like so:
GetDlgItemText( hWnd, IDC_EDIT_TO, (LPSTR) awcBuffer, 150 );
GetDlgItemText( hWnd, IDC_EDIT_TO, (LPSTR) awcBuffer, 150 );
That is an euphemism, by the way. 'wstring::c_str()' returns a 'const wchar_t*', and that's the way it is supposed to be treated like - as a 'const' buffer. Writing to it will result in unexpected behaviour, actually you are lucky that it does not crash on the 1st or 2nd char entered.