Solved

VB:readprocessmemory

Posted on 2004-09-11
5
314 Views
Last Modified: 2010-05-02
im trying to use readprocess memory to read a value in another process's memory
ive got it to work in visual c++ so i know the address is correct and im going about it the right way
anyway heres my code (uses 4 text boxes and a button)
when i use this the window is found and a handle is created but the value input to the buffer after readprocessmem is incorrect
and if i keep pressing the button the value changes, most of the time it is either 127 or 0, and will alternate after each press
---------------------------------

Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
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 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 WriteString Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'Private Declare Function WriteValue Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub get_Click()
Dim bytvalue As Long
Dim phandle As Long
Dim res As Long

    res = FindWindow(vbNullString, "MyApp")
    Text2 = res
    If res = 0 Then
        MsgBox "Could not find window"
    End If
     
    GetWindowThreadProcessId res, pId
   
    Text3 = pId
   
    phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
   
    Text4 = phandle
   
    If (phandle = 0) Then
         GoTo die
    End If
   
    tmp = ReadProcessMemory(phandle, "532E8C", bytvalue, 1, 0&)
   
    Text1 = bytvalue
   
   
die:

End Sub
0
Comment
Question by:tsukasa
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 12037052
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 12559775
Points to AzraSound
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question