Resolved I would like to have only one API declare

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
216
Programming Experience
10+
VB.NET:
Public Declare Auto Function SendMessage Lib "user32.dll" (hWnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
Public Declare Auto Function SendMessage Lib "user32.dll" (hWnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As Integer) As IntPtr

This is old 32-bit code that still works with 64-bits.
But since integer and IntPtr are equal in size only at 32 bits and not at 64 bits I wonder why.
Integers and floating-point numbers, are blittable and do not require marshalling.
I have not been able to learn the default marshalling of Intptr.

Can you explain why passing a 32-bit and a 64-bit both work?

I would like to have only one declare and compensate at the calls.
Can you suggest which would be the better choice?
 
Solution
Windows data type is LPARAM, which is alias for LONG_PTR, a "signed long type for pointer precision" that is bitness-dependent.
For some windows messages that is a just a 32 bit integer or a string reference in/out anyways.
IntPtr as pointer is correct for both bitness, but it can be convenient to pass the lparam additional info directly, for example an enum value or constant or a string. A declare with lparam as String (input) or StringBuilder (output) is common.
 
I'm thinking now that Integers must get marshalled to 64-bit if the API is 64-bit. Correct?

Isn't the API's stack a set of 64-bit values? I read, and nentioned above, that it integers did not need marshalling but it seems to me the API would expect 64 correct bits.


but it can be convenient to pass the lparam additional info directly

I want to be sure I understand this. I take this to mean it can be convenient to retain both declares. And if neaded, some with lparam as appropiate.
 
Last edited:
Windows data type is LPARAM, which is alias for LONG_PTR, a "signed long type for pointer precision" that is bitness-dependent.
For some windows messages that is a just a 32 bit integer or a string reference in/out anyways.
 
Solution
Back
Top