DLL动态调用出错,静态调用却没问题,郁闷呀(100分)

  • 主题发起人 主题发起人 logingyw
  • 开始时间 开始时间
L

logingyw

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL:

function DownFileSize( fList:TStringList;var List:TListView ):integer;stdcall;
var
i,Total:integer;
URL:string;
node:TListItem;
begin
Total := 0;
List.Clear;
http := TIdHTTP.Create(nil);
try
for i := 0 to fList.Count - 1 do
begin
URL := hysite + ExtractFileName( fList.Strings );
http.Head( URL );
Total := Total + http.Response.ContentLength;

node := List.Items.Add;
node.Caption := ExtractFileName( fList.Strings );
if i=0 then
node.ImageIndex := 4
else
node.ImageIndex := 0;
node.SubItems.Add( '准备下载' );
node.SubItems.Add( inttostr(http.Response.ContentLength) );
end;
finally
Result := Total;
FreeAndNil( http );
end;
end;

function GetFileList( Ver, DesFile:pchar; var fList:TStringList ):integer;stdcall;
var f:TFileStream;
inif:TiniFile;
i, j:integer;
s, verstr, URL:string;
List:TStringList;
begin
Result := SUCCESS;
try
http := TIdHTTP.Create(nil);
try
f := TFileStream.Create( DesFile, fmCreate);
try
URL := hysite + 'update.ini';
http.Get( url, f );
except
Result := DOWNFILE_FAIL;
EXIT;
end;
finally
FreeAndNil( f );
end;
finally
FreeAndNil( http );
end;

try
List := TStringList.Create;
List.Clear;
inif := TIniFile.Create( DesFile );
if ver>=inif.ReadString('ver', 'LastVer', '2006.08.01') then
begin
Result := NONEWVER;
exit;
end;
for i := 1 to inif.ReadInteger( 'ver', 'num', 0 ) do
begin
if ver>inif.ReadString( 'ver', 'ver'+inttostr(i), '') then continue;
verstr := inif.ReadString('ver', 'ver'+inttostr(i), '');
for j := 1 to inif.ReadInteger( verstr, 'FileCount', 0) do
begin
s := inif.ReadString( verstr, 'File'+inttostr(j), '');
List.Add(s);
end;
if List.IndexOf( s )<0 then List.Add( s );
end;
if List.Count<1 then
RESULT := CONFIGFILE_ERROR;
fList.Clear;
for i:= 0 to List.Count - 1 do
fList.Add(List.Strings);
finally
FreeAndNil( List );
FreeAndNil( inif );
end;
end;


App:
procedure Tf_main.Button1Click(Sender: TObject);
var dFile:string;
n:integer;
begin
try
Button1.Enabled := False;
try
fList := TStringList.Create;
//到这里总报读地址错误
rt := GetFileList( pchar('2006.08.16'), pchar(dFile), fList);// call dll
n := DownFileSize( fList, ListView1);// call dll
Gauge1.MaxValue := n;
Label5.Caption := '成功。';
Except
Label5.Caption := '失败!!!';
end;
finally
FreeAndNil( fList );
Button1.Enabled := True;
end;
end;
 
自己看生成DLL的那个单元最上面的一段英文.......重点解释都有了,而且这个问题DFW上面的帖子多的不能再多了.楼主自己找找吧.
 
fList := TStringList.Create;
//到这里总报读地址错误

这里报错?

fList怎么定义的?
 
您上面那段app下的代码是 动态调用嘛? 那是你静态调用的吧。

动态调用得, loadLibrary(dllfilename)
get方法名, 然后执行。。。
 
我有一个pub.pas
type
TDFSize = function ( fList:TStringList;var List:TListView ):integer;stdcall;
TDF = function ( DesPath:pchar; fList:TStringList; var htp:TIdHTTP; var List:TListView ):integer;stdcall;

function DownFileSize( fList:TStringList;var List:TListView ):integer;
var
LibH:THandle;
DFSize : TDFSize;
begin
try
LibH := LoadLibrary( pchar(pubAppPath + DllFile) );
if LibH>0 then
begin
@DFSize := GetProcAddress( LibH, 'DownFileSize');
if (@DFSize<>nil) then
begin
Application.MessageBox(pchar(inttostr(fList.Count)), 'a');
Result := DFSize( fList, List );
end else
MessageDlg('没有找到函数!', mtError, [mbok], 0);
end;
finally
FreeLibrary( LibH );
end;
end;

function GetFileList( Ver,DesFile:pchar;var fList:TStringList ):integer;
var
LibH:THandle;
GFList : TGFList;
begin
try
LibH := LoadLibrary( pchar(pubAppPath + DllFile) );
if LibH>0 then
begin
GFList := GetProcAddress( LibH, 'GetFileList' );
Result := GFList( Ver, DesFile, fList );
end;
finally
FreeLibrary( LibH );
end;
end;
 
你把代码贴完整一点吧,给你调试一下。

你以上的代码,我复制下来,后发现有不少的东西没定义,调试麻烦。
 
多人接受答案了。
 
静态调用不错啊..干吗不做
 
后退
顶部