I need to append text to win32 edit control i have working function to do this , but the text that printed in the edit control is gibrish why ? the sample code taken from microsoft example from here
void settext(HWND hDlg,std::string s)
{
//std::wstring ws;
//ws.assign( s.begin(), s.end() );
//LPWSTR pwst = &ws[0];
//// get temporary LPCWSTR (pretty safe)
//LPCWSTR pcwstr = ws.c_str();
//SetDlgItemText(hWndEdit, IDC_EDIT1,pcwstr);
HWND hWndEdit = GetDlgItem (hDlg, IDC_EDIT1);
LPSTR pst = &s[0];
int ndx = GetWindowTextLength (hWndEdit);
SetFocus (hWndEdit);
#ifdef WIN32
SendMessage (hWndEdit, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
#else
SendMessage (hWndEdit, EM_SETSEL, 0, MAKELONG (ndx, ndx));
#endif
SendMessage (hWndEdit, EM_REPLACESEL,0,(LPARAM)pst);
}
and from the DlgProc im calling :
std::string ss("wwwwww");
settext(hwnd,ss);
update
even if i do as suggested here :
SendMessage (hWndEdit, EM_REPLACESEL,0,(LPARAM)s.c_str());
that pass compilation but still the characters printed are gibrish
and if i do :
LPSTR pst = s.c_str()
it doesn't pass compilation the error:
error C2440: 'initializing' : cannot convert from 'const char *' to 'LPSTR'