Reputation: 11409
I am trying to get the rect from lParam
while subclassing WM_MOVING
.
My code currently is
Public Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim r As RECT
CopyMemory r, lParam, Len(r)
But the values of r
are so absurd (like left: 1633872, right: 219218039, bottom: 1) that I think I am doing something wrong.
Does anybody see my error?
Thank you!
Upvotes: 1
Views: 714
Reputation: 24283
Your declaration and code is passing a pointer to lParam
which itself is a pointer to the structure.
You should adjust the calling code to pass the lParam
value "by value" so CopyMemory
gets the actual data pointer:
CopyMemory r, ByVal lParam, Len(r)
Using the generic declaration for CopyMemory
that you had originally means you can pass a pointer to anything, or a pointer value itself with the ByVal
keyword.
'Copy data out
CopyMemory r, ByVal lParam, Len(r)
'Modify r
'Copy data back in
CopyMemory ByVal lParam, r, Len(r)
Alternativly, you can create strongly typed alias as per your other answer.
Upvotes: 1
Reputation: 11409
I am now using the fool-safe
Private Declare Function CopyFromLParamToRect Lib "user32" Alias "CopyRect" (lpDestRect As RECT, ByVal lpSourceRect As Long) As Long
It works fine.
Upvotes: 2