[DllImport("HighPowerDll.dll", CallingConvention = CallingConvention.StdCall)] public static extern int GetVcell_Index(int Devicechannum, int IndexSs, ref string mV);
此调用函数概率性的出现上述错误,已知对方的返回是pchar类型的。
关键大部分时间都是OK的,小概率的出现错误,时间延迟上都还是比较宽裕的,具体目测是因为string类型的错误?
还请大侠解答!!
此调用函数概率性的出现上述错误,已知对方的返回是pchar类型的。
关键大部分时间都是OK的,小概率的出现错误,时间延迟上都还是比较宽裕的,具体目测是因为string类型的错误?
还请大侠解答!!
function GetVcell_Index(Devicechannum,IndexSs:Integer;var mV:widestring):Integer;stdcall;
这里widestring已经叫他修改为pchar。他已经说修改了,不过是否修改掉我就没法知道了。
只是已经可以大概率正常读取了。
StringBuilder确实应该试试,不过StringBuilder我要转换为float的怎么转?
已经不能用float.parse(string).
public static extern int GetVcell_Index(int Devicechannum, int IndexSs, IntPtr mV);string mv = 参数mv的值;
byte[] arr = new byte[mv.Length * 2];
Encoding.ASCII.GetBytes(mv, 0, mv.Length, arr, 0);
IntPtr p = Marshal.AllocHGlobal(arr.Length);
Marshal.Copy(arr, 0, p, arr.Length);
GetVcell_Index(第一个参数, 第二个参数, p);
mv = Marshal.PtrToStringAnsi(p);
Marshal.FreeHGlobal(p);这样试下