调用dll出错!!! 急(200分)

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

LittleSong

Unregistered / Unconfirmed
GUEST, unregistred user!
Dll 代码
============

library Compress;

uses
ShareMem,SysUtils,Classes,Windows, Messages,AbBase, AbBrowse, AbZBrows,
AbZipper, AbUnZper, AbZipKit,AbArcTyp;

Function ZipFile(DFileName,SFileName:String):Integer;StdCall;
Var
AbZipper: TAbZipper;
Begin
Try
AbZipper:=TAbZipper.Create(Nil);
With AbZipper Do Begin
FileName:=DFileName;
AddFiles(SFileName,0);
End;
Result:=0;
Except
Result:= -1;
End;
End;

Procedure UnZipFile(UnComPressPath,Compressfile:String);StdCall;
Var
AbUnZipper: TAbUnZipper;
Begin
with AbUnzipper do begin
FileName := Compressfile;
BaseDirectory := ExtractFilePath(UnComPressPath);
ExtractFiles( '*.*' );
end;
End;

Exports
ZipFile,
UnZipFile;

Begin
end.


接口代码
===================

unit comm;

interface

uses
ShareMem,Windows, Messages, SysUtils, Classes;

Function Zipfile(DFileName,SFileName:String):integer;Stdcall;
Procedure UnZipfile(UnComPressPath,Compressfile:String);Stdcall;

implementation


Function Zipfile; External 'Compress.dll' Index 1;
Procedure UnZipfile; External 'Compress.dll' Index 2;

end.


问题:
1。调用时出错。
2。接口中如果写成 Function Zipfile;External 'Compress.dll' Name 'Zipfile';则出现无法定位错
 
估计又是string的问题了,默认有一段注释啊?
{ Important note about DLL memory management: ShareMem must be the first
unit in your library's USES clause AND your project's (select Project-View
Source) USES clause if your DLL exports any procedures or functions that
pass strings as parameters or function results. This applies to all strings
passed to and from your DLL--even those that are nested in records and
classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory
manager, which must be deployed along with your DLL. To avoid using
BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }

如果DLL输出的过程或函数带有长字符类型的参数,或者函数返回类型是长字符串或带有
长字符串元素的构造类型,Object Pascal规定无论是DLL还是调用它的程序必须把
ShareMem单元加到Uses部分。而ShareMem单元是从DelphiMM.DLL这个DLL中引入的接口单
元,因此这种程序分发时必须带有DelphiMM.DLL。Delphi建议为了避免使用
DelphiMM.DLL,传递字符串信息时使用PChar或ShortString类型参数。
 
写成这样试试
Function Zipfile(DFileName,SFileName:String):integer;Far;
External 'Compress.dll'
 
to wjiachun: 补充一下,项目文件(.Dpr)中也要把ShareMem方在Uses的开头(Dephi文档中没说这一点),
我试过pchar和shortstring都没用。
 
应该在 DLL 和 EXE 的 Project 源文件中第一个引用 ShareMem 单元,而不是在工程中所
包含的其它单元中引用。
并且按名字调用 DLL 中函数时要注意函数名大小写要一致。试试:
Function Zipfile;External 'Compress.dll' Name 'ZipFile';
你原来的是 'Zipfile',不知道是否你只是发贴时写错了。
 
我已经解决了,但到现在我也不明白为什么,我换了一种写法
 
后退
顶部