What does C # Marshal.ReadInt32 (IntPtr) mean in Delphi?
This just reads a 4 byte integer from the pointer. In managed .net code, you don't have pointers (unless you're using unsafe code), so the framework provides tools for communication between the native and managed worlds. The MSDN documentation for .net libraries is comprehensive and of course, describes Marshal.ReadInt32
.
An additional complication here is that there is an additional 4 byte offset. In fact, the pointer is probably pointing to a structure, and this code allocates an integer value at offset 4 of the structure. This is overwhelmingly the most likely explanation for the code as it is.
Now, literal translation:
PInteger(msg.WParam+4)^
but you can also write it in Delphi like this:
type
TMyRecord = record
i1: Integer;
i2: Integer;
end;
PMyrecord = ^TMyRecord;
....
value := PMyRecord(msg.WParam)^.i2;
If you know which message this one refers to WParam
, then you will also know what will use true here record
. And so you will not need to define the highlighted entry, as Windows.pas
it will already do that.
source to share