Jilani Khaldi wrote:
Hi All,

I have written a little library in C (compiled in as a DLL) to use it in Free Pascal and Delphi applications. While the code (below) works with Delphi (7), I get an Access Violation using FPC (1.98). Perhaps I am missing something.
Any hint? Thanks!


program fpc_dll;
{$H+}{$MODE OBJFPC}

uses
 sysutils;

type
myarray = array of double;
// if I declare "myarray = array[0..9] of double;" the code runs as expected.


function get_array(a, b: myarray; size: integer; value: double): integer; cdecl; external 'mylib.dll';

Change this to

type
  PDouble = ^Double;

function get_array(a, b: PDouble; size: integer; value: double): integer; cdecl; external 'mylib.dll';

In C "double a[]" is the same as "double *a" which is the same as "A: PDouble" in Pascal. "array of Double" is not the same thing as "PDouble", as fpc developers already explained.

// extern "C" __cdecl __declspec(dllexport) int get_array(double a[], double b[], int size, double val);
...
qq := get_array(mat1,mat2,kk,3.14);

Change this to

qq := get_array(PDouble(mat1),PDouble(mat2),kk,3.14);

Michalis

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to