Hello.
I have a C# program, which controls a experiment and gets data to double[] arrays. Those arrays are dynamic - there is no known size.
I should create a DLL in free pascal which should calculate one parameter from those arrays and return back.
Example code of simple DLL:
library solidity;
type
TDynArray = array[0..65536] of double;
function taramasalata ( TimeArray: TDynArray; ValueArray : TDynArray) : double; cdecl; {Linux/Unix -cdecl, Windows - sdtcal}
var
LengthOfArray : integer;
L1, L2 : integer;
i : integer;
begin
i :=0;
taramasalata:= TimeArray[0] + ValueArray[1];
end;
exports
taramasalata;
end.
Example code of C#:
using System;
using Gtk;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Globalization;
public partial class MainWindow: Gtk.Window
{
const string SimpLibName = "libtarama.dll";
//Declare external functions using the DllImport attribute.
[DllImport(SimpLibName, EntryPoint="taramasalata", CharSet=CharSet.Auto,
CallingConvention=CallingConvention.Cdecl)]
public static extern double rmSuoliai ([MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] double[] TimeArray, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)] double[] ValueArray);
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected void OnPressBtnClicked (object sender, EventArgs e)
{
try {
string[] Timelist = array1.Buffer.Text.Split ('\n');
List<double> TimeArray = new List<double> ();
string[] ValueList = array2.Buffer.Text.Split ('\n');
List<double> ValueArray = new List<double> ();
foreach (string s in Timelist) {
TimeArray.Add (Convert.ToDouble (s, CultureInfo.InvariantCulture));
}
foreach (string m in ValueList) {
ValueArray.Add (Convert.ToDouble (m, CultureInfo.InvariantCulture));
}
//call to dll:
double answer = taramasalata (TimeArray.ToArray (), ValueArray.ToArray ());
answer42.Text = Convert.ToString (answer, CultureInfo.InvariantCulture);
} catch (Exception ex) {
Console.WriteLine (ex.ToString ());
}
}
}
Question:
How to pass a double[] to DLL? Those duoble[] arrays are dynamically.