垦求高手帮忙~~~关于DLL与应用程序的参数传递(无效的授权说明) ( 积分: 30 )

  • 主题发起人 主题发起人 xiang8410
  • 开始时间 开始时间
X

xiang8410

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

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部