日期:2014-05-18  浏览次数:20778 次

C#调用Dephi的DLL尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
[DllImport("HighPowerDll.dll", CallingConvention = CallingConvention.StdCall)]

  public static extern int GetVcell_Index(int Devicechannum, int IndexSs, ref string mV);
此调用函数概率性的出现上述错误,已知对方的返回是pchar类型的。
关键大部分时间都是OK的,小概率的出现错误,时间延迟上都还是比较宽裕的,具体目测是因为string类型的错误?
还请大侠解答!!

------解决方案--------------------
如果是对方是pchar,这边你用byte*试试
------解决方案--------------------
StringBuilder
------解决方案--------------------
如果参数是传出,可以用StringBuilder,要预先分配足够空间。SB要转成float,可以先ToString,再parse呀。
------解决方案--------------------
C# code
[DllImport("HighPowerDll.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int GetVcell_Index(int Devicechannum, int IndexSs, IntPtr mV);