What are the definitions for LPARAM and WPARAM?

C#C++Windows

C# Problem Overview


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.

C# Solutions


Solution 1 - C#

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 - C#

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 - C#

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 - C#

Here:

typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;

Solution 5 - C#

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

Solution 6 - C#

c++ in linux and windows 64bit tested, the most simple solution I found:

#define WPARAM long long unsigned int
#define LPARAM long long int

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMark HeathView Question on Stackoverflow
Solution 1 - C#CB BaileyView Answer on Stackoverflow
Solution 2 - C#dan04View Answer on Stackoverflow
Solution 3 - C#Brian R. BondyView Answer on Stackoverflow
Solution 4 - C#jpalecekView Answer on Stackoverflow
Solution 5 - C#SerialSebView Answer on Stackoverflow
Solution 6 - C#superbemView Answer on Stackoverflow