<div dir="ltr"><div>Thank you Marco, I am elaborating on top of your suggestions.</div><div dir="ltr"><br></div><div dir="ltr">> The problem is that the logical solution, making it a macro, doesn't<br>work, as macro definitions don't export through USES clauses.<br></div><div><br></div><div>I think that pre-processor constants with $I would be a valid alternative for using the best solution. For example:</div><div><br></div><div>// constants.pp</div><div>____</div><div>{$MACRO ON}<br>{$ifndef EXTERNAL_DEV_NONE}<br>  {$DEFINE EXTERNAL_DEV_NONE := TGetExButtonStatesFunction(Pointer(0))}<br>{$endif}<br>{$ifndef EXTERNAL_DEV_CEDRUS}<br>  {$DEFINE EXTERNAL_DEV_CEDRUS := TGetExButtonStatesFunction(Pointer(1))}<br>{$endif}<br>{$ifndef EXTERNAL_DEV_SYS_KEYBOARD}<br>  {$DEFINE EXTERNAL_DEV_SYS_KEYBOARD := TGetExButtonStatesFunction(Pointer(2))}<br>{$endif}  <br></div><div>____<br></div><div><br></div><div>program godcastsucks;<br><br>{$I constants}<br><br>type<br><br>  PCCDBS = ^TCCDBS;<br>  TCCDBS = record<br>    userdata: Pointer;<br>    buttons: array[0..255] of AnsiChar;<br>    internal: Pointer;<br>  end;<br><br>  TGetExButtonStatesFunction = function (accdbs: PCCDBS): Int32; cdecl;<br><br>  function enable_external_calibration_device(<br>    buttonStatesfcn: Pointer {other arguments removed for simplicity}): Int32; cdecl;<br>  var<br>    Statesfcn : TGetExButtonStatesFunction;<br>  begin<br>    Result := Int32(TGetExButtonStatesFunction(@buttonStatesfcn^));<br>    case Result of<br>      0 : { do nothing };<br>    else<br>      begin<br>        Statesfcn := TGetExButtonStatesFunction(buttonStatesfcn);<br>        Statesfcn(nil);<br>        Result := -1;<br>      end;<br>    end;<br>  end;<br><br>function ExButtonStatesFunction(accdbs: PCCDBS): Int32; cdecl;<br>begin<br>  WriteLn('God casts sucks');<br>end;<br><br>begin<br>  WriteLn(enable_external_calibration_device(EXTERNAL_DEV_NONE));<br>  WriteLn(enable_external_calibration_device(@ExButtonStatesFunction));<br>  ReadLn;<br>end.<br></div><div>____ </div><div><br></div>> Note that an alternative for this macro exists since FPC 3.2.0:<div><br></div><div>Thank you for the reference!</div><div><br></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 13, 2023 at 7:00 AM <<a href="mailto:fpc-pascal-request@lists.freepascal.org">fpc-pascal-request@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send fpc-pascal mailing list submissions to<br>
        <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:fpc-pascal-request@lists.freepascal.org" target="_blank">fpc-pascal-request@lists.freepascal.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:fpc-pascal-owner@lists.freepascal.org" target="_blank">fpc-pascal-owner@lists.freepascal.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of fpc-pascal digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re:  Free Pascal bindings for EyeLink C code (with a<br>
      god-cast) (Marco van de Voort)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Tue, 13 Jun 2023 11:25:13 +0200<br>
From: Marco van de Voort <<a href="mailto:fpc@pascalprogramming.org" target="_blank">fpc@pascalprogramming.org</a>><br>
To: <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
Subject: Re: [fpc-pascal] Free Pascal bindings for EyeLink C code<br>
        (with a god-cast)<br>
Message-ID:<br>
        <<a href="mailto:5a5a8eac-e91d-d9d7-4131-d7301ec3c4d3@pascalprogramming.org" target="_blank">5a5a8eac-e91d-d9d7-4131-d7301ec3c4d3@pascalprogramming.org</a>><br>
Content-Type: text/plain; charset=UTF-8; format=flowed<br>
<br>
<br>
On 13-6-2023 05:19, Rafael Pican?o via fpc-pascal wrote:<br>
> (1) I have no idea on how to translate these god-casts, eg., <br>
> ((getExButtonStates)0), to free pascal. Right now, I think that even <br>
> if I don't really need them, I just want?to understand and learn <br>
> in?the?process.<br>
<br>
The problem is that the logical solution, making it a macro, doesn't <br>
work, as macro definitions don't export through USES clauses.<br>
<br>
Defining it a proper constant would be the best solution, but FPC <br>
doesn't like it :<br>
<br>
const<br>
<br>
 ?EXTERNAL_DEV_NONE = TGetExButtonStatesFunction(pointer(0));<br>
<br>
so the next best is turning it into a type constant at the expense of <br>
sizeof(pointer) bytes in the binary:<br>
<br>
const<br>
<br>
 ? EXTERNAL_DEV_NONE : TGetExButtonStatesFunction= pointer(0);<br>
<br>
etc etc.<br>
<br>
><br>
> (2) So, the whole point here is?binding the <br>
> "enable_external_calibration_device" function. It expects a <br>
> "getExButtonStates buttonStatesfcn". Can you check if my current <br>
> binding is right?<br>
><br>
A purist would say it needs to be "ansichar" rather than char (because <br>
in future unicode modes char could be 2-byte, for the rest it seems ok.<br>
<br>
> (3) I am using the?ELCALLTYPE?macro just because?they were?using them <br>
> too,?I am assuming backward compatibility. But I am not sure if I <br>
> really need them. EyeLink code depends on custom SDL2 headers and I <br>
> am?running SDL2 Free Pascal related stuff just fine (and it has cdecl <br>
> in everything). What do you think about that? For reference, this is <br>
> the macro:<br>
><br>
You must match the calling convention of the implementation. Some <br>
functions have target dependent calling conventions, some non native <br>
libraries force cdecl even on Windows. (where stdcall or fastcall is <br>
more conventional)<br>
<br>
Note that an alternative for this macro exists since FPC 3.2.0:<br>
<br>
<a href="https://wiki.freepascal.org/FPC_New_Features_3.2.0#Support_for_WinAPI_directive" rel="noreferrer" target="_blank">https://wiki.freepascal.org/FPC_New_Features_3.2.0#Support_for_WinAPI_directive</a><br>
<br>
Even though the naming is not "elegant" for crossplatform usage.<br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
<br>
<br>
------------------------------<br>
<br>
End of fpc-pascal Digest, Vol 228, Issue 14<br>
*******************************************<br>
</blockquote></div></div></div>