When passing a value to a function that takes both a WPARAM and a LPARAM parameter, does it matter on which of them I pass it? Someone told me that if I use Windows x64 I should use WPARAM; is this true?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 我用scrapy写了一个蛮简单的爬虫怎么封装成一个api啊
- 后端给前端的API接口是怎么用代码写的
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
When sending messages,
WPARAM
andLPARAM
parameters have specific interpretations depending on the message. You need to pass those parameters in the way that the message that you are sending expects them to be passed. If you are defining your own message (perhaps via an offset fromWM_USER
,WM_APP
, orRegisterWindowMessage
), then you obviously have a bit more latitude.In the days of 16-bit Windows, a
WPARAM
was a 16-bit word, whileLPARAM
was a 32-bit long. These distinctions went away in Win32; they both became 32-bit values.According to this,
LPARAM
is defined asLONG_PTR
, which in 64-bit Windows is a signed, 64-bit value.WPARAM
is defined asUINT_PTR
, which in 64-bit Windows is an unsigned, 64-bit value. If you are defining your own message, you might want to assign its parameters accordingly.Yes, it does. I once passed them in swapped order and the function I call fails. Nevertheless, you should consult MSDN when in doubt. I never program in Win64 though, so I don't whether there are differences between Win32 and Win64 regarding
WPARAM
/LPARAM
behavior.Yes, the order matters.
WPARAM
sent/posted in one side winds upWPARAM
on the other end; likewise forLPARAM
.If you have your own custom messages you can use
WPARAM
andLPARAM
for anything you want. (There may be some common conventions though.)The history of its definition has changed over the years.
WINDOWS.H (Windows 2.03 SDK, c. 1988)
WinDefs.h (c. 1999)
WinDef.h (c. 2005)
Bonus Reading
W
is for unsigned 16-bitWORD
, andL
is for signed 32-bitLONG
)It's message-specific. You can use this list of system-defined message categories as reference. Select a group, then a message from the group to see what the message specifies you should pass as WPARAM/LPARAM.
Raymond Chen explains why we have two params.