On 07/01/2014 11:53 AM, Jonas Maebe wrote:
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).
Thanks Jonas for the help! This now works for me in FPC (MyReturnStr is
PChar):
Status := ps5000aGetUnitInfo( ps5000a_handle, @MyReturnStr[ 0],
StringLen, requiredSize, RInfo);
But in D7 using "@MyReturnStr[ 0]" gives an Access violation exception
in the dll. The address the DLL is trying to write is about the same as
in FPC so I still don't understand why FPC works but D7 doesn't.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal