I’m translating some C# code to Delphi, I understand that(msg = TMsg):
(int)msg.LParam
is just a cast(please correct me if I’m wrong), however the following boggles my mind:
Marshal.ReadInt32( (IntPtr)msg.WParam, 4 )
can someone please clarify this?
That just reads a 4 byte integer from a pointer. In managed .net code you don’t have pointers (unless you use unsafe code) so the framework provides tools to help interop between the native and managed world. The documentation on MSDN for the .net libraries is comprehensive and, of course, describes
Marshal.ReadInt32.The extra complication here is that there is an additional offset of 4 bytes. In reality the pointer is probably pointing to a struct and this code is picking out the integer value at offset 4 of the struct. That’s overwhelmingly the most likely explanation for the code being the way it is.
Now, a literal translation would be:
but you might alternatively write it in Delphi like this:
If you know which message this
WParamrelates to then you will also know what the truerecordis to use here. And so you would not need to define a dedicated record sinceWindows.paswould already do so.