Reputation: 830
I have used RRUZ's solution to improve the look of disabled images. The excerpt below, as example, however:
procedure HookProc(Proc, Dest: Pointer; var BackupCode: TXRedirCode);
var
n: DWORD;
Code: TXRedirCode;
begin
Proc := GetActualAddr(Proc);
Assert(Proc <> nil);
if ReadProcessMemory(GetCurrentProcess, Proc, @BackupCode, SizeOf(BackupCode), n) then
begin
Code.Jump := $E9;
Code.Offset := PAnsiChar(Dest) - PAnsiChar(Proc) - SizeOf(Code);
WriteProcessMemory(GetCurrentProcess, Proc, @Code, SizeOf(Code), n);
end;
end;
worked well with Delphi 2007, but when I use it in Delphi XE10 I get
E2033 Types of actual and formal var parameters must be identical
when calling ReadProcessMemory and WriteProcessMemory
As far as I an see the types are the same. Can anyone advise me what' need to change?
Upvotes: 1
Views: 2030
Reputation: 612954
E2033 Types of actual and formal var parameters must be identical
The documentation says:
For a variable parameter, the actual argument must be of the exact type of the formal parameter.
In other words, you encounter this error when an argument that you are passing to a var
parameter has a type that is not identical to that in the function's declaration.
To solve the problem, the first step is to find the declaration of the function that you are calling. Then you need to compare its argument list with the arguments that you are passing.
In your case, these two functions are in Winapi.Windows.pas
(the IDE hover hints tell you that) and look like this:
function ReadProcessMemory(hProcess: THandle; const lpBaseAddress: Pointer;
lpBuffer: Pointer; nSize: SIZE_T; var lpNumberOfBytesRead: SIZE_T): BOOL; stdcall;
function WriteProcessMemory(hProcess: THandle; const lpBaseAddress: Pointer;
lpBuffer: Pointer; nSize: SIZE_T; var lpNumberOfBytesWritten: SIZE_T): BOOL; stdcall;
The only var
parameters are the final parameter of each function which immediately pinpoints the problem. But more generally, if a function has multiple var
parameters then you would have to consider each one in turn.
The final parameter for these two functions now has type SIZE_T
. The code you refer to uses DWORD
. Change the type of the variable being passed to SIZE_T
and you will solve the problem.
Upvotes: 5