Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPARAM and LPARAM parameters

Tags:

c++

winapi

api

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?

like image 582
Adrian Avatar asked Jun 14 '11 06:06

Adrian


People also ask

What is difference between Wparam and Lparam?

If you look at the design of window messages, you will see that if the message takes a pointer, the pointer is usually passed in the LPARAM , whereas if the message takes a handle or an integer, then it is passed in the WPARAM .

What is Lparam used for?

lParam - Specifies additional message information. The contents of this parameter depend on the value of the uMsg parameter.

What type is Lresult?

LRESULT is an integer value that your program returns to Windows. It contains your program's response to a particular message.

What is Wm_command?

Sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.


2 Answers

When sending messages, WPARAM and LPARAM 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 from WM_USER, WM_APP, or RegisterWindowMessage), then you obviously have a bit more latitude.

In the days of 16-bit Windows, a WPARAM was a 16-bit word, while LPARAM was a 32-bit long. These distinctions went away in Win32; they both became 32-bit values.

According to this, LPARAM is defined as LONG_PTR, which in 64-bit Windows is a signed, 64-bit value. WPARAM is defined as UINT_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.

like image 151
Aaron Klotz Avatar answered Sep 20 '22 14:09

Aaron Klotz


╔════════════════╦══════════════════╦═══════════════╗
║                ║ WPARAM           ║ LPARAM        ║
║                ╟──────────────────╫───────────────╢
║ OS             ║ handles, numbers ║ pointers      ║
╠════════════════╬══════════════════╬═══════════════╣
║ 16-bit Windows ║ 16-bit unsigned  ║ 32-bit signed ║
║ 32-bit Windows ║ 32-bit unsigned  ║ 32-bit signed ║
║ 64-bit Windows ║ 64-bit unsigned  ║ 64-bit signed ║
╚════════════════╩══════════════════╩═══════════════╝ 

The history of its definition has changed over the years.

WINDOWS.H (Windows 2.03 SDK, c. 1988)

/* Message structure */
typedef struct tagMSG {
    HWND hwnd;
    WORD message;
    WORD wParam;
    LONG lParam;
    DWORD time;
    POINT pt;
} MSG;

WinDefs.h (c. 1999)

/* Types use for passing & returning polymorphic values */
typedef UINT WPARAM;
typedef LONG LPARAM;
typedef LONG LRESULT;

WinDef.h (c. 2005)

/* Types use for passing & returning polymorphic values */
typedef UINT_PTR            WPARAM;
typedef LONG_PTR            LPARAM;
typedef LONG_PTR            LRESULT;

Bonus Reading

  • What do the letters W and L stand for in WPARAM and LPARAM? archive(W is for unsigned 16-bit WORD, and L is for signed 32-bit LONG)
  • What happens to WPARAM, LPARAM, and LRESULT when they travel between 32-bit and 64-bit windows? archive(the unsigned is zero-extended, the signed is sign-extended)
like image 37
Ian Boyd Avatar answered Sep 18 '22 14:09

Ian Boyd