Solved

VB:readprocessmemory

Posted on 2004-09-11
5
318 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

830 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