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

Sven Barth pascaldragon at googlemail.com
Tue Jul 1 23:15:58 CEST 2014

Am 01.07.2014 20:59 schrieb "Jonas Maebe" <jonas.maebe at elis.ugent.be>:
> On 01/07/14 19:42, Paul Breneman wrote:
>> I'm doing the same thing in FPC and D7:
>>        StringLen := 14;
>>        MyReturnStr := 'test1234567890';
>>        Status := ps5000aGetUnitInfo( ps5000a_handle, @MyReturnStr[ 0],
>> StringLen, requiredSize, RInfo);
> It wrong in both FPC and D7 (and it will also crash on all platforms in
the next version of FPC; in the current version, it will only crash on OS
X). You are assigning a string constant to a pchar, and then telling the
DLL to overwrite it.
> In current release versions of FPC (where it doesn't crash), that will
result in the data of that string constant getting overwritten. This means
that if you assign 'test1234567890' somewhere else to a string, that string
will actually get the value with which this string was overwritten the last
> Use getmem to allocate writeable memory.

In case MyReturnStr is a Ansi-, Wide- or UnicodeString shouldn't
"SetLength(MyReturnStr, StringLen)" work as well?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140701/13239b83/attachment.html>

More information about the fpc-pascal mailing list