VB中知道了内存地址,怎么把数据保存到这个内存地址所对应的内存中?
比如,我知道了12345678是个地址,我怎么把一个变量存到这个地址对应的空间中?

解决方案 »

  1.   

    呵呵,楼上说得对在Windows中,每个应用程序都享有独立的2GB内存空间,使每个进程的地址空间对另一个进程完全不可见,相互间不影响。同时Windows也提供了一系列访问进程内存空间的函数,在VB中的声明如下:
    Private Declare Function OpenProcess Lib "KERNEL32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long ’打开进程用于访问
    Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long ’释放句柄
    Private Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long ’向目标进程中写入内存
    Private Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten 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 VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long ’释放分配的内存
      

  2.   

    如果是本进程内的地址用CopyMemory就行了.