Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadProcessMemory() Error

Status
Not open for further replies.

granddemon

IS-IT--Management
Mar 25, 2005
9
US
I am testing out the ReadProcessMemory and WriteProcessMemory functions just for fun (I believe I am going to have to use them in the future, so I am just practicing with them now), but ReadProcessMemory always returns an error. It only returns a 0, so I have no idea what that means or what went wrong. Here is the code snippet I am using:

----------------------------------------------------

int addr = 0x400000;
BYTE buffer = 0;
bool dummy = true;
if (ReadProcessMemory(Process.m_hProcess,(void*)addr,&buffer,1,NULL) == 0) {
MessageBox("There was an error reading the process's memory","Error",MB_ICONWARNING);
init_passed = false;
break;
}

--------------------------------------------------

As you probably guessed, my error message box is popping up.

I am hoping to read one byte starting at the beginning of the process (0x400000) just to see it work, but I can't even get that going. Process.m_hProcess should contain the right information (I debugged the program and it contains 0x000007c4 which I assume is the right value for my other window...). I figure the problem is probably something with either my buffer or addr variable as I was unsure what to do with those.

Any pointers in the right direction would be greatly appreciated. :) Thanks infinitely in advance,

GrandDemon
 
Do you have the appropriate rights to read other's process memory?
Try to use GetLastError to obtain the error code and then FormatMessage to translate this error code to human readable error description. Then, post a reply to this topic with the error message.
 
Thanks a lot! That actually did solve the problem. When I was opening the handle I specified the privileges as PROCESS_VM_READ or PROCESS_VM_WRITE, but changing it to PROCESS_ALL_ACCESS fixed my problem. I wonder why the first one didn't open it for Read/write access like expected...?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top