大家帮我看一下这个DLL在D6中调用没问题,在PB中不能,我函数内容清空PB可以调用,为?(100分)

  • 主题发起人 主题发起人 beer_xjx
  • 开始时间 开始时间
B

beer_xjx

Unregistered / Unconfirmed
GUEST, unregistred user!
我把函数内容清空可以调用,但只要在里面写上一个条件语句就错误(PB中)
不知为什么,请高手指教/

library filemail;

{ 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. }
uses
ShareMem,
SysUtils,
Classes,
IdMessage,
IdPOP3,
IdBaseComponent,
IdComponent,
IdTCPConnection,
IdTCPClient,
IdMessageClient,
IdSMTP;

function getpop3(var mailserver:PChar;var port:integer;var account:PChar;var password:PChar ;var filepath:PChar ;var isdelete :PChar ;var isaccept:PChar):boolean ; stdcall;
var
ls_pathfile:string;
li_mailCount,li_next,li_nextAttch:longint;
id_pop:TIdpop3;
id_msg:Tidmessage;


begin
id_pop:=TIdpop3.Create(nil);
id_msg:=Tidmessage.Create(nil);
//如果已经连接,就断开
if id_pop.Connected then
begin
id_pop.Disconnect;
end;
//连接邮件服务器
id_pop.Host :=mailserver; //邮件服务器名
id_pop.Port :=port; //端口
id_pop.UserID :=account; //用户号
id_pop.Password := password; //密码
id_pop.Connect;//连接服务器

li_mailCount :=id_pop.CheckMessages ;//共有几封邮件,?怎样判断是否打开过??
{*当有邮件时,把所有的邮件的附件放在指定的
目录下面如果没有目录,建立一个把附件放在里面*}
if li_mailCount > 0 then
begin
for li_next:=0 to li_mailCount -1 do
begin
id_msg.Clear;
//返回一封信的附件
id_pop.Retrieve(li_next + 1, id_msg);
{*查看消息的附件部份,*}
for li_nextAttch := 0 to Pred(id_msg.MessageParts.Count) do
begin
if isaccept='T' then
begin
if (id_msg.MessageParts.Items[li_nextAttch] is TIdAttachment) then //如果是附件
begin //general attachment
{*得到一个文件名,进一步要判断一个目录是否存在,如果
不存在,还要建立一个目录*}
ls_pathfile:=filepath+TIdAttachment(id_msg.MessageParts.Items[li_nextAttch]).Filename;
//把文件存在传入的目录下
TIdAttachment(id_msg.MessageParts.Items[li_nextAttch]).SaveToFile(ls_pathfile);
end ;
end ;
end ;
end;
// id_pop.Free;
// id_msg.Free;
result:=true;
end
else
// id_pop.Free;
// id_msg.Free;
result :=false;
end ;
{$R *.res}
exports
getpop3 ;

begin
end.
 
问题应该出在这里
ls_pathfile:=filepath+TIdAttachment(id_msg.MessageParts.Items[li_nextAttch]).Filename;
你在dll中为ps_pathfile分配了局部内存(也许就在堆栈里), 函数返回时内存回收程序将该内存释放了。 也就是说返回之后ls_pathfile指向了无效地址。
 
接受答案了.
 
后退
顶部