代码如下,目标是显示游戏里人物的金币数,完美游戏的基址刚算了几遍没错,金钱的偏移也没错,就是读不出游戏中人物的金币数。目前确认游戏窗口的进程pid没错,到进程句柄这以后就不知道对不对了,高手帮忙分析下
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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, ByVal lpBaseAddress As Long, ByVal lpBuffer As Byte, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
Const W2i_Base = &HA5BFCC
Private Sub Command1_Click()
Dim hwnd As Long
Dim pid As Long
Dim hprocess As Long
Dim ECXI As Long
Dim ECXIA As Long
Dim eax As Long
hwnd = FindWindow("ElementClient Window", "完美世界国际版")
GetWindowThreadProcessId hwnd, pid
hprocess = OpenProcess(&H1F0FFF, 0, pid)
If hprocess = 0 Then
Exit Sub
End If
'----金币信息---------------------------------------------
ReadProcessMemory hprocess, ByVal W2i_Base, ECXI, 4, 0
ReadProcessMemory hprocess, ByVal ECXI + &H20, ECXIA, 4, 0
ReadProcessMemory hprocess, ByVal ECXIA + &H538, eax, 4, 0
Me.Caption = "金钱:" & CStr(eax)
Text1.Text = CStr(eax)
End Sub
|