ReadProcessMemory的问题 超级绿豆 其他人都近来看看啊
看一下以下代码错在哪里 谢谢
代码目的是获取另一进程状态栏某1面板的文本
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 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 VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) 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 VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
Const PROCESS_ALL_ACCESS = &H1F0FFF
Const cBuf = 1024
Const MEM_COMMIT = &H1000
Const MEM_DECOMMIT = &H4000
Const PAGE_READWRITE = &H4&
Const WM_USER = &H400
Const SB_GETPARTS = (WM_USER + 6)
Const SB_GETTEXT = (WM_USER + 2)
Dim hMain As Long
Dim idProcess As Long
Dim hProcess As Long
Dim pBuf As Long
Dim hStatus As Long
Dim s As String * cBuf
Private Sub Command1_Click()
hMain = FindWindowEx(0, 0, "TMainForm", "窗口标题")
If hMain = 0 Then End
hStatus = FindWindowEx(hMain, 0, "TStatusBar", "")
If hStatus = 0 Then End
GetWindowThreadProcessId hMain, idProcess
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, idProcess)
If hProcess = 0 Then End
pBuf = VirtualAllocEx(ByVal hProcess, ByVal 0&, Len(s), MEM_COMMIT, PAGE_READWRITE)
If pBuf = 0 Then End
n = SendMessage(hStatus, SB_GETTEXT, 2, ByVal pBuf)
Dim nn As Long
nn = ReadProcessMemory(ByVal hProcess, pBuf, s, Len(s), ByVal 0)
VirtualFreeEx hProcess, ByVal pBuf, 0, MEM_DECOMMIT
If nn <> 0 Then Me.Print s
End Sub