据说vb6中,字 符串以以UNICODE方式存储,所以
Private Type UDT lngM1 As Long lngM2 As Long strM3 As String * 18 strM4 As String * 8 lngM5 As Long End Type Private Sub Command4_Click() Dim tmp As UDT With tmp .lngM1 = 1 .lngM2 = 2 ' .strM3 = "一二三四五六七八九十一二三四五六七八" .strM3 = "一二三四五六七八九" ' .strM3 = "ABCD" .strM4 = "测试ABC" .lngM5 = 5 End With Dim bytBuf() As Byte ReDim bytBuf(Len(tmp) - 1) CopyMemory bytBuf(0),tmp,Len(tmp) Winsock1.SendData bytBuf End Sub
vc6中定义相对应的结构体:
typedef struct{ long lM1; long lM2; char szM3[18]; char szM4[8]; long lM5; }UDT; //。。。。。。(省略部分代码) char recvBuf[128]; UDT t; while(true) { memset(&t,sizeof(t)); memset(recvBuf,sizeof(recvBuf)); //接收数据 int recvlen=recvfrom(svr,recvBuf,128,(sockaddr*)&addrClient,&len); ::CopyMemory(&t,128); } //。。。。。。。
通过socket传到vc里进行调试如下:
二、当 vb中调整代码为(.strM3 )
显然,不是UNICODE的表示方法
另人郁闷??????
----------------------------------------------------------
添加 tmp.strM3 = StrConv(tmp.strM3,vbUnicode):