我想让用户调用我的DLL中的发信函数而不等待,这该怎么实现?
在多线程中调用DLL倒是简单,反过来我不会写。

解决方案 »

  1.   

    非常感谢!能不能详细一点?我的DLL中的函数是这样的用了INDY的两个控件,如何改成多线程的?function sendemailtome(myname,mailbox,subject,content,filename:pchar):pchar;export;stdcall;
    var
      IdMessage1:TIdMessage;
      IdSMTP1:TIdSMTP;
    begin
    if (pos('.',string(mailbox))=0) or (pos('@',string(mailbox))=0) or (trim(mailbox)='')then
      begin
      result:=pchar(string(mailbox)+'邮箱名不正确,不能发信!');
      exit;
      end;
    try
    try
    Idmessage1:=Tidmessage.Create(nil);
    IdSMTP1:=TIdSMTP.Create(nil);
    IdMessage1.Body.text:=(#13+#10+'__________________________________________________________________');
    if trim(filename)<>'' then
    if fileexists(filename) then
       begin
       Tidattachment.Create(idmessage1.MessageParts,filename);
       content:=pchar(content+#13+#10+#13+#10+'[本邮件包含附件,附件中的文件名是:'+extractfilename(filename)+']');
       end
       else
       content:=pchar(content+#13+#10+#13+#10+'[提示:本邮件应该包含附件,附件中的文件名是:'+
                              extractfilename(filename)+',但这是个文件在发信时不存在。]');
      IdMessage1.From.Name:=myname;    //发件人名字
      IdMessage1.From.Address :='[email protected]';
      IdMessage1.Recipients.EMailAddresses:=mailbox;  //收件人地址
      IdMessage1.Subject := subject; //邮件主题
      IdMessage1.Body.Text:=content+IdMessage1.Body.Text; //邮件正文
      IdSMTP1.Host := 'xxxxxxxxxx.com';
      IdSMTP1.Port := 25;
      IdSMTP1.AuthenticationType:=atlogin;
    // if not SMTPAuthority then      IdSMTP1.AuthenticationType:=atNone;  IdSMTP1.Username:='[email protected]';
      IdSMTP1.password:='demo';
      IdMessage1.Body.Append('邮件服务器的专用邮箱发送,请您不要回复此信。要得到更多信息,请浏览xxxxxxxxxxx网站。');
       try
        IdSMTP1.Connect;
       except
        result:='连接SMTP服务器失败!';
        exit;
       end;
        IdSMTP1.Send(IdMessage1);
        result:='发送成功';            //这个字串不能改,要识别
        except
         on E:exception do
         result:=pchar('发送失败,返回信息是:'+e.Message);
        end;
       finally
       IdSMTP1.Disconnect;
       FREEANDNIL(Idmessage1);
       FREEANDNIL(IdSMTP1);
       end;
    end;