What are the definitions for LPARAM and WPARAM?

69,464

Solution 1

LPARAM is a typedef for LONG_PTR which is a long (signed 32-bit) on win32 and __int64 (signed 64-bit) on x86_64.

WPARAM is a typedef for UINT_PTR which is an unsigned int (unsigned 32-bit) on win32 and unsigned __int64 (unsigned 64-bit) on x86_64.

MSDN link

Solution 2

These typedefs go back to the 16-bit days. Originally, LPARAM was a long (signed 32-bit) and WPARAM was a WORD (unsigned 16-bit), hence the W and L. Due to the common practice of passing casted pointers as message parameters, WPARAM was expanded to 32 bits on Win32, and both LPARAM and WPARAM were expanded to 64 bits on Win64.

In C#, you should use IntPtr for LPARAM and UIntPtr for WPARAM.

Note that despite the LP prefix, LPARAM is not a far pointer to an ARAM.

Solution 3

LPARAM refers to a LONG_PTR and WPARAM refers to a UINT_PTR

On x86 they will be 4 bytes and on x64 they will be 8 bytes.

Solution 4

Here:

typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;

Solution 5

What you need my friend is http://www.pinvoke.net/

Share:
69,464
Mark Heath
Author by

Mark Heath

I'm the creator of NAudio, an open source audio library for .NET. I'm interested in any ways to improve the quality of my code, and teaching others the things I learn along the way. I'm also the author of several Pluralsight courses.

Updated on July 05, 2022

Comments

  • Mark Heath
    Mark Heath almost 2 years

    I know I'm being lazy here and I should trawl the header files for myself, but what are the actual types for LPARAM and WPARAM parameters? Are they pointers, or four byte ints? I'm doing some C# interop code and want to be sure I get it working on x64 systems.

  • Mark Heath
    Mark Heath about 14 years
    yes, its a useful site, although very mixed quality interop conversions
  • User
    User over 12 years
    @Charles Bailey: maybe I'm misunderstanding you but when you say: "__int64 (signed 64-bit) on x86" don't you mean "on x86-64" or win64 or something? I take x86 to be 32-bit.
  • CB Bailey
    CB Bailey over 12 years
    @User: Yes, it's supposed to say x86_64 which is how Microsoft now refer to amd64.
  • Tobias Knauss
    Tobias Knauss over 6 years
    Please notice that the description refers to long in C++. In C#, a long is a signed 64bit, also when compiling to 32bit.