最近学校上VBNET的课VB以前学过一点点只会看不会写不过没有办法学校开的所以几个人就组了个小组写一个下的杀毒软件要用到ReadProcessMemory来读取其它进程的内存可以怎么调用也不行goole和baidu找了N个小时提这个问题的人倒是一大堆可以是没有人解决过但是其中也给我一些其实后来在好友freecat的帮助下找到了问题的所在主要就是ReadProcessMemory声明的问题我们应该这样声明
Public Declare Function ReadProcessMemory Lib kernel (ByVal hProcess As Integer ByVal lpBaseAddress As Integer ByVal lpBuffer() As Byte ByVal nSize As Integer ByRef lpNumberOfBytesWritten As Integer) As Integer
主要是其中的ByVal lpBaseAddress As Integer ByVal lpBuffer() As Byte
要设为byval而不是byref
这样调用就可以得到返回值了
Private Declare Function OpenProcess Lib kerneldll _
(ByVal dwDesiredAccess As Integer ByVal bInheritHandle As Integer ByVal dwProcessId As Integer) As Integer
Public Declare Function ReadProcessMemory Lib kernel (ByVal hProcess As Integer ByVal lpBaseAddress As Integer ByVal lpBuffer() As Byte ByVal nSize As Integer ByRef lpNumberOfBytesWritten As Integer) As Integer
Private Const PROCESS_VM_READ As Long = &H
Dim ph As Integer
Dim i As Integer
Dim h As Integer
Dim buffer() As Byte
Dim bytesRead As Integer
获得进程
ph = OpenProcess(PROCESS_ALL_ACCESS False )
If ph Then
MessageBoxShow(true)
h = ReadProcessMemory(ph &H buffer bufferLength bytesRead)
For i = To bufferLength
TempMem += buffer(i)ToString
Next
Else
MessageBoxShow(false)
End If