[fpc-pascal] Does the varargs specifier behave differently on 32 and 64 bit platforms?

Thomas Kurz fpc.2021 at t-net.ruhr
Fri Jan 5 14:38:48 CET 2024


Hello,

I'm using a declaration like this

TYPE TRSMControl = FUNCTION (AData: PtrInt): PtrInt; CDECL; VARARGS;
VAR RSMControl: TRSMControl;

to make calls to a DLL function which expects a variable number of arguments. For example:

RSMControl (PtrInt(1), PtrInt(2), PtrInt(3))

On win32, this works fine. On win64, I get only the first argument correctly, the rest is garbage. Within the DLL, I subsequently access all parameters by taking the address of the first parameter and incrementing it in steps of 4 bytes (or 8 bytes on win64).

I wonder whether I'm doing something wrong on the caller or callee side. The code worked reliably on win32, but I'm now trying to target win64 and am facing the problem that I cannot access the data that were passed. The CDECL calling convention should pass all arguments on the stack, and I expect subsequent arguments to be at subsequent memory addresses.

Does anyone have a clue for me?

Kind regards,
Thomas



More information about the fpc-pascal mailing list