1
votes

So i'm getting this error message, can someone help me, already tried a lot of google answers :p nothing worked.

ctrl+shift+space result on ReadProcessMemory

**Parameters** 
hProcess System.Cardinal 
IpBaseAddress System.Pointer 
IpBuffer System.Pointer 
nSize System.Cardinal 
IpNumberOfBytesRead System.Cardinal 
**Returns** 
System.Boolean 

Ptr Function:

Ptr Function: function Ptr(Value: Integer): Pointer;  

Variables

var 
  Form1: TForm1; 
  PH : THandle; 
  PID, ThID: DWORD; 
  H : THandle;

function Ptr(Value: Integer): Pointer;

Function

function LerInt(Address: Integer): Integer;
var
  value:integer;
  ler:dword;
begin
  H := FindWindow(nil, 'Something Here :)');
  ThID := GetWindowThreadProcessID(H, @PID);
  PH := OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
  ReadProcessMemory(PH, Ptr(Address), @value, 4, ler); // THIS LINE
  Result:=value;
end;
1
It means that you put argument of wrong type to one of functions here (the one to which compiler points you). Point is: if you have procedure (i: Integer), you can call it passing byte, shortint, Word, Integer after all and compiler will cast you argument to the type procedure needs. But if you have procedure (var i: Integer), you must pass STRICTLY Integer and nothing more. So, look exact types of arguments and compare with what you write here. - Yuriy Afanasenkov
It would be easy to answer exactly what argument here is wrong, if you provided us with exact line where this error arised and types of variables we don't know as H, ThID, PH. Telepaths are on their way of course, but please don't rely on them too much. - Yuriy Afanasenkov
The compiler tells you exactly what line is causing the problem, and using Code Insight (Ctrl+Shift+Space between the function parameter parens) tell you exactly what the datatype is that is expected for each parameter. As you've not bothered to either include the line number for the error or indicate which line is the issue, use the information I just gave you to figure it out yourself. :-) IOW, there's absolutely no reason for you not to identify the specific problem area for us, since it's right on your screen in front of you. - Ken White
You've also not bothered to indicate what some of the variable types are that you're using (eg., H, ThID, PH, PID). If you want help from us, give us the information you already have. You're asking for free help from us to solve a problem you're having - you should make it as easy as possible for us to do so. - Ken White
Another important missing piece is what Ptr is. Your lack of error checking is going to come back to haunt you. Win32 API calls won't throw exceptions. You have to check for errors. I say this at least 10 times a day. - David Heffernan

1 Answers

3
votes

The variable ler is the wrong type. It must be SIZE_T.

Other comments:

  1. You don't need a function to convert an integer to a pointer. Just cast it with Pointer(address). Note though that you will encounter pointer truncation problems if you ever pass this code through the 64 bit compiler.
  2. You do not check for errors in any of your API calls. Please check for errors.