function wsf_getJyxx(soap_endpoint:string;username:string;password:string;zsbh:string;ret:pchar):Integer; stdcall; external 'pimsservice.dll'; //函数声明
delphi中函数如下:
var
soap_endpoint : string;
zsbh : string;
username : string;
password : string;
iReturn : Integer;
ret :  Array[0..2000] of Char;
begin
soap_endpoint :=  'http://1.0.0.225:8080/PIMSService/service/DataService/';
zsbh := 'DL09T00026';
username := 'admin';
password := 'admin';
iReturn := wsf_getJyxx(soap_endpoint,username,password,zsbh,@ret[0]);
showmessage(ret);
end;
为什么返回值为乱码,是不是数组内存不够?小弟初次接触delphi,望各位大虾指教

解决方案 »

  1.   

    情况有很多
    c++里喜欢用指针,把你的string类型先改为pchar试试
      

  2.   

    另外能看到源码的话c里的dll声明最好贴出来或者c里调用dll的代码贴出来
      

  3.   

    传向dll的参数没有乱码,返回值ret显示为乱码
      

  4.   

    C++声明
    const int __stdcall wsf_getJyxx(char *soap_endpoint, char* username, char* password, char* zsbh,char* ret);
      

  5.   

    在delphi中怎样定义接收dll中的返回值
      

  6.   

    C++声明
    const int __stdcall wsf_getJyxx(char *soap_endpoint, char* username, char* password, char* zsbh,char* ret);function wsf_getJyxx(soap_endpoint, username,password,  zsbh, ret:pchar ):integer; stdcall;
      

  7.   

    我是这样声明的,但是怎样在方法中定义接收ret的值呢
      

  8.   

    感觉Lz的接收代码没错,但是传参用的string是delphi特有的,和其他语的string类型不同的,LZ确定c代码里收到的传入参数正确么?
    5L的声明可都是pchar类型啊
      

  9.   

    或者就换pchar看看
    p:PChar; 
    GetMem(p,1024); 
    wsf_getJyxx(soap_endpoint,username,password,zsbh,p);
      

  10.   

    soap_endpoint值传的对不对?
    从地址构造形式上看是使用java、xfire实现的WS,去掉soap_endpoint地址最后一个/试试。
      

  11.   

    function wsf_getJyxx(soap_endpoint,username,password,zsbh:pchar; var ret:pchar):Integer; stdcall; external 'pimsservice.dll'; //函数声明
    delphi中函数如下:
    var
    soap_endpoint : string;
    zsbh : string;
    username : string;
    password : string;
    iReturn : Integer;
    ret : Array[0..2000] of Char;
    testret:pchar;
    retstr:string;
    begin
    soap_endpoint := 'http://1.0.0.225:8080/PIMSService/service/DataService/';
    zsbh := 'DL09T00026';
    username := 'admin';
    password := 'admin';
    GetMem(testret,1024);
    try
    iReturn := wsf_getJyxx(pchar(soap_endpoint),pchar(username),pchar(password),pchar(zsbh),testret);
    retstr:=testret;
    finally
    FreeMem(testret);
    end;
    showmessage(retstr);
    end;
    --------------------------------------------------------
    试试按地址传递参数看看行不行。
      

  12.   


    给字符数组分配下内存空间
    GetMem(ret,2000);
      

  13.   

     VC  用 char * delphi  用 Pchar 对应    应该没问题,我用过。
      

  14.   

    前面4个参数应该没问题吧,都是Pchar即可
    后一个ret看你的调用,应该是返回的字符类型的数组指针试试这样:
    function wsf_getJyxx(soap_endpoint, username,password, zsbh:Pchar var ret:array of Pchar):integer;...使用
    var
      i:integer;
      P:array of PChar;
    begin
      setlength(P,20); //设置数组长度20,注意不能少于函数wsf_getJyxx体内的
      for i:=low(P) to high(P) do //初始化; 初始化就已经分配内存,不须要另外分配
        P[i]:='';  
      i:=wsf_getJyxx('A','A','A','A',P);//调用,A改成具体的值
      showmessage(P[0]); //访问任一个看看P[0]到P[20]
      setlength(P,0);  
    end;另:如果知道数组长度,直接定义就好,不用动态
      

  15.   

    zsbh:string;ret:pchar):
    这个定义成成var ret:pchar