怎么样使读取内存出来的是数字Private Sub Timer1_Timer()Dim pHandle As LongD

1个回答

  • BOOL WINAPI ReadProcessMemory(

    __in HANDLE hProcess,

    __in LPCVOID lpBaseAddress,

    __out LPVOID lpBuffer,

    __in SIZE_T nSize,

    __out SIZE_T *lpNumberOfBytesRead

    );

    因此,你的代码应为:

    Private Sub Timer1_Timer()

    Dim pHandle As Long

    Dim buf As Long

    pHandle = OpenProcess(PROCESS_ALL_ACCESS,False,pid)

    If (pHandle = 0) Then Exit Sub

    ReadProcessMemory pHandle,&H841040,byval varptr(buf),4,0&

    txtDisplay = CStr(buf)

    CloseHandle hProcess

    End Sub

    这里是读一个Long的长度

    如果要读取一组内存数据到一个数组,则为:

    Private Sub Timer1_Timer()

    Dim pHandle As Long

    Dim buf() As Byte

    Const Size as long=20 '20 bytes

    redim buf(0 to size-1)

    pHandle = OpenProcess(PROCESS_ALL_ACCESS,False,pid)

    If (pHandle = 0) Then Exit Sub

    ReadProcessMemory pHandle,&H841040,byval varptr(buf(0)),size,0&

    '此时,buf(0 To (Size-1))保存了内存偏移量0x841040中Size大小的数据

    CloseHandle hProcess

    End Su