tags:

views:

667

answers:

1

Hello,

I tried using both ReadProcessMemory() and WriteProcessMemory() in my application,but in both cases I get one result - Only part of a ReadProcessMemory or WriteProcessMemory request was completed.

Has anyone met that error code before? I'm using Vista SP2,I tried to run as admistrator,but I till get that erorcode.

+1  A: 

Make sure you call VirtualProtectEx to set the correct protection level on the memory you want to read/write.

After thinking about it, it's probably not the problem since most memory has read access enabled, but to set the protection level do something like this (in C++)

(no error checking and just using a random memory address, but you should get the idea)

char buffer[256];
DWORD oldProtect = 0;
DWORD numRead = 0;
VirtualProtectEx( hProc, (LPVOID)0x77810F34, 256, PAGE_EXECUTE_READWRITE, &oldProtect );
ReadProcessMemory( hProc, (LPVOID)0x77810F34, buffer, 256, &numRead );
VirtualProtectEx( hProc, (LPVOID)0x77810F34, 256, oldProtect, NULL ); //restore the original protection when you're done
Gerald
Do I have to call it on all the addresses or can I call it for whole process memory? could you show an example,please!
John
It will most likely fail if you try to call it for the whole process memory, so you should call it for just the memory you want to access.
Gerald
But it may be that you're not passing a valid argument in one of the slots, so it would be a good idea to post some of your code, even if it's in Delphi, if this isn't the problem.
Gerald
@Gerald,Thank you!
John