在VB6中: 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 WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Integer, lpNumberOfBytesWritten As Integer) As Integer
但 As Any 在VB2005里不支持,无法完成内存读写,在网上查找同样的问题和方法,也是无法得到答案。可在VB2005的帮助给了提示,成功地完成内存的读写。 只要在“WriteProcessMemory”和“ReadProcessMemory”的函数各多插入一个函数。方法如下: Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As String, ByRef lpBuffer As String, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
“As Any”,可是“String ”也可是 “Integer”所以一条的“As Any ”改为“As String”,另一条“As Any”改为“As Integer”就可以了。 测试后,成功通过内存读写。 |
|