Delphi DLL 函数原型:function MyFun(key:PChar;var name:PChar):boolean;stdcall;export;
begin
  name := StrAlloc(StrLen(key) + 1);
  StrCopy(name,key);
  result := TRUE;
end;PB申明:
function boolean MyFun(string key,ref string name) Library "MyFun.dll"PB调用:
string ls_key,ls_name
ls_key = "ME"
MyFun(ls_key,ls_name)
MessageBox(ls_key,ls_name)问:提示内容却不是"ME"了,为什么?

解决方案 »

  1.   

    我以前用Delphi写过dll给PB用,,,在字符串处理上有一点比较特殊的地方,我说不出是什么原因。如果通过DLL的变参返回字符串,用DELHPI写一个测试EXE程序,DLL中形参要说明为var但如果是PB调用,,就不用VAR,,,楼主把Delphi DLL 函数原型改为试试:function MyFun(key:PChar; name:PChar):boolean;stdcall;export;
      

  2.   

    你也可以将 StrCopy(name,key);换成这个函数:StrPCopy
    function StrPCopy(Dest: PChar; const Source: string): PChar;
    Description
    StrPCopy copies a Pascal-type string Source into a null-terminated string Dest. It returns a pointer to Dest.
    StrPCopy does not perform any length checking. The destination buffer must have room for at least Length(Source)+1 characters.另外也有这种可能:
      

  3.   

    多谢鱼,将 StrCopy 改为 StrPCopy 搞定。