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

H

hyxic

Unregistered / Unconfirmed
GUEST, unregistred user!
Dll代码如下:
type
arg=array of array of PChar;

{$R *.res}
function GetInsObject:arg;stdcall;
var
i,n:integer;
cmp:TComponent;
cmpChk:TCheckBox;
cmpCbx:TComboBox;
CurVar:arg;
begin
n:=0;
Result:=Null;
Try
fInsObject:=fInsObject.Create(Application);
Try
//检查是否存在所选的组件
for i:=1 to 21 do
begin
cmp:=cmpChk.FindComponent('c'+IntToStr(i));
If (not Assigned(cmp)) or (not (cmp is TCheckBox)) then
begin
Result:=Null;
SysUtils.Abort
end
else
begin
cmpChk:=TCheckBox(cmp);
if cmpChk.Checked then
inc(n);
end;
end;
SetLength(CurVar,n,1);
if fInsObject.ShowModal=mrOK then
begin
for i:=1 to 21 do
begin
//cmp:=cmpCbx.FindComponent('c'+IntToStr(i));
cmpChk:=TCheckBox(cmp);
if cmpChk.Checked then
CurVar[i-1][0]:=PChar(cmpChk.Caption);
cmp:=cmpCbx.FindComponent('m'+IntToStr(i));
If (not Assigned(cmp)) or (not (cmp is TComboBox)) then
begin
Result:=Null;
SysUtils.Abort
end
else
begin
cmpCbx:=TComboBox(cmp);
CurVar[i-1][1]:=PChar(cmpCbx.Text);
end;
end;
Result:=CurVar;
end;
finally
fInsObject.Free;
end;
Except
On E:Exception Do
MessageDlg('动态链接库DLL发生错误:'+E.Message,mtError,[mbOK],0);
End;
end;
exports
GetInsObject name 'GetInsObject' resident;

调用代码如下:
type
arg=array of array of PChar;
var
myHandle:THandle;
Func:TFarProc;
FuncStr:function ():arg;stdcall;
dd:arg;
begin
inherited;
myHandle:=LoadLibrary('SysDll/InsObject.dll');
If myHandle>0 then
try
Func:=GetProcAddress(myHandle,PChar('GetInsObject'));
if Func<>nil then
begin
FuncStr:=Func;
dd:=FuncStr();
End;
finally
FreeLibrary(myHandle);
end;
end;
 
在你的dll项目的dpr文件中,找到
uses
WIndows,
...
这样的句子,在uses下面紧跟的第一行,写上
uses
ShareMem,
Windows,
...
然后打开你的exe项目的dpr文件,也做如上操作,完成后,编译dll,再编译exe,最后运行即可.这样就行了
 
zqw0117老兄,我照你的方法作了还是不行????
 
在通常情况下,你不要尝试从DLL中返回任何DLL中分配的内存指针!
你应当在调用时分配好内存后再传递指针给DLL进行处理!!
 
to:ANiDelphi,button本来就有MOUSEDOWN呀,为什么不能继承呢.
 
顶部