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

Paul Breneman Paul2006 at BrenemanLabs.com
Tue Jul 1 22:24:00 CEST 2014


On 07/01/2014 02:58 PM, Jonas Maebe wrote:
> 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 time.
>
> Use getmem to allocate writeable memory.

Thanks Jonas!  That got things working!




More information about the fpc-pascal mailing list