Calling function with array parameters in C ++ dll from Delphi

It's hard for me to call a function in a C ++ dll from delphi.

C ++ function is defined as follows

BALL_SCRUB_DLL_API int CALLING_CONVENTION bsl2_ModelBallFlight(float cam_X, 
    float cam_Y, 
    float cam_Z, 
    Ball3d* ball_data_in, 
    int n_balls_in, 
    Ball3d* ball_data_out, 
    int &n_balls_out);

The template structure is as follows:

  typedef struct 
  { float X;
  float Y;
  float Z;
  float VX;
  float VY;
  float VZ;
  int frame_id;
  int flag;
  } Ball3d;

I want to send the ball_data_in array from my delphi application, and the C ++ dll will return the same array type, but with the changed values ​​to ball_data_out.

I defined the TBall3D entry as follows:

TBall3D = record
    X : Single;
    Y : Single;
    Z : Single;
    VX : Single;
    VY : Single;
    VZ : Single;
    Framecount : Integer;
    BallFlag : Integer;
  end;
  PBall3D = ^TBall3D;
  TBall3DArray = array of TBall3D;
  PBall3DArray = ^TBall3DArray;

The declaration of my function is as follows:

  TBSL2_ModelBallFlight = function( const Cam_X, Cam_Y, Cam_Z : Single;
                                    const ball_data_in : PBall3DArray;
                                    const NFramesIn : Integer;
                                    var ball_data_out : PBall3DArray;
                                    const NFramesOut : Integer) : Integer; cdecl;

How do I make this call from delphi to dll? Any help would be greatly appreciated.

+4
source share
1 answer

The problem is here:

TBall3DArray = array of TBall3D;

. Delphi . , . . , .

:

TBSL2_ModelBallFlight = function(
  Cam_X: Single;
  Cam_Y: Single;
  Cam_Z: Single;
  ball_data_in: PBall3D;
  NFramesIn: Integer;
  ball_data_out: PBall3D;
  var NFramesOut: Integer
): Integer; cdecl;

++. ++ Ball3d*, Ball3d, PBall3D, TBall3D.

. ++ int &n_balls_out. int. var Delphi.

. :

var
  ball_data_in, ball_data_out: TBall3DArray;

SetLength. , , @ball_data_in[0], PBall3D(ball_data_in). out.

, , :

SetLength(ball_data_in, NFramesIn);
SetLength(ball_data_out, NFramesOut);
retval := bsl2_ModelBallFlight(..., PBall3D(ball_data_in), NFramesIn, 
  PBall3D(ball_data_out), NFramesOut);
+2

All Articles