
Originally Posted by
Er1k
Thanks for your reply. I have actually given it a try and managed to export a TIntegerArray type to simba and got it to work. But how do you export custom types other than those already used by simba? For example, how about an array [0..8] of integer? I tried declaring a type in both simba and the dll, but it won't recognize.
Again, you export it the same. Instead of array of integer you put array [0..8] of integer. Doesn't that work?
Edit: Made you an example:
Simba Code:
library test;
{$mode objfpc}{$H+}
uses
Classes, sysutils
{ you can add units after this };
type
TTestIntegerArray = array [0..8] of integer;
{$R *.res}
procedure populate(var arr : TTestIntegerArray); stdcall;
var
i : integer;
begin
for i := 0 to high(arr) do
arr[i] := random(100);
end;
function GetTypeCount() : Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: integer; var sType, sTypeDef : string): integer; stdcall;
begin
result := x;
case (x) of
0 : begin
sType := 'TTestIntegerArray';
sTypeDef := 'array [0..8] of integer;';
end;
else
result := -1;
end;
end;
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @populate;
StrPCopy(ProcDef, 'procedure populate(var t : TTestIntegerArray);');
end;
else
x := -1;
end;
Result := x;
end;
exports GetFunctionCount, GetFunctionInfo,
GetTypeCount, GetTypeInfo;
begin
end.
Build that plugin, place it in your plugins folder, run this script in Simba:
Simba Code:
program test;
{$loadlib test}
var
arr : TTestIntegerArray;
begin
writeln(length(arr)); // should be 9
writeln(arr); // should be all zeroes
populate(arr); // fills with random numbers
writeln(arr); // should be now filled with random numbers
setarraylength(arr, 8); // should fail
end.
Hope that works
.