How do you concatenate multi-byte LPSTR string?

0

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?

c
concatenation
asked on Stack Overflow Jun 23, 2014 by Forrest4096 • edited Jun 23, 2014 by peakxu

1 Answer

1

You declared newText as a pointer to the constant text "", which cannot be written.

Try CHAR newText[256] instead.

answered on Stack Overflow Jun 23, 2014 by user3767013

User contributions licensed under CC BY-SA 3.0