您好,登錄后才能下訂單哦!
這篇文章主要介紹如何解決VB.NET中ReadProcessMemory的問題,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
在學校上VB.NET的課,VB以前學過一點點,只會看不會寫,不過沒有辦法,學校開的,所以幾個人就組了個小組,寫一個VB.NET下的殺毒軟件,要用到VB.NET ReadProcessMemory來讀取其它進程的內存,可以怎么調用也不行,goole和baidu找了N個小時。提這個問題的人倒是一大堆,可以是沒有人解決過,但是其中也給我一些其實,后來在好友freecat的幫助下,找到了問題的所在,主要就是VB.NET ReadProcessMemory聲明的問題,我們應該這樣聲明
Public Declare Function ReadProcessMemory Lib "kernel32"
(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 "kernel32.dll" _
(ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer,
ByVal dwProcessId As Integer) As IntegerPublic Declare Function ReadProcessMemory Lib "kernel32"
(ByVal hProcess As Integer, ByVal lpBaseAddress As Integer,
ByVal lpBuffer() As Byte, ByVal nSize As Integer,
ByRef lpNumberOfBytesWritten As Integer) As IntegerPrivate Const PROCESS_VM_READ As Long = &H10
Dim ph As Integer
Dim i As Integer
Dim h As Integer
Dim buffer(20) As Byte
Dim bytesRead As Integer
'獲得進程
ph = OpenProcess(PROCESS_ALL_ACCESS, False, 1832)
If ph Then
MessageBox.Show("true")
h = ReadProcessMemory(ph, &H403000, buffer, buffer.Length, bytesRead)
For i = 0 To buffer.Length - 1
TempMem += buffer(i).ToString
Next
Else
MessageBox.Show("false")
End If
以上是“如何解決VB.NET中ReadProcessMemory的問題”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。