日期:2014-05-18 浏览次数:20911 次
[DllImport("JFNetLib.dll", EntryPoint = "SetRemoteServerAddr")] public static extern void SetRemoteServerAddr(Int64 nSvrPort, string szSvrAddr); [DllImport("JFNetLib.dll", EntryPoint = "SendRequestPack")] public static extern Int64 SendRequestPack(string sendbuf, Int64 sendlen, StringBuilder recvbuf, out Int64 recvlen, Int64 waitsecs); Int64 dk = 8800; string sbIP = "192.168.0.80"; string sbCS = "EXCHCODE=GY01&HOSCODE=0C01"; StringBuilder sbJG = new StringBuilder(65535); long length; SetRemoteServerAddr(dk, sbIP); int cnt = (int)SendRequestPack(sbCS, sbCS.Length, sbJG, out length, 200); MessageBox.Show(cnt.ToString()); MessageBox.Show(sbJG.ToString());
------解决方案--------------------
1、把所有Int64改为Int32。因为在C++中long类型其实和int一样只是32位的
2、int cnt = (int)SendRequestPack(sbCS, sbCS.Length, sbJG, sbJG.Length, 200);
传入sbJG.Length是不对的。因为sbJG创建后只是提供了1024字节的容量,但其实际长度Length = 0。可以传入sbJG.Capacity或者小于sbJG.Capacity的实际希望读取的字节数目