Setting up Delphi to call a 2 dimensional array in C++ DLL

UPDATED USING PREVIOUS ANSWERS

I have a DLL with the following header definitions:

typedef struct {
    int32_t dimSizes[2];
    double NumericControl[1];
} DoubleArrayBase;
typedef DoubleArrayBase **DoubleArray;
    
void __stdcall ReadTERFCorrectedData(char FilepathString[], 
    int32_t ArrayLengths[], DoubleArray *AmplitudeData, 
    DoubleArray *FrequencyData, int32_t len);

DoubleArray __cdecl AllocateDoubleArray (int32 *dimSizeArr);
MgErr __cdecl ResizeDoubleArray (DoubleArray *hdlPtr, int32 *dimSizeArr);
MgErr __cdecl DeAllocateDoubleArray (DoubleArray *hdlPtr);

My question is, how do I go about setting up a Delphi call to this function?

My Delphi definition of the call is as follows:

type
  PDoubleArray = ^DoubleArray;
  DoubleArray = ^PDoubleArrayBase;
  PDoubleArrayBase = ^DoubleArrayBase;
  DoubleArrayBase = packed record
    dimSizes: array[0..1] of Int32;
    NumericControl: array[0..0] of Double;
  end;

  procedure ReadTERFCorrectedData(FilepathString: PAnsiChar;
                                  var ArrayLengths: Int32; AmplitudeData, FrequencyData: PDoubleArray;
                                  len: Int32);stdcall; external DLLDirectory;
  function AllocateDoubleArray (SizeArray: PInt): DoubleArray;stdcall; external DLLDirectory;

And then in the body of the code I allocate space for the arrays then get the data as follows:

implementation

{$R *.dfm}

procedure TForm7.btn1Click(Sender: TObject);
var
  AmplitudeData, FrequencyData : DoubleArray;
  arraylengths: array[0..1] of int32;
  I: Integer;
  TempSize : Int32;
begin
  TempSize := 50;
  AmplitudeData := AllocateDoubleArray(@Tempsize);
  FrequencyData := AllocateDoubleArray(@Tempsize);
  ReadTERFCorrectedData(fileloc, ArrayLengths[0], @AmplitudeData, @FrequencyData, 50);
  ShowMessage(arraylengths[1].tostring);
end;

How do I go about accessing the data stored in the AmplitudeData and FrequencyData? They are both DoubleArray types, but how do i get to the DoubleArrayBase.dimSizes and DoubleArrayBase.NumericControl values buried by the pointer? I have tried AmplitudeData[0,0], AmplitudeData.NumericControl, etc but can not get to the values.

I am basicaly trying to create a Delphi version of what is being done in this post: https://lavag.org/topic/20486-lv-dll-creates-mysterious-doublearray-class/



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)