哪位仁兄帮忙看看下面代码哪出问题,ReadProcessMemory每次读取都是0,用GetLastError()每次都是显示299。
想做一个小游戏的修改器,读取的内存地址为0043E13C。
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 Any, ByVal 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 Declare Function GetLastError Lib "kernel32" () As Long
Dim GameHwnd As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Sub Timer1_Timer()
GameHwnd = FindWindow(vbNullString, "ywne")
Dim GamePid As Long, GPPid As Long, a As Long
If GameHwnd > 0 Then
GetWindowThreadProcessId GameHwnd, GamePid
GPPid = OpenProcess(PROCESS_ALL_ACCESS, False, GamePid)
ReadProcessMemory GPPid, &H43E13C, a, 4, 0&
MsgBox GetLastError()
CloseHandle GPPid
Label1.Caption = Str(a)
End If
End Sub
想做一个小游戏的修改器,读取的内存地址为0043E13C。
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 Any, ByVal 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 Declare Function GetLastError Lib "kernel32" () As Long
Dim GameHwnd As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Sub Timer1_Timer()
GameHwnd = FindWindow(vbNullString, "ywne")
Dim GamePid As Long, GPPid As Long, a As Long
If GameHwnd > 0 Then
GetWindowThreadProcessId GameHwnd, GamePid
GPPid = OpenProcess(PROCESS_ALL_ACCESS, False, GamePid)
ReadProcessMemory GPPid, &H43E13C, a, 4, 0&
MsgBox GetLastError()
CloseHandle GPPid
Label1.Caption = Str(a)
End If
End Sub
解决方案 »
- SOS,VB求助
- 我的程序应该怎么改?如何实现"打开对话框"那样,窗体以外部分不接受操作?
- 三层结构中,中间层和客户端必须用Windows的透明验证吗?
- 哪种数据报表可以实现数据分栏打印????
- 喂!你们发布软件时是怎么填写的啊?软件包是怎么送上去的呀?为什么我的总是“未发布”?
- 哈哈我又有问题了。如何在代码里添加DataEnvironment1的connection
- 在VB中如何连接远程ORACLE数据库(没有安装ORACLE客户端),小弟菜鸟,请大侠帮忙!
- 100分求一份重要资料!
- 找高手解决webbrowser控件问题
- 如何将打印在Picbox 里的文字打印出来?比如将picbox 作为容器,里面设置两个label 控件,如何将用最简单的办法打印出来?
- 准备回去过春节了 先挂个喜庆贴 散粉了...
- VB注册组件
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 Any, ByVal 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 Declare Function GetLastError Lib "kernel32" () As Long
Dim GameHwnd As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF'修改API声明
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long _
, lpBaseAddress As Any _
, lpBuffer As Any _
, ByVal nSize As Long _
, lpNumberOfBytesWritten As Long _
) As LongPrivate Sub Command1_Click()
GameHwnd = FindWindow(vbNullString, "Form1")
Dim GamePid As Long, GPPid As Long
Dim a(100) As Byte '修改接收变量的类型
If GameHwnd > 0 Then
GetWindowThreadProcessId GameHwnd, GamePid
GPPid = OpenProcess(PROCESS_ALL_ACCESS, False, GamePid)
Dim i As Long
i = ReadProcessMemory(GPPid, ByVal &H43E13C, a(0), 100, 0&)
CloseHandle GPPid
Label1.Caption = StrConv(a, vbUnicode)
End If
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 Long2.修改了接受变量的类型.Dim a(100) As Byte '修改接收变量的类型
3.修改了调用i = ReadProcessMemory(GPPid, ByVal &H43E13C, a(0), 100, 0&)
谢谢Lost_Painting的修改,不过还是不行啊。