+ -
当前位置:首页 → 问答吧 → delphi编写的dll,pb调用返回乱码

delphi编写的dll,pb调用返回乱码

时间:2011-12-16

来源:互联网

以下是我delphi编写的dll,用Pchar输出
library testDll;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls,ComObj;


{$R *.res}
 function getComput(inputStr:pchar; out outStr:pchar):integer;stdcall;export;
  begin
  try
  outstr := AllocMem(255);
  strcopy(outstr,'woshizhong');
  result := 0;
  showmessage(outstr) ;
  finally
  FreeMem(outstr);
  end;
  end;
exports
  getComput;
begin

end.
pb声明:
function integer getComput(string inputStr, ref String outStr) LIBRARY "testDll.dll"
pb调用:
string ls_outstr 
integer li_net
ls_outstr = space(256)
li_net = getComput('oooo',ls_outstr)
messagebox(string(li_net), ls_outstr)

出现乱码,如delphi用shortstring输出,则不会,但是会偏移位

作者: hanker1314520   发布时间: 2011-12-16

怎么没有人回答呢?现在没有人做delphi了吗

作者: hanker1314520   发布时间: 2011-12-18