unit CustomRotorLibrary;

interface

uses
  Windows;
function getAzimuth: integer;
function AddDouble(a: double; b: double): double;
function ANDER(a: boolean; b: boolean): boolean;
// function AddInt(a: integer; b: integer): integer; stdCall;
// function AddMultiply(a: double; b: double): double;
function Multiply(a: double; b: double): double;
procedure ReturnTwoStrings(Str1, Str2: pAnsichar);

function Version(Str1: pAnsichar; var numChar: integer): boolean;

implementation

var
  dllHandle: cardinal;

function Version(Str1: pAnsichar; var numChar: integer): boolean;
type
  TVersionFunc = function(Strl: pAnsichar): integer; stdCall;
var
  VersionFunc: TVersionFunc;
begin
  result := false;
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @VersionFunc := GetProcAddress(dllHandle, 'Version');
    if Assigned(VersionFunc) then
    begin
      numChar := VersionFunc(Str1);
      result := true;
    end
    else
    begin
      result := false;
      FreeLibrary(dllHandle)
    end;
  end;
end;

function Multiply(a: double; b: double): double;
type
  TMultiplyFunc = function(a: double; b: double): double; stdCall;
var
  MultiplyFunc: TMultiplyFunc;
begin
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @MultiplyFunc := GetProcAddress(dllHandle, 'Multiply');
    if Assigned(MultiplyFunc) then
      result := MultiplyFunc(a, b)
    else
    begin
      FreeLibrary(dllHandle)
    end;
  end;
end;

function getAzimuth: integer;
type
  TgetAzimuthFunc = function(): integer; stdCall;
var
  getAzimuthFunc: TgetAzimuthFunc;
begin
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @getAzimuthFunc := GetProcAddress(dllHandle, 'getAzimuth');
    if Assigned(getAzimuthFunc) then
      result := getAzimuthFunc()
    else
    begin
      FreeLibrary(dllHandle)
    end;
  end;
end;

function AddDouble(a: double; b: double): double;
type
  TAddDoubleFunc = function(a: double; b: double): double; stdCall;
var
  AddDoubleFunc: TAddDoubleFunc;
begin
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @AddDoubleFunc := GetProcAddress(dllHandle, 'Add');
    if Assigned(AddDoubleFunc) then
      result := AddDoubleFunc(a, b)
    else
    begin
      FreeLibrary(dllHandle)
    end;
  end;
end;

procedure ReturnTwoStrings(Str1, Str2: pAnsichar);
type
  TReturnTwoStringsFunc = function(Str1, Str2: pAnsichar): pAnsichar; stdCall;
var
  ReturnTwoStringsFunc: TReturnTwoStringsFunc;
begin
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @ReturnTwoStringsFunc := GetProcAddress(dllHandle, 'ReturnTwoStrings');
    if Assigned(ReturnTwoStringsFunc) then
      ReturnTwoStringsFunc(Str1, Str2)
    else
    begin
      FreeLibrary(dllHandle)
    end;
  end;
end;

function ANDER(a: boolean; b: boolean): boolean;
type
  TANDERFunc = function(a, b: boolean): integer; stdCall;
var
  ANDERFunc: TANDERFunc;
  res: integer;
begin
  result := false;
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @ANDERFunc := GetProcAddress(dllHandle, 'ANDER');
    if Assigned(ANDERFunc) then
    begin
      res := ANDERFunc(a, b);
      if res = 0 then
        result := false
      else
        result := true;

    end
    else
    begin
      FreeLibrary(dllHandle)
    end;
  end;
end;
// function ANDER; external 'rotor.dll' index 6;

// function Version; external 'rotor.dll' index 4;
// function TestScottAddDoubles; external 'MathLibrary.dll' index 7;
// function AddDouble; external 'rotor.dll' index 1;

// function AddInt; external 'MathLibrary.dll' index 3;

//
// function AddMultiply; external 'MathLibrary.dll' index 4;
// function Multiply; external 'MathLibrary.dll' index 5;

// procedure ReturnTwoStrings; external 'MathLibrary.dll' index 6;

end.
