调用一个delphi编译的dll,文档中申明:
Procedure ZWTutor(PBuff:PChar);cdecl;export;
同时告诉我返回的值在程序中直接传给了PBuff参数。现在在c#中调用功能都是正常的,就是无法得到PBuff的值,请问有什么办法能够实现这个需求?

解决方案 »

  1.   

    这是个指针,用
    ref char k;这样的参数试试。
      

  2.   

    你说的ref char k是不是c#中定义的类型
      

  3.   

    c#中定义如下:
    [DllImport(dllName,CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Ansi, EntryPoint="ZWTutor")]
    public static extern void ZWTutor(string sFormula);
      

  4.   

    c#中定义如下:
    [DllImport(dllName,CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Ansi, EntryPoint="ZWTutor")]
    public static extern void ZWTutor( ref string sFormula);
      

  5.   

    你先要去问分配内存是由外部分配还是他delphi内部分配的。从他的声明形式来看,应该是外部分配。如果是外部分配,你就这么声明[DllImport(dllName,CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Ansi, EntryPoint="ZWTutor")] 
    public static extern void ZWTutor( StringBuilder formula );调用之前先new StringBuilder(256);然后传入。
      

  6.   

    内部分配不太可能,从他给你的api声明来看,内部分配的指针是没办法传出来的,除非他用指针的指针。