Solved

ReadProcessMemory

Posted on 2006-11-20
2
1,146 Views
Last Modified: 2008-02-07
Hi,

When using read process memory, here is an example:

dim lngBaseAdd as long
dim lngResult as long
dim lngReadBytes as long

lngBaseAdd = &HF0129F 'or some arbitrary base address

When using the read process memory API you must pass the lngBaseAdd by value, why?

ReadProcessMemory hProcess, lngBaseAdd, lngResult, 4, lngReadBytes '<--- FAILS
ReadProcessMemory hProcess, byVal lngBaseAdd, lngResult, 4, lngReadBytes '<--- WORKS

I dont get why you must pass it by value.



Thanks.
Brian

0
Comment
Question by:BrianGEFF719
2 Comments
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 17983709
Hi
Calling by ref is equal to calling by val using pointer to variable instead of variable itself:

ReadProcessMemory hProcess, lngBaseAdd, lngResult, 4, lngReadBytes

is equal to

ReadProcessMemory hProcess, ByVal VarPtr(lngBaseAdd), lngResult, 4, lngReadBytes

lngBaseAddress is a Long type variable, which is actual virtual address in remote process address space. When you pass it ByVal, you tell ReadProcessMemory API to read remote process memory, starting from this actual address, when pass it ByRef, you send to remote process not actual address, but pointer to your variable (VarPtr(lngBaseAddress)). Remote process get a value from this pointer in its own memory space (which can be 0 or any unpredicable value) and start reading from this value - and fail.
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 17983809
Thanks Ark.


-Brian
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 54
Visual Studio 2005 text editor 10 38
IF ELSE Statement in Excel Macro VBA 16 63
which modules are active in VB6 project? 6 10
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

770 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