小弟,在主程序調用自己寫的封裝了Indy MD5的DLL,調用是正常,但是在退出調用后的過程時報錯。
DLL代碼:library DMS_CommFun;
uses
  SysUtils,
  Classes,
  IdHashMessageDigest,
  IdGlobal,
  IdHash;function EncString(SourceString : String) : String ; stdcall;
var
  md5Str : TIdHashMessageDigest5;
begin
  if SourceString <> '' then begin
     md5Str := TIdHashMessageDigest5.Create;
     result := md5Str.AsHex(md5Str.HashValue(SourceString));
     md5Str.Free;
    end
  else
    result := '';
end;exports
  EncString;
begin
end.
主程序調用模塊
    if EncString(NowUser.strPassword) <> dm_Public.ADOD.FieldByName('Password').Value  then begin
      dm_Public.ADOD.Close;
      bsMessage.MessageDlg2('Invaild user name or password!','Login',mtError,[mbOK],0);
      edit_User.Enabled := True;
      edit_Password.Enabled := True;
      exit;
end;主程序執行到exit時報錯“Invaild pointer operation”
將EncString(NowUser.strPassword)替換成常量后沒有報錯。求高手指點是否DLL寫的有問題。

解决方案 »

  1.   

    string 换成 pchar,代码再稍微改一下。。或者理论上,加sharemem和BORLNDMM.DLL参照
    { 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. }
      

  2.   

    搞定,謝謝高手,固然改成Pchar,OK!