Delphi函数
function TestStr(var strValue:pChar):integer;我想用strValue返回参数,在C#中用如下几种方式调用都不行
[ DllImport(....)]
public static extern int TestStr(out string strValue);
.
.
调用:string s="";
      TestStr(out s);
    错误:未将对象引用为实例
[ DllImport(....)]
public static extern int TestStr(out StringBuild strValue);
.
.
.
调用:StringBuild s=new StringBuild(256);
      TestStr(out s);
      s变为Null;
请高手讲解

解决方案 »

  1.   

    去掉var和out修饰符看看如果不行,改为:
    [DllImport(....)]
    public static extern int TestStr([MarshalAs(UnmanagedType.LPTStr)]string strValue);
      

  2.   

    WinForm 和 ASP.Net 有区别吗?
    Eastunfail(恶鱼杀手)的方法我也试过,可能是Delphi的数据类型的问题。
    你们有没有用Delphi写过Dll,用参数来返回值在其它开发环境中调用成功啊(PB、VC、C#、VB等)。
    我写的Dll函数 function TestStr(var strValue:pChar):integer;
    在Delphi中能调用成功,能通过参数取到返回值,但是在其它的环境中都不成功。
      

  3.   

    要返回的字符串最好拷贝到一个新的区域中,然后strValue再指向这块新的区域.
      

  4.   

    PowerBuilder中不可能用地址和指针取到这些