delphi编写的dll,pb调用返回乱码
以下是我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输出,则不会,但是会偏移位