X
xiang8410
Unregistered / Unconfirmed
GUEST, unregistred user!
//调用DLL的单元Umain.pas<br>type<br> TShowLt=procedure(aHandle:THandle;username,password,dbname,serverip:string);stdcall;<br>......<br>private<br> DLLHandle:THandle;<br>....<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> DLLHandle:=LoadLibrary('ltwydll.dll');<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> FreeLibrary(DLLHandle);<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br> var<br> Showlt:TShowLt;<br> username,password,dbname,serverip:string;<br>begin<br> username:=Trim(Eusername.Text);<br> password:=Trim(Epassword.Text);<br> dbname:=Trim(Edbname.Text);<br> serverip:=Trim(Eserverip.Text);<br> @Showlt:=GetProcAddress(DLLHandle,'ShowLT');<br> if (@ShowLT=nil) then<br> RaiseLastWin32Error;<br> ShowLT(Application.Handle,username,password,dbname,serverip);//运行提示此行出错<br>end;<br>//DLL项目文件ltwydll.dpr<br>library ltwydll;<br>...<br>exports<br> ShowLT;<br>...<br>//DLL中的单元文件Unit1.pas<br>unit Unit1;<br>....<br>public<br> function connetionserver(username,password,dbname,serverip:string):Boolean;<br>end;<br>var<br> Frm: TFrm;<br>procedure ShowLT(aHandle:THandle;username,password,dbname,serverip:string);stdcall;<br>implementation<br> uses ActiveX;<br>{$R *.dfm}<br>//-------------DLL参数传递的过程-------------//<br>procedure ShowLT(aHandle:THandle;username,password,dbname,serverip:string);<br>begin<br> try<br> CoInitialize(nil);<br> Application.Handle:=aHandle;<br> with TFrm.Create(Application) do<br> begin<br> if connetionserver(username,password,dbname,serverip)=True then<br> Frm.Show<br> else<br> begin<br> ShowMessage('参数不正确,连接失败');<br> Application.Terminate;<br> end;<br> end;<br> finally<br> CoUninitialize;<br> end;<br>end;<br>//-------------数据库连接--------------------------//<br>function TFrm.connetionserver(username, password, dbname,<br> serverip: string): Boolean;<br>var<br> connstr:string;<br>begin<br> Result:=False;<br> connstr :='Provider=SQLOLEDB.1;Persist Security Info=false;User ID='<br> +username+';Password='+password+';Initial Catalog='<br> +dbname+';Data Source='+serverip;<br> ADOConnection1.ConnectionString:=connstr;<br> try<br> ADOConnection1.Connected:=True;<br> Result:=True;<br> except<br> ShowMessage('参数不正确,连接失败');<br> Application.Terminate;<br> end;<br>end;<br>一运行,如果在调用程序的四个Edit输入连接数据库的用户名(sa),密码(123),数据库(wy_2007SPTest),ip(.)就会报错(Access violatation at address 0104DOE2 in module 'ltwydll.dll'.Read of adress 000002EC).如果在调用程序的四个Edit不输入任何信息就提示报错('无效的授权说明').请问高手这是哪错了~~~~(本人是怀疑传参数错了,但找不出哪错了~~望高手指点一下)