动态库test.dll
用C语言编写,支持各种编程语言调用。函数原型:
void fun(const char *in, char** out)   in: 传入参数,为加密后的密文字符串。
  out:传出参数,为解密后的返回明文字符串。
调用方法:
  char** out
  fun('ABCDEF',out)
以上是DLL说明;
我在程序中做如下调用
procedure discryptpassword (const instr : PChar  ; var outstr : PPchar) ;stdcall;external'stkey.dll';
.
.
.
.
var
   instr , outstr : string;
   pin : PChar;
   pout : PChar;
   ppout : PPChar;
begin
    instr := pwdlist[ComboBox1.ItemIndex];   //取加密的字符串
    pin := Pchar(instr);    pout := Pchar(outstr);
    ppout := @pout ;    showmessage(instr);
    discryptpassword(pin , ppout);   //解密
    showmessage(outstr) ;
end;但是调用后的outstr 还是个空串,没有得到对应的明文.

解决方案 »

  1.   

    理论上这样调用是没有问题的var
    s:string;
    outstr : PPchar;
    begin
      s:='212121';
      discryptpassword (PChar(s) ,outStr );
    end;
      

  2.   

    是不是delphi和dll里的调用约定不一样
      

  3.   

    var
    s:string;
    outstr : PChar;
    begin
    try  
    outstr:=stralloc(1024);
      s:='212121';
      discryptpassword (PChar(s) ,outStr );
    finally
    strdispose(outstr);
    end;
    end;
      

  4.   

    可以分静态和动态调用,上面说的都是静态调用,下面的是动态调用你可以试试
    procedure TForm1.Button1Click(Sender: TObject); 
    type 
    TAddNumber=function(Num1,Num2:Integer):Integer;stdcall; 
    Var 
    aptr:TFarproc; 
    Lhnd:THandle; 
    s,t,d:integer; 
    begin 
    s:=1; 
    t:=3; 
    Lhnd:=Loadlibrary('AddNum.dll'); 
    aptr:=GetprocAddress(lhnd,'AddNumber'); 
    d:=TAddNumber(aptr)(s,t); 
    Edit1.Text:=IntToStr(d); 
    FreeLibrary(Lhnd); 
    end;