[fpc-pascal] DLL call works on FPC 2.6.4 but not with D7
Paul2006 at BrenemanLabs.com
Thu Jul 3 12:53:39 CEST 2014
On 07/02/2014 06:43 AM, Paul Breneman wrote:
> On 07/01/2014 04:24 PM, Paul Breneman wrote:
>> 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!
> There is a 1.2 MB zip file here with the working source code:
Just thought I should share (here) what I started sharing several other
There are simple tools (free and open source) and code for C and Pascal
(Python hopefully soon) on the new page mentioned above.
If you are an experienced programmer then this probably doesn't apply to
you. But if you or someone you know is just starting out, maybe these
types of projects can be a valuable resource. These folks have been
doing something similar (demonstrating simple tools) since 1998:
More information about the fpc-pascal