Passing array from golang dll to Delphi

Hello,
I try to write a simple dll returning an array of int in Golang.

//export Test
func Test() uintptr {
names := []int{12345, 678910, 1314155}
	return uintptr(unsafe.Pointer((*C.int)(unsafe.Pointer(&names[0]))))
}

I try to retrieve this array in Delphi but I failed:

function TTest.Test(): boolean;
type
  TIntArray =  Array of integer;
var
  TestFunc: TTestFunc;
  p: PInteger;
  OutputData: TIntArray;
begin
  Result := False;
  if DLLHandle <> 0 then
  begin
    TestFunc := GetProcAddress(DLLHandle, 'Test');
    if Assigned(TestFunc) then
    begin
      p:= TestFunc();
      OutputData:= TIntArray(p);
      OutputDebugString(PChar(IntToStr(OutputData[0])));
    end;
  end;
end;

Any idea?

Regards

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.