T
T
tigmen2022-02-02 21:36:14
C++ / C#
tigmen, 2022-02-02 21:36:14

GetWindowText() writes to an array of chars through a character, how to solve?

the code:

char msg[256];
 GetWindowText(obj.hEDIT,(LPWSTR)&msg, sizeof(msg));
 //SendMessage(obj.hEDIT, EM_GETLINE, 0,(LPARAM)(LPSTR)msg);
 servermessage(msg);
 SendMessage(obj.hListBox, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)msg);

servermessage():
int s = sizeof(msg);
send(hconnect, msg, s, NULL);
return 0;

this is how visual studio debugging sees the msg array:
61facf12b2831475404775.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2022-02-02
@tigmen

GetWindowText() writes to an array of chars via character
GetWindowText(obj.hEDIT,(LPWSTR)&msg, sizeof(msg));

If it is a char array, then GetWindowTextA must be used and the pointer to the array must not be cast to the LPWSTR type.
The last argument to GetWindowText, by the way, is not the size of the buffer, but the number of characters in it, so you should (should) have passed not sizeof(msg)a sizeof(msg)/sizeof(*LPWSTR).

H
HemulGM, 2022-02-02
@HemulGM

Read MSDN. Everything is clearly written what and how. First study - then stupid questions. And not vice versa.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question