当前位置:编程学习 > VB >>

有关vb修改内存的

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 WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, 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 Sub RedTimer_Timer()
Dim hwnd As Long
hwnd = FindWindow("TForm1", "Cheat Engine Tutorial v3")
If (hwnd = 0) Then
MsgBox "没有发现窗口"
Exit Sub
End If
Dim pid As Long
GetWindowThreadProcessId hwnd, pid
Dim pHandle As Long
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle = 0) Then
MsgBox "获取句柄失败"
Exit Sub
End If
End Sub


这个运行之后总是跳出获取句柄失败  我找不出是什么原因   我要找的那个程序也是开着的  就是ce自带的那个~~请大神赐教 --------------------编程问答-------------------- hMine = FindWindow(vbNullString, "扫雷")    '找 扫雷 窗口
    Call GetWindowThreadProcessId(hMine, MineID)    '返回 扫雷 进程的ID,为mineId
    yOffset = 60
    xOffset = 20
    pMine = OpenProcess(PROCESS_VM_READ, True, MineID)             '打开 扫雷 进程
    If pMine = 0 Then
        Call MsgBox("你还没有打开扫雷吧:)", vbInformation, "找不到哦")
        RunMine
        Exit Sub
    End If --------------------编程问答--------------------
Private Sub Command4_Click()
Dim fname As Long
Dim fId As Long
Dim PHandle As Long
fname = FindWindow(vbNullString, "扫雷")
GetWindowThreadProcessId fname, fId
PHandle = OpenProcess(PROCESS_ALL_ACCESS, False, fId)
WriteProcessMemory PHandle, ByVal &H100579C, ByVal VarPtr(0), 4, 0&
CloseHandle PHandle
Debug.Print IIf(UpdateWindow(fname) = 0, "成功", "失败") + fname

End Sub
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,