I used to create
.dll file on
Lazarus version 1.6.4 and tested it by calling statically. It worked well.
But today I use
1.8.2 and copy the same .dll file (that complied in 1.6.4) to be used in working folder.
Problem #1:The old .dll file cannot be used. I have to re-complied it again.
I'm not sure there is some minor-chang in compling .dll in the latest version of IDE.
Anyway, the main problem is the next one.
Problem #2: After the .dll file has been re-complied, it can be used.
But the result from the function is not the same.
It is going negative value.
I found that the problem is .... the wrong order of input argument.
Please see my .dll and Unit1 below:
library TestDLL;
{$mode objfpc}{$H+}
uses
Classes
function TestMinus(A,B:double) : double; stdcall;
begin
result := A-B ;
end;
exports
TestMinus;
begin
end.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
function TestMinus(A,B : double) : double; external 'TestDLL.dll'; //Static Calling .dll
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Caption:='A = 5, B =2, Then A - B = ' + FloatToStr(TestMinus(5,2));
//I got A-B = -3
end;
end.
From the above codes, I got " A - B = -3".
Is it bug?