在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里不支持,,無法完成內(nèi)存讀寫,在網(wǎng)上查找同樣的問題和方法,,也是無法得到答案,。可在VB2005的幫助給了提示,,成功地完成內(nèi)存的讀寫,。 只要在“WriteProcessMemory”和“ReadProcessMemory”的函數(shù)各多插入一個函數(shù)。方法如下: 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”就可以了,。 測試后,成功通過內(nèi)存讀寫。 |
|