请问各位动态链接库中动态数组作为返回值怎么做,我的程序编译是没问题,调用就出错了!!!!!!!!分都给了(18分)

H

hyxic

Unregistered / Unconfirmed
GUEST, unregistred user!
Dll代码如下:<br>type<br> &nbsp;arg=array of array of PChar;<br><br>{$R *.res}<br>function GetInsObject:arg;stdcall;<br>var<br> &nbsp;i,n:integer;<br> &nbsp;cmp:TComponent;<br> &nbsp;cmpChk:TCheckBox;<br> &nbsp;cmpCbx:TComboBox;<br> &nbsp;CurVar:arg;<br>begin<br> &nbsp;n:=0;<br> &nbsp;Result:=Null;<br> &nbsp;Try<br> &nbsp; &nbsp;fInsObject:=fInsObject.Create(Application);<br> &nbsp; &nbsp;Try<br> &nbsp; &nbsp; &nbsp;//检查是否存在所选的组件<br> &nbsp; &nbsp; &nbsp;for i:=1 to 21 do<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;cmp:=cmpChk.FindComponent('c'+IntToStr(i));<br> &nbsp; &nbsp; &nbsp; &nbsp;If (not Assigned(cmp)) or (not (cmp is TCheckBox)) then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=Null;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SysUtils.Abort<br> &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmpChk:=TCheckBox(cmp);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if cmpChk.Checked then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inc(n);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;SetLength(CurVar,n,1);<br> &nbsp; &nbsp; &nbsp;if fInsObject.ShowModal=mrOK then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;for i:=1 to 21 do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//cmp:=cmpCbx.FindComponent('c'+IntToStr(i));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmpChk:=TCheckBox(cmp);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if cmpChk.Checked then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CurVar[i-1][0]:=PChar(cmpChk.Caption);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmp:=cmpCbx.FindComponent('m'+IntToStr(i));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If (not Assigned(cmp)) or (not (cmp is TComboBox)) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=Null;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SysUtils.Abort<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmpCbx:=TComboBox(cmp);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CurVar[i-1][1]:=PChar(cmpCbx.Text);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;Result:=CurVar;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;fInsObject.Free;<br> &nbsp; &nbsp;end;<br> &nbsp;Except<br> &nbsp; &nbsp;On E:Exception Do<br> &nbsp; &nbsp; &nbsp;MessageDlg('动态链接库DLL发生错误:'+E.Message,mtError,[mbOK],0);<br> &nbsp;End;<br>end;<br>exports<br> &nbsp;GetInsObject name 'GetInsObject' resident;<br><br>调用代码如下:<br>type<br> &nbsp;arg=array of array of PChar;<br>var<br> &nbsp;myHandle:THandle;<br> &nbsp;Func:TFarProc;<br> &nbsp;FuncStr:function ():arg;stdcall;<br> &nbsp;dd:arg;<br>begin<br> &nbsp;inherited;<br> &nbsp;myHandle:=LoadLibrary('SysDll/InsObject.dll');<br> &nbsp;If myHandle&gt;0 then<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;Func:=GetProcAddress(myHandle,PChar('GetInsObject'));<br> &nbsp; &nbsp; &nbsp;if Func&lt;&gt;nil then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;FuncStr:=Func;<br> &nbsp; &nbsp; &nbsp; &nbsp;dd:=FuncStr();<br> &nbsp; &nbsp; &nbsp;End;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;FreeLibrary(myHandle);<br> &nbsp; &nbsp;end;<br>end;
 
顶部