GetMem2

Reads two bytes from a memory address into an Integer variable.

Syntax: GetMem2 Address , retVal

Address
required LongPtr. The address to read from.
retVal
required Integer. The variable to receive the value read from Address.

The bytes are interpreted in the host’s native byte order — little-endian on x86 and x64. The address is read directly with no bounds or alignment check.

Common Errors

Error When
94 (&H5E), Invalid use of Null Address is Null

Example

This example writes a 16-bit value to a buffer and reads it back with GetMem2.

Dim buf As LongPtr = AllocMem(4)
PutMem2 buf, &H1234
Dim v As Integer
GetMem2 buf, v          ' v = &H1234
FreeMem buf

See Also