Garbage in my Char buffer

I have a program that when i push a button, i want it to get the text from 3 different text boxes and then concatenate them then change them back to a char array so i can pass it as LPWSTR to MessageBox(). the problem is that the message box will display random Chinese looking characters instead of the textbox text. if i set the message box to output any of the individual texts it works fine. only after concatenation does it get messed up. any help?

also im sure one of you fine people will know a better way to concatenate these. so please do share if you are that person. thanks =).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
			case INPUT_BUTTON:
				char DistanceText[256], TimeText[256], DateText[256];
				
				//Get the text from 3 different edit boxes
				GetWindowText(GetDlgItem(hwnd,	DISTANCE_BOX) ,(LPWSTR)DistanceText, GetWindowTextLength(GetDlgItem(hwnd, DISTANCE_BOX))+2);
				GetWindowText(GetDlgItem(hwnd,	TIME_BOX) ,(LPWSTR)TimeText, GetWindowTextLength(GetDlgItem(hwnd, TIME_BOX))+2);
				GetWindowText(GetDlgItem(hwnd,	DATE_BOX) ,(LPWSTR)DateText, GetWindowTextLength(GetDlgItem(hwnd, DATE_BOX))+2);
				
				//convert the text of the 3 boxes into strings
				std::string DistanceString = DistanceText;
				std::string TimeString = TimeText;
				std::string DateString = DateText;
				

				//concatenate the strings together
				std::string AllTextString = DistanceString+TimeString+DateString;

				//convert the concatenated string back into a char array to pass it as LPWSTR
				char AllText[256];
				strcpy(AllText, AllTextString.c_str());

				//MessageBox(hwnd,L"Are you sure?",L"",MB_OK);
				MessageBox(hwnd,(LPCWSTR)AllText,L"test",MB_OK);
				break;
		}
		break;
Stop suppressing compiler warnings/errors with casts and understand why the compiler warnings/errors are occurring, then fix the problem that so that casts are not required.
thanks for the help

for anyone who may have the same beginner issue use

GetWindowTextA()

instead of

GetWindowText()

and then dont cast the buffer as LPWSTR and its all gravey

cheers.
Topic archived. No new replies allowed.