最近學校上VB
NET的課
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
這樣調用就可以得到返回值了
[code]
Private Declare Function OpenProcess Lib
kernel
dll
_
(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
MessageBox
Show(
true
)
h = ReadProcessMemory(ph
&H
buffer
buffer
Length
bytesRead)
For i =
To buffer
Length
TempMem += buffer(i)
ToString
Next
Else
MessageBox
Show(
false
)
End If
[/code]
From:http://tw.wingwit.com/Article/program/net/201311/12639.html