ReadprocessMemory Dichiarazione
-
02-01-2020 - |
Domanda
Attualmente lo ho definito come
Private Declare Function ReadProcessMemory1 Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
.
E ho un'altra dichiarazione per ogni tipo. Sto cercando di usare questo invece
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Function ReadProcessMemory( _
ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As Integer, _
<Out()> ByRef lpBuffer As Byte(), _
ByVal dwSize As Integer, _
ByRef lpNumberOfBytesRead As Integer) As Boolean
End Function
.
che è fuori pvinvoke.net, ecco come sto cercando di usarlo:
Public Shared Function Int(address As Integer)
Dim buffer(3) As Byte
ReadProcessMemory(pHandle, address, buffer, 4, 0)
Return BitConverter.ToInt32(buffer, 0)
End Function
.
Questi errori e dice tentare di leggere o scrivere memoria protetta, ma uso la vecchia dichiarazione RPM che ho in questo modo e funziona bene.
Public Shared Function Int(address As Integer)
Dim buffer As Integer
ReadProcessMemory(pHandle, address, buffer, 4, 0)
Return buffer
End Function
.
Cosa sto facendo male?
Soluzione
La tua dichiarazione P / invocata è sbagliata.Dovrebbe essere:
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Function ReadProcessMemory( _
ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
<Out()> ByVal lpBuffer As Byte(), _
ByVal dwSize As IntPtr, _
ByRef lpNumberOfBytesRead As IntPtr) As Boolean
End Function
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow