Reputation: 169
I am working on a small GUI calculator project and I ran into a problem when I executed the following code:
HWND edit = GetDlgItem(hWnd, BUTTON_ZERO);
LPSTR currText = "";
GetDlgItemText(hWnd, EDIT_NUMBER, currText, INT_MAX);
LPSTR num = "0";
LPSTR newText = "";
StringCchCopy(newText, INT_MAX, currText);
StringCchCat(newText, INT_MAX, num);
SendMessage(editNumber, WM_SETTEXT, NULL, LPARAM(LPCSTR(newText)));
I am trying to concatenate currText
and num
into newText
.
When I execute this code, it gives me an error:
0xC000041D: An unhandled exception was encountered during a user callback.
Any suggestions?
Upvotes: 0
Views: 454
Reputation: 236
You declared newText as a pointer to the constant text "", which cannot be written.
Try CHAR newText[256] instead.
Upvotes: 1