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 ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPrivate Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'提升权限
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private ipd As Long
Private hwdn As Long
Private pen As Long
Private xia As Long
Private h As Long
Private Sub Command1_Click()
hwdn = FindWindow(vbNullString, "计算器")
Call GetWindowThreadProcessId(hwdn, ipd)
pen = OpenProcess(PROCESS_ALL_ACCESS, False, ipd)
ReadProcessMemory pen, ByVal &H77F344A4, ByVal xia, 4, 0&
h = GetLastError()
Print xia
CloseHandle pen
End Sub
问题在哪啊? 

解决方案 »

  1.   

    OpenProcess(PROCESS_VM_READ,True,ipd),把False改成True
    这样才可以读取PROCESS_VM_READ=&H10&
      

  2.   

    没学基础扎实就去读内存,比如连Byte数组都不懂如何操作就去操作其他进程内存,死的很惨。
      

  3.   

    ReadProcessMemory pen, ByVal &H77F344A4, ByVal xia, 4, 0&
    这句有问题的说
      

  4.   

    貌似 xia 这个应该是个数组  我改了好多次 一直返回0
      

  5.   

    小弟 学习 内存读取  代码写的 寒酸  不过看的方便 望了解 ReadProcessMemory 正确试用方法的大侠 给指条明路。 实在是对这个函数的用法搞不清楚。
      

  6.   

    从写了一下代码 谁给看看 还是返回0
    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 CloseHandle Lib "kernel32" (ByVal hObject 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
    Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    Private Sub Command1_Click()
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, "计算器")
    Dim pid As Long
    Call GetWindowThreadProcessId(hwnd, pid)
    Dim hprocess As Long
    hprocess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    Dim lon As Byte
    ReadProcessMemory pid, &H77F344A4, lon, 4, 0&
    Print lon
    CloseHandle hprocess
    End Sub