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, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal _ hProcess As Long, ByVal 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 Const PROCESS_ALL_ACCESS = &H1F0FFF Dim hh As Long Dim pp As Long Dim pp2 As Long
Private Sub Command1_Click() dim str as string str="red alert 2" '此为游戏窗体名称,视游戏的不同而改变 hh = FindWindow(vbNullString, str) If hh <> 0 Then GetWindowThreadProcessId hh, pp pp2 = OpenProcess(PROCESS_ALL_ACCESS, False, pp) If pp2 <> 0 Then WriteProcessMemory pp2, &H4E4B89, &H90, 1, 0 '如果为ADD指令则为WriteProcessMemory pp2, &H4E4B89, &H03, 1, 0 WriteProcessMemory pp2, &H4E4B8A, &H90, 1, 0 '如果为ADD指令则为WriteProcessMemory pp2, &H4E4B8A, &H27, 1, 0
CloseHandle (pp2) Else MsgBox "打开进程失败", , "红警修改器" End If Else MsgBox "请先运行红色警戒2", , "红警修改器" End If End Sub