请教vb.net下 readprocessmemory一些问题 里有代码
vb6代码
如下:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesRead As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten 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 GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Dim jcm As Long
Dim jcpid As Long
Dim dujc As Long
jcm = FindWindow(vbNullString, "游戏名")
If jcm = 0 Then
Form1.Caption = "游戏未启动,请开启在试"
Else
Form1.Caption = "游戏启动成功"
End If
GetWindowThreadProcessId jcm, jcpid
dujc = OpenProcess(PROCESS_ALL_ACCESS, False, jcpid)
ReadProcessMemory dujc, ByVal dizhi, dxue, 4, 0&
dxue = &H8FC4 + &H314 + dxue
ReadProcessMemory dujc, ByVal dxue, dxue, 4, 0&
label1.caption=dxue
显示成功
vb.net 下代码如下:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function OpenProcess Lib "kernel32.dll" Alias "OpenProcess" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Integer, ByVal dwSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Dim jcm As Integer
Dim jcpid As Integer
Dim dujc As Integer
Dim dxue As Integer
jcm = FindWindow(vbNullString,"游戏名" )
If jcm > 0 Then
Me.Text = "启动成功"
GetWindowThreadProcessId(jcm, jcpid)
If jcpid > 0 Then
dujc = OpenProcess(PROCESS_ALL_ACCESS, 0, jcpid)
If dujc = 0 Then
Else
ReadProcessMemory(dujc, &H99D8B8, dxue, 4, 0&)
dxue=dxue + (&H8FC4 + &H314)
ReadProcessMemory(dujc, dxue,dxue, 4, 0&)
label1.Text = CInt(dxue)
End If
End If
End If
无法显示 显示为0 读不内存
忘高手指教下!!!!