const UINT MyMessage = RegisterWindowMessage(L"SomeUniqueText");
Now I´m trying to send messages, using WPARAM and LPARAM, nothing
sophisticated, no pointers, just plain small values.
DWORD a = 123;
int x = 17;
int y = 35;
LPARAM b = MAKELPARAM(x,y);
SendMessage(SomeWindow,MyMessage,a,b);
So far, that´s all working fine, my problem is, submitting negative
values.
It works fine using
DWORD a = -1;
SendMessage(SomeWindow,MyMessage,a,0);
At the receiving window I get
(int)wParam = -1
But if I want to use two values per parameter
int x = -1;
int y = 0;
WPARAM a = MAKEWPARAM(x,y);
SendMessage(SomeWindow,MyMessage,a,0);
the receiving window gets
(int)LOWORD(wParam) = 65535 instead of -1
Obviously, somewhere on the way my value gets converted to UINT, but I
can´t find any hint at MSDN under MAKEWPARAM or LOWORD, why this would
happen.
Could anyone clear this up for me?
And how could I do this correct?
You have done nothing wrong. It is inherent in the twos complement
binary number system used by the hardware. -1 is represented as
0xFFFF, which is 65535.
Thanks for the hint, yet the problem also occurs when I send any other
nagative value.
-101 arrives as 65425
Either way, is there a solution to it, other than restricting messages
to one value per parameter?
Just take it apart into the two elements, assign them to integers:
int x = LOWORD(lParam);
int y = HIWORD(lParam);
An int has the sign bit at bit 31. Just tell
the compiler that he has to expect it at bit 15
by casting to short which is 16 bit.
int x = (short)LOWORD(wParam)
The problem starts at the point where you put
two ints into one DWORD using the MAKEWPARAM
macro.
Its better style to do this with two shorts
because they always fit while the ints loose
half their bits. This way you get a better
feeling for the fact that only values from
-32768 to 32767 will survive the transport.
Uwe
Thank you very much, I´ll keep that in mind.