Hello everybody, im starting on C and i need some help :)
Ive created a function receives the HWND of a Edit Control and some text as arguments.
The thing is simple: It should send the Text to the HWND using SendMessage and WM_SETTEXT.
The name of the HWND is stored in char hwndname[20];
The text is stored in char thetext[50];
I try to
SendMessage(hwndname, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
and i get
C:\FirstProject\sendtexttohwnd.c
[Warning] passing arg 1 of `SendMessageA' from incompatible pointer type
/John00 F.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just declare
HWND hwnd;
and then try
SendMessage(hwnd, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
Should work this way. HWND is a type, it's not a char or pointer to char or array of chars...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Guess you got it now ;-)
int somefunction(char * <-- what's a char* doing there if you want to pass the function a HWND? Nothing! ;-)
Pass it the HWND and try again:
int somefunction(HWND NameOfTheHWNDiWantToSendTheMessageTo) {....}
Good luck! And a little tip: If you get a message saying something like "[Warning] passing arg 1 of `blabla' from incompatible blablabla type" it's best to check the API again and look at the functions prototype because most of the times you used the function wrong. And remember: Allways pass what you need the right way! ;-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everybody, im starting on C and i need some help :)
Ive created a function receives the HWND of a Edit Control and some text as arguments.
The thing is simple: It should send the Text to the HWND using SendMessage and WM_SETTEXT.
The name of the HWND is stored in char hwndname[20];
The text is stored in char thetext[50];
I try to
SendMessage(hwndname, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
and i get
C:\FirstProject\sendtexttohwnd.c
[Warning] passing arg 1 of `SendMessageA' from incompatible pointer type
/John00 F.
A HWND is a HWND, WTF are you trying to do?
Just declare
HWND hwnd;
and then try
SendMessage(hwnd, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
Should work this way. HWND is a type, it's not a char or pointer to char or array of chars...
I know...i have all my H=hwnds declared as HWNDS, all my hinstances declared as HINSTANCES, i must have explained the problem very wrongly.
int somefunction(char *NameOfTheHWNDiWantToSendTheMessageTo) {
SendMessage(NameOfTheHWNDiWantToSendTheMessageTo, WM_SETTEXT, (sizeof (thetext) -1), (LPARAM) ((LPSTR) thetext));
return 0;
}
Is this possible? Thena what is the right way to do it? You can see the erros im having at my first msg.
Oh i got it, what you meant is thhat i have to set the arg to the functions as a HWND too, is that it?
Guess you got it now ;-)
int somefunction(char * <-- what's a char* doing there if you want to pass the function a HWND? Nothing! ;-)
Pass it the HWND and try again:
int somefunction(HWND NameOfTheHWNDiWantToSendTheMessageTo) {....}
Good luck! And a little tip: If you get a message saying something like "[Warning] passing arg 1 of `blabla' from incompatible blablabla type" it's best to check the API again and look at the functions prototype because most of the times you used the function wrong. And remember: Allways pass what you need the right way! ;-)