想要做个程序读取指定地址的数据,但是在第二个语句:ReadProcessMemory gmePro, ByVal sitBase(sitNum), chessData(8, 25), 200, 运行时,只能读取当前指定地址的第一个数据,其他的数据无法读取或显示,请教各位大大,(我的代码 )如下,我的代码错在什么地方了,第一个ReadProcessMemory语句读出的数据是正确的,可第二个,测试了很多次,只能读取一个数据到当前的chessData(8, 25),二维数组中,如何才能正确的把指定地址的内存数据读取到指定的二维数组,并显示到文本框中呢?
'-----------------------------------------------API函数声明部分--------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
'关闭进程函数
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'-------------------------------测试代码部分---------------------------------------
Private Sub Command1_Click()
Dim gmeH As Long
Dim gmePid As Long
Dim gmePro As Long
Dim sitNum As Long
Dim readByte As Long
Dim sitBase(3) As Long
sitBase(0) = &H479418
sitBase(1) = &H479FFC
sitBase(2) = &H47ABE0
sitBase(3) = &H47B7C4
Dim chessData(1 To 8, 1 To 25) As Byte
Dim x As Integer
Dim y As Integer
Dim s As String
gmeH = FindWindow(vbNullString, gmeCaption)
If gmeH = 0 Then MsgBox "程序未启动!"
GetWindowThreadProcessId gmeH, gmePid
gmePro = OpenProcess(PROCESS_ALL_ACCESS, False, gmePid)
If gmePro = 0 Then MsgBox "进程打开失败!"
ReadProcessMemory gmePro, ByVal sitNumBase, sitNum, 4, readByte
ReadProcessMemory gmePro, ByVal sitBase(sitNum), chessData(8, 25), 200, readByte
'Text2.Text = ""
For y = 1 To 8
s = ""
For x = 1 To 8
s = s + CStr(chessData(8, 25)) + "|"
Text2.Text = s
Next x
Next y
Text1.Text = CStr(sitNum)
CloseHandle gmePid
CloseHandle gmePro
End Sub
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
地确,我这段代码,如果把chessData(8,25)改为chessData(1,8),则可以正确读取第一列的数据,当然,循环语句相应改为:
For y = 1 To 8
s = ""
For x = 1 To 8
s = s + CStr(chessData(x, y)) + "|"
Print
Text2.Text = s
Next x
Next y
可这样的改动也只是能读取这个二维数据中的第一列数据,其他的数据无法读取或显示.换句话说,我觉得ReadProcessMemory函数的声明应该是没有问题的.