50分求助。Delphi代码类型如下:
 Tdll = function(fid:Integer; ostr : PChar; out tests : WideString):Integer;cdecl;
定义一些变量如下:
  re : Integer;
  Td : Tdll;
  mystr : array[1..20] of char;
  ss : WideString;
初始化如下:
ss:='input for test';
调用方式如下:
re := Td(8888, @mystr[1], ss);VC DLL接口:
__declspec(dllexport) int Td(int iFunction, char *ostr, BSTR ss);
函数内容:
__declspec(dllexport) int Td(int iFunction, char *ostr,  BSTR ss)
{
strcpy(ostr,"111111111");
ss = CComBSTR("This is a test");
return 1;
}结果:函数调用没问题,函数返回值没问题,参数中的ostr : PChar参数能返回,但是WideString死活返回不了!!!,请大家帮忙。
WideString

解决方案 »

  1.   

    //String、WideString是Delphi特有类型,不能作为DLL参数传递
    //使用PWideChar代替
    //可能是这样 Tdll = function(fid: Integer; ostr: PChar; ss: PWideChar): Integer; cdecl;  mystr : array[1..20] of char;
      ss: PWideChar;re := Td(8888, @mystr[1], ss);
      

  2.   

    解决是解决了。我的解决办法是:Delphi里面用PChar,vc里面用char * 这样在传入参数时预先分配好内存,同时与VC约定一个最大空间(或者传入size),这样在调用前先把WideString转换为PChar,返回结果再转换为WideString.主要我传入传出的都是XML结构的字符串,所以有这个问题啊。