Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB:readprocessmemory

Posted on 2004-09-11
5
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 28

Accepted Solution

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

Expert Comment

by:AzraSound
ID: 12559775
Points to AzraSound
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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