|
|
按照一个范例进行找窗口读进程的制作,函数代码如下
建立一个文本框,按钮,时钟,在程序运行的时候出现了这么一句话:"Couldn't get a process handle!",调试时发现错在Timer中,但就是找不出原因,请哪位大哥帮我?或者发个修改器制作的范例,谢谢!我这里只是初步的找窗口,读进程,还需要大哥的指点```
类模块的代码
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal IpClassName As String, ByVal IpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, IpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal IpBaseAddress As Any, ByVal IpBuffer As Any, ByVal nSize As Long, IpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal IpBaseAddress As Any, ByVal IpBuffer As Any, ByVal nSize As Long, IpNumberOfBytesWritten As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
工程代码
Private Sub Command1_Click()
Dim hwnd As Long
Dim pid As Long
Dim pHandle As Long
hwnd = FindWindow(vbNullString, "Resident Evil 3")
If (hwnd = 0) Then
MsgBox "Window not found!"
Exit Sub
End If
GetWindowThreadProcessId hwnd, pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle = 0) Then
MsgBox "Couldn't get a process handle!"
Exit Sub
End If
WriteProcessMemory pHandle, &HA62285, "Beans", 5, 0&
CloseHandle hProcess
End Sub
Private Sub Timer1_Timer()
Dim hwnd As Long
Dim pid As Long
Dim pHandle As Long
Dim str As String * 20
hwnd = FindWindow(vbNullString, "Resident Evil 3")
If (hwnd = 0) Then Exit Sub
GetWindowThreadProcessId hwnd, pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle = 0) Then Exit Sub
ReadProcessMemory pHandle, &HA62285, str, 30, 0&
Text1 = str
CloseHandle hProcess
End Sub
[em24] |
|