Link to home
Start Free TrialLog in
Avatar of jd9288
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.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>It is *not* a good idea

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.
Avatar of jd9288
jd9288

ASKER

Excellent, but I have to cast the buffer like so:

GetDlgItemText( hWnd, IDC_EDIT_TO, (LPSTR) awcBuffer, 150 );