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

解决方案 »

  1.   

    我以前与遇到这样的问题,
    应该就是你的DLL中的接口没有做好呀
    你可以贴出来,让我们大家帮你看看呀
      

  2.   

    没用过pb的路过,不过乱码通常是几个问题造成的
    1 stdcall和cdecl 
    2 ansi和unicode
    3 delphi中使用了string字符串从你的代码看 把这句换成move例如
      sKey := 'woshizhong';
        iKey := length(sKey) + 1;
        GetMem(outStr, iKey);
        Move(sKey[1], outStr^, iKey);
      

  3.   

    另外LZdll的返回值的分配和释放在调用函数处理,你这样写会有问题
      

  4.   

    sKey := 'woshizhong';
    iKey := length(sKey) + 1;
    GetMem(outStr, iKey);
    Move(sKey[1], outStr^, iKey);按照楼上的写法还是出现乱码,不知道怎么做好呢?真是好想没有办法?
      

  5.   

    改为调用时分配内存,不是在dll里面分配,修饰词Out不要;function getComput(inputStr:pchar; outStr:pchar):integer;stdcall;export;
    begin
     strcopy(outstr,inputStr);
     result := 100;
    end;delphi调用,PB的自己改一下:
    var
     k:integer;
     P:pchar;
    begin
      p:=stralloc(1024);
      try
      k:=getComput('测试',P);
      showmessage(Inttostr(k)+','+P);//返回'100,测试'
      finally
        strdispose(p);
      end;
    end;
      

  6.   

    以下是我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;
    beginend.
    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输出,则不会,但是会偏移位第一delphi的定义应该是: function getComput(inputStr:pchar; outStr:pchar):integer;stdcall;export;
    var
      vString: String;
    begin
      try
        vString := 'woshizhong';
        move(PChar(vString)^, outstr^, length(vString));
        result := 0;
      except
        result := -1;
      end;
    exports
      getComput;
    beginend.第二、PB调用就是按你写的就可以了第三、如delphi用shortstring输出,则不会,但是会偏移位这是因为shortstring 类型第一个字节存放的是该字符的长度,应该会偏移一位;
      

  7.   

    这是因为shortstring 类型第一个字节存放的是该字符的长度,应该会偏移一位;=》【偏移一字节】
      

  8.   

    强烈建议用kaikai_kk的方法,pchar就可以了。
    inputStr:pchar;  outStr:pchar
      

  9.   

    感谢xhz2000,解决了乱码的问题