delphi动态调用dll出错,请指导
主程序:unitUnit1;interfaceusesShareMem,Windows,Messages,SysUtils,Variants,Classes,Graphi...
主程序:
unit Unit1;interfaceuses ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type plus=function(x,y:double):double; stdcall; TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);varpfunc:TFarProc;hd1:THandle;a,b:double;begina:= strtofloat(edit1.text);b:= strtofloat(edit2.text);hd1:=loadlibrary('Project2.dll');if hd1<>0 thenbeginpfunc:=getprocaddress(hd1,'Project2.dll');edit3.text:=floattostr(plus(pfunc)(a,b));end; freelibrary(hd1);end;end.
dll程序代码:
library Project2;uses SysUtils, Classes;{$R *.res}function plus(x,y:double):double; stdcall;beginplus:=x+y;end;exportsplus;beginend.
出错图片: 展开
unit Unit1;interfaceuses ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type plus=function(x,y:double):double; stdcall; TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);varpfunc:TFarProc;hd1:THandle;a,b:double;begina:= strtofloat(edit1.text);b:= strtofloat(edit2.text);hd1:=loadlibrary('Project2.dll');if hd1<>0 thenbeginpfunc:=getprocaddress(hd1,'Project2.dll');edit3.text:=floattostr(plus(pfunc)(a,b));end; freelibrary(hd1);end;end.
dll程序代码:
library Project2;uses SysUtils, Classes;{$R *.res}function plus(x,y:double):double; stdcall;beginplus:=x+y;end;exportsplus;beginend.
出错图片: 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询