Forrest4096
Forrest4096

Reputation: 169

How do you concatenate multi-byte LPSTR string?

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

Answers (1)

user3767013
user3767013

Reputation: 236

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

Try CHAR newText[256] instead.

Upvotes: 1

Related Questions