谁帮我看看这段动态调用DLL的代码的问题,全部家产奉送(97分)!(97分)

  • 主题发起人 主题发起人 icola
  • 开始时间 开始时间
I

icola

Unregistered / Unconfirmed
GUEST, unregistred user!
我刚学DLl,下面动态调用DLl时,无论Edit1和Edit2中输入什么整数,Edit3显示的结果老是2485092,怎么回事?<br>library adddll;<br>uses<br> &nbsp;SysUtils,<br> &nbsp;Classes;<br>{$R *.res}<br>function add(x,y:Integer):Integer;stdcall<br>begin<br> &nbsp;Result:=x+y;<br>end;<br>exports<br> &nbsp;add;<br>begin<br>end.<br><br><br><br>unit AddImplicit;<br>interface<br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, ExtCtrls;<br>type<br> &nbsp;Tadd = function(var x,y:Integer):Integer;stdcall;<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;Edit2: TEdit;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Edit3: TEdit;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br>implementation<br>{$R *.dfm}<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;AHandle:THandle;<br> &nbsp;add:Tadd;<br> &nbsp;x,y,z:Integer;<br>begin<br> &nbsp;AHandle:=LoadLibrary('adddll.dll');<br> &nbsp;try<br> &nbsp; &nbsp;if AHandle=0 then Exit;<br> &nbsp; &nbsp; &nbsp;@add:=GetProcAddress(AHandle,'add');<br> &nbsp; &nbsp;if Assigned(@add) then<br> &nbsp; &nbsp; &nbsp;x:= StrToInt(Edit1.Text);<br> &nbsp; &nbsp; &nbsp;y:= StrToInt(Edit2.Text);<br> &nbsp; &nbsp; &nbsp;z:=add(x,y);<br> &nbsp; &nbsp; &nbsp;Edit3.Text:=IntToStr(z);<br> &nbsp;finally<br> &nbsp; &nbsp;FreeLibrary(AHandle);<br> &nbsp;end;<br><br>end;<br><br>end.
 
Tadd = function([red]var [/red]x,y:Integer):Integer;stdcall;<br>这个和DLL<br>function add(x,y:Integer):Integer;stdcall<br>声明不一致<br>多了红色部分。<br>去掉红色部分就OK了。
 
接受答案了.
 
后退
顶部