请看看这个简短的DLL动态调用程序哪点有问题??? (10分)

  • 主题发起人 主题发起人 asphunter
  • 开始时间 开始时间
A

asphunter

Unregistered / Unconfirmed
GUEST, unregistred user!
指针定义:<br>type<br>&nbsp; &nbsp; &nbsp;NodePtr=^TNodePtr;<br>&nbsp; &nbsp; &nbsp;TNodePtr=record<br> curDir: NodePtr;<br> next: NodePtr;<br>end;<br><br>外部函数定义:<br>Type Tmymethod=procedure(filename:pchar;var myDir: NodePtr);<br><br>调用过程如下:<br>var<br>&nbsp; &nbsp;aptr:TFarproc;<br>&nbsp; &nbsp;lhnd:Thandle;<br>&nbsp; &nbsp;mymethod:Tmymethod;<br>&nbsp; &nbsp;m:NodePtr;<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; lhnd:=null;<br>&nbsp; &nbsp; &nbsp; &nbsp; lhnd:=LoadLibrary('C:/Demo.DLL');<br><br>&nbsp; &nbsp; &nbsp; &nbsp; if (lhnd&lt;32) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('The Demo.DLL load Error.');<br> &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; aptr:=GetprocAddress(lhnd,'mymethod');<br><br>&nbsp; &nbsp; &nbsp; &nbsp; if aptr&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new(m);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mymethod:=Tmymethod(aptr);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mymethod('c:/a.txt',m);//执行到此时出错,说地址访问错误,我用VC++调时是正确的<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; FreeLibrary(lhnd);<br>end;
 
DLL中导出的函数一般应该用stdcall的调用方式,你这里用的是普通的Delphi调用
 
接受答案了.
 
后退
顶部