Solved

VB:readprocessmemory

Posted on 2004-09-11
5
311 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA : retain and exclude values based on a config sheet and multiple parameters 5 52
VB6 Compile Compatibility Issue 4 89
VBA filters 2 50
Child Form in front 4 38
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now