Private Declare Function GetWindowThreadProcessId Lib "user32" ( ByVal hWnd As Long , lpdwProcessId As Long ) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( ByVal lpClassName As String , ByVal lpWindowName As String ) 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
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or &HFFF )
Private Sub Form_Load()
Dim hWnd As Long
Dim pid As Long
Dim hProcess As Long
Dim h As Long
Dim addr As Long
Dim buffer( 31 ) As Byte
hWnd = FindWindow(vbNullString, "Element Client" )
If hWnd Then
GetWindowThreadProcessId hWnd, pid
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False , pid)
If hProcess Then
addr = &H12F82C
ReadProcessMemory hProcess, ByVal addr, h, 4 , 0 &
ReadProcessMemory hProcess, ByVal (h + &H24 ), h, 4 , 0 &
ReadProcessMemory hProcess, ByVal (h + &H390 ), h, 4 , 0 &
ReadProcessMemory hProcess, ByVal h, buffer( 0 ), 32 , 0 &
CloseHandle hProcess
End If
Text1.Text = buffer
End If
End Sub
结束
读角色名时并没有先读取长度,因为本身就是0结尾U串,没必要。
结果也证明是对的。
如果有朋友老是出现无法读值的问题,一般来说是你搞错了传值传址的问题。