R
richardi
Unregistered / Unconfirmed
GUEST, unregistred user!
下面代码中把EXE程序中的APopedom传递给DLL中的APopedom,测试报内存错误,这是为什么?请高人指点,谢谢<br><br>//dll中的单元文件中的调用函数<br>procedure CallForm(const app:TApplication;<br> const adocnn:Tadoconnection;<br> const aLoginName:string;<br> Popedom:array of boolean);stdcall;<br>begin<br> Application:=app;<br> if frmPartNo=nil then<br> begin<br> frmPartNo:=TfrmPartNo.Create(app);<br> frmPartNo.ADOConnection1:=adocnn;<br> frmPartNo.LoginName :=aLoginName;<br> frmPartNo.APopedom:=@Popedom;//把参数地址传给frmPartNo.APopedom,这样写不知有没有问题?<br> end;<br> frmPartNo.Show;<br>end;<br>exports<br> CallForm;<br><br>//DLL中的单元<br>unit uPartNo;<br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, DB, ADODB, StdCtrls, Buttons;<br>type<br> TfrmPartNo = class(TForm)<br> ADOConnection1: TADOConnection;<br> BitBtn1: TBitBtn;<br> procedure BitBtn1Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> public<br> LoginName:string;//声明变量<br> APopedom:array of boolean;//声明数组变量,用于接收exe传递过来的参数<br> { Public declarations }<br> end;<br>var<br> frmPartNo: TfrmPartNo;<br>implementation<br>{$R *.dfm}<br>procedure TfrmPartNo.BitBtn1Click(Sender: TObject);<br>begin<br> if APopedom[1]=true<br> begin<br> showmessage('ok');//这儿有问题,怎么写法?好像没参数没传过来<br> end;<br>//showmessage(booltostr(APopedom[1]));//测试<br>showmessage(LoginName);<br>end;<br><br>//EXE中的写法<br> PlugIn=function(const app:TApplication;<br> const adocnn:Tadoconnection;<br> const aLoginName:string;<br> Popedom:array of boolean):integer;stdcall;//声明函数类型<br>……<br>procedure TfrmPlms.N5Click(Sender: TObject);<br>var<br> ahandle:THandle;<br> pluglugIn;<br>begin<br> APopedom[1]:=true;<br> ahandle:=LoadLibrary('pn.dll') ;<br> if ahandle=0 then<br> exit;<br> @plug:=GetProcAddress(ahandle,'CallForm');<br> if @plug<>nil then<br> plug(Application,frmDM.ADOConnection1,'test',APopedom);<br>//传递参数,APopedom变量在EXE文件的声明是APopedom :array[0..160] of boolean;<br>end;