well the title kinda describes it.
I tried LOWORD(lParam) = somenum;
and it threw me an error saying that the left side valye has to be a 1-value
well the title kinda describes it.
I tried LOWORD(lParam) = somenum;
and it threw me an error saying that the left side valye has to be a 1-value
As discovered, LOWORD(lParam) = somenum; fails because the LOWORD macro expands to an expression, not an assignable lvalue. was right to point out the lvalue issue and suggest rebuilding the parameter with bit operations, and correctly called out the standard way to recompose words. The practical rule: do not try to assign into the macro — construct a new LPARAM that contains the desired low word.
A small, portable helper keeps intent clear and works on both 32- and 64-bit builds:
inline LPARAM SetLowWord(LPARAM orig, WORD low)
{
using Up = std::uintptr_t;
const Up clearMask = ~static_cast<Up>(0xFFFFu);
Up v = static_cast<Up>(orig) & clearMask;
v |= static_cast<Up>(static_cast<uint16_t>(low));
return static_cast<LPARAM>(v);
} When the low-word actually represents a signed 16-bit value (mouse X/Y, for example), sign-extension matters. A reliable extractor looks like this:
inline int LowWordAsSigned(LPARAM v)
{
return static_cast<int>(static_cast<int16_t>(static_cast<uint16_t>(v & 0xFFFFu)));
} Notes and cautions: prefer composing a new LPARAM before forwarding or sending a message rather than trying to mutate the incoming parameter in-place. On x64, use pointer-sized integer types (as above) to avoid truncation. Avoid brittle tricks such as unions that depend on layout or endianness. If convenience is wanted and semantics are simple, the standard macro that combines two words is fine (as suggested); otherwise, the helper above makes intent explicit and keeps signed/unsigned handling correct.
Jump to Post— Salem 6,009That's l-value, not 1-value (lowercase-L)
Read up on bitwise operators.
lParam &= ~0xFFFF;
lParam |= ( somenum & 0xFFFF );
That's l-value, not 1-value (lowercase-L)
Read up on bitwise operators.
lParam &= ~0xFFFF;
lParam |= ( somenum & 0xFFFF );
LOWORD is a macro, used to extract the 'low word' from a long.
HIWORD extracts the 'high word'
There is another macro that can be used to put them back together:
LPARAM MAKELPARAM(
WORD wLow,
WORD wHigh
); So a call like: MAKELPARAM(somenum, HIWORD(lParam)) would be pretty close to what you want.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.