求帮忙,为什么我用char[50]给CString赋值会少值?
本帖最后由 VisualEleven 于 2013-01-09 11:01:25 编辑
1CString m_StringID;
2CString m_StringPassword;
3CString m_StructData; //将要传输给服务器的字符串
4char temp[50];
5
6REQU_EXCHANGE_DATA LoadData;
7LoadData.flag = 0x7878;
8LoadData.type = US_LOAD_ON;
9
10m_Edit_ID.GetWindowText(m_StringID); //获取用户输入的账号和密11码
12m_Edit_Password.GetWindowText(m_StringPassword);
13/*m_IDandPassword = m_StringID+m_space+m_StringPassword; */
14if(m_StringID.IsEmpty() || m_StringPassword.IsEmpty())
15{
16MessageBox(_T("账号或密码不能为空!"));
17return;
18}
19
20sprintf(LoadData.InstrumentID,"%s",m_StringID); //Cstring转char[]
21sprintf(LoadData.TradingDay,"%s",m_StringPassword);
22
23memcpy(temp,&LoadData,sizeof(REQU_EXCHANGE_DATA)); //将结构体中的数据拷24贝到字符串中
25m_StructData=temp;
26WSABUF wsabuf;
27DWORD dwsend;
28int len;
29SOCKADDR_IN addrto;
30
31addrto.sin_addr.S_un.S_addr = inet_addr("192.9.169.140");
32addrto.sin_family = AF_INET;
33addrto.sin_port = htons(9528);
34
35 len = m_StructData.GetLength();
36wsabuf.buf = m_StructData.GetBuffer(len);
37wsabuf.len = len+1;
if (SOCKET_ERROR == WSASendTo(socketUdp,&wsabuf,1,&dwsend,0,(SOCKADDR*)&addrto,sizeof(SOCKADDR),NULL,NULL))
{
int error = 0;
error = WSAGetLastError();
MessageBox((_T("Send(Login) data failed!")));
return;
}