unit CustomRotorLibrary;

interface

uses
  Windows;
// function ScottAddDoubles(a: double; b: double): double; stdCall;
function TestScottAddDoubles(a: double; b: double): double;

function AddDouble(a: double; b: double): double;

// function AddInt(a: integer; b: integer): integer; stdCall;
function ANDER(a: boolean; b: boolean): boolean;
//
// function AddMultiply(a: double; b: double): double;
function Multiply(a: double; b: double): double;
procedure ReturnTwoStrings(Str1, Str2: pAnsichar);
// function TestVersion(var Str1: array   of Ansichar): integer; stdCall;
function Version(Str1: pAnsichar): integer;
// function Version(Str1: pAnsichar): integer; stdCall;

implementation

var
  dllHandle: cardinal;

function TestScottAddDoubles(a: double; b: double): double;
type
  TScottAddDoublesFunc = function(aa: double; bb: double): double; stdCall;
var
  ScottAddDoublesFunc: TScottAddDoublesFunc;
  res: double;
begin
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @ScottAddDoublesFunc := GetProcAddress(dllHandle, 'ScottAddDoubles');
    if Assigned(ScottAddDoublesFunc) then
      result := ScottAddDoublesFunc(a, b)

    else
    begin
      result := 666;
      FreeLibrary(dllHandle);
    end;
  end;
end;

function Version(Str1: pAnsichar): integer;
type
  TVersionFunc = function(Strl: pAnsichar): integer; stdCall;
var
  VersionFunc: TVersionFunc;
begin
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @VersionFunc := GetProcAddress(dllHandle, 'Version');
    if Assigned(VersionFunc) then
      result := VersionFunc(Str1)
    else
    begin
      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 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): boolean; stdCall;
var
  ANDERFunc: TANDERFunc;
begin
  result := false;
  dllHandle := LoadLibrary('rotor.dll');
  if dllHandle <> 0 then
  begin
    @ANDERFunc := GetProcAddress(dllHandle, 'ANDER');
    if Assigned(ANDERFunc) then
      result := ANDERFunc(a, b)
    else
    begin
      FreeLibrary(dllHandle)
    end;
  end;
end;

// 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 ANDER; external 'rotor.dll' index 6;
//
// function AddMultiply; external 'MathLibrary.dll' index 4;
// function Multiply; external 'MathLibrary.dll' index 5;

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

end.
