[fpc-pascal] Free Pascal bindings for EyeLink C code (with a god-cast)
Rafael Picanço
cpicanco42 at gmail.com
Tue Jun 13 05:19:10 CEST 2023
Hi everyone,
First of all, I am sorry if this is not the best place for this
interoperability issue.
The problem I want to solve is how to make a Free Pascal binding for to the
following piece of C code:
typedef struct _CCDBS {
void *userdata;
char buttons[256];
void *internal;
}CCDBS;
typedef int (ELCALLBACK *getExButtonStates)(CCDBS *);
#define EXTERNAL_DEV_NONE ((getExButtonStates)0)
#define EXTERNAL_DEV_CEDRUS ((getExButtonStates)1)
#define EXTERNAL_DEV_SYS_KEYBOARD ((getExButtonStates)2)
int ELCALLTYPE enable_external_calibration_device(getExButtonStates
buttonStatesfcn, const char * config, void *userData);
Questions
(1) I have no idea on how to translate these god-casts, eg.,
((getExButtonStates)0), to free pascal. Right now, I think that even if I
don't really need them, I just want to understand and learn in the process.
(2) So, the whole point here is binding the
"enable_external_calibration_device" function. It expects a
"getExButtonStates buttonStatesfcn". Can you check if my current binding is
right?
type
PCCDBS = ^TCCDBS;
TCCDBS = record
userdata: Pointer;
buttons: array[0..255] of Char;
internal: Pointer;
end;
TGetExButtonStatesFunction = function (accdbs: PCCDBS): Int32; ELCALLTYPE
function enable_external_calibration_device(
buttonStatesfcn: TGetExButtonStatesFunction;
config: PChar; userData: Pointer): Int32; ELCALLTYPE ELDLL
(3) I am using the ELCALLTYPE macro just because they were using them
too, I am assuming backward compatibility. But I am not sure if I really
need them. EyeLink code depends on custom SDL2 headers and I am running
SDL2 Free Pascal related stuff just fine (and it has cdecl in everything).
What do you think about that? For reference, this is the macro:
{$ifndef ELCALLTYPE}
{$IFDEF Windows}
{$DEFINE ELCALLTYPE := stdcall;}
{$ELSEIF Linux}
{$DEFINE ELCALLTYPE := cdecl;}
{$ELSE}
{$DEFINE ELCALLTYPE := cdecl;}
{$ENDIF}
{$endif}
(4) I can send the code and soon will release it on my GitHub (cpicanco).
Best.
R
PS.: You can find a related discussion here
https://stackoverflow.com/questions/76427311/free-pascal-bindings-for-a-typedef-function-inside-a-define-macro-and-a-number-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230613/736b36de/attachment-0001.htm>
More information about the fpc-pascal
mailing list