Visual Basic - Technik, FAQ, Tricks, Beispiele

Home / System / Windows / PeekPoke

Speicher auslesen und schreiben

Mit folgenden Funktionen kann der Inhalt des Speichers direkt ausgelesen (Peek) oder geschrieben (Poke) werden:
'Deklarationsteil:
Declare Sub RtlMoveMemory Lib "kernel32" ( _
    dest As Any, source As Any, ByVal bytes As Long)

'Byte (8 Bit):
Function PeekB(ByVal Addr As Long) As Byte
  RtlMoveMemory PeekB, ByVal Addr, 1
End Function
Sub PokeB(ByVal Addr As Long, ByVal Value As Byte)
  RtlMoveMemory ByVal Addr, Value, 1
End Sub

'Word (16 Bit):
Function PeekW(ByVal Addr As Long) As Integer
  RtlMoveMemory PeekW, ByVal Addr, 2
End Function
Sub PokeW(ByVal Addr As Long, ByVal Value As Integer)
  RtlMoveMemory ByVal Addr, Value, 2
End Sub

'Long (32 Bit):
Function PeekL(ByVal Addr As Long) As Long
  RtlMoveMemory PeekL, ByVal Addr, 4
End Function
Sub PokeL(ByVal Addr As Long, ByVal Value As Long)
  RtlMoveMemory ByVal Addr, Value, 4
End Sub

Übersetzung eines Artikels von Francesco Balena (VB2TheMax).

© Jost Schwider, 18.06.2000-29.10.2000 - http://vb-tec.de/peek.htm