dll的调用故障,该如何解决
dll的调用故障
sdll文件如下:
library sdll;
uses
SysUtils,
Classes;
function GetInteger(I:Integer): Integer;stdcall;
function GetDouble(D:Double): Double;stdcall;
{$R *.res}
function GetInteger(I:Integer): Integer;stdcall;
begin
Result := I;
end;
function GetDouble(D:Double): Double;stdcall;
begin
Result := D;
end;
exports
GetInteger,
GetDouble;
begin
end.
调用dll文件:
unit usedll1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function GetDouble(D:Double): Double;stdcall;external 'sdll.dll ';
function GetInteger(I:Integer): Integer;stdcall;external 'sdll.dll ';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text := inttostr(GetInteger(100));
end;
end.
运行后就是报错如下:
project f:\delphi\usedll.exe faulted with message: 'access violation at ox77f8ea53:write of address ox00030cb4 '.process stopped.use step or run to continue.
由于是第一次搞DLL,望大家指导指导!多谢了!
------解决方案--------------------
library sdll;
uses
SysUtils,
Classes;
//function GetInteger(I:Integer): Integer;stdcall;
//function GetDouble(D:Double): Double;stdcall;//--------把这两行去掉就行了。^_^
{$R *.res}
function GetInteger(I:Integer): Integer;stdcall;
begin
Result := I;
end;
function GetDouble(D:Double): Double;stdcall;
begin
Result := D;
end;
exports
GetInteger,
GetDouble;
begin
end.
------解决方案--------------------
+上
uses
ShareMem;
------解决方案--------------------
因为:
type
TGetDouble=function(D:Double):Integer;stdcall;
^这里写错了
sdll文件如下:
library sdll;
uses
SysUtils,
Classes;
function GetInteger(I:Integer): Integer;stdcall;
function GetDouble(D:Double): Double;stdcall;
{$R *.res}
function GetInteger(I:Integer): Integer;stdcall;
begin
Result := I;
end;
function GetDouble(D:Double): Double;stdcall;
begin
Result := D;
end;
exports
GetInteger,
GetDouble;
begin
end.
调用dll文件:
unit usedll1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function GetDouble(D:Double): Double;stdcall;external 'sdll.dll ';
function GetInteger(I:Integer): Integer;stdcall;external 'sdll.dll ';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text := inttostr(GetInteger(100));
end;
end.
运行后就是报错如下:
project f:\delphi\usedll.exe faulted with message: 'access violation at ox77f8ea53:write of address ox00030cb4 '.process stopped.use step or run to continue.
由于是第一次搞DLL,望大家指导指导!多谢了!
------解决方案--------------------
library sdll;
uses
SysUtils,
Classes;
//function GetInteger(I:Integer): Integer;stdcall;
//function GetDouble(D:Double): Double;stdcall;//--------把这两行去掉就行了。^_^
{$R *.res}
function GetInteger(I:Integer): Integer;stdcall;
begin
Result := I;
end;
function GetDouble(D:Double): Double;stdcall;
begin
Result := D;
end;
exports
GetInteger,
GetDouble;
begin
end.
------解决方案--------------------
+上
uses
ShareMem;
------解决方案--------------------
因为:
type
TGetDouble=function(D:Double):Integer;stdcall;
^这里写错了