[fpc-pascal] DLL call works on FPC 2.6.4 but not with D7

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Jul 1 17:53:26 CEST 2014

On 01/07/14 17:27, Paul Breneman wrote:
> Sorry, but after I sent the email above I realized that I was editing a
> file in the wrong folder.  Free Pascal doesn't work with "var" on the
> line below:
>    var str : Pchar;
> This is what works on FPC 2.6.4:
> function ps5000aGetUnitInfo
>           (handle : smallInt;
>            Str : Pchar;
>            stringLength : smallInt;
>            var requiredSize : smallInt;
>            info : integer
>            ) : integer;
> {$IFDEF WIN32} stdcall; external 'ps5000a.dll';{$ENDIF}

It will work in both FPC and Delphi if you pass @MyReturnStr[1], 
provided that the length of MyReturnStr is sufficiently large. When 
dealing with addresses to strings/arrays, always explicitly specify the 
first element you want to use rather than the entire string/array. That 
will always work regardless of the string or array type 
(static/dynamic/open/... array, ansi/short/wide/..., and even pchar).


More information about the fpc-pascal mailing list