typedef struct
{
    int command;
CString str;
}data_struct;
data_struct data;
data.command=0;
data.str="Hello";
if(send(sockfd_client,(void*)data,m_messagesend.GetLength(),0)==-1)报编译错误  error C2440: 'type cast' : cannot convert from 'data_struct' to 'void *'

解决方案 »

  1.   

    if(send(sockfd_client,(char*)data,m_messagesend.GetLength(),0)==-1)请看函数声明:
    int send(
      SOCKET s,              
      const char FAR *buf,  
      int len,               
      int flags              
    );
      

  2.   

    if(send(sockfd_client,(char*)&data,m_messagesend.GetLength(),0)==-1)
    这样做是错的,发过去的里面包含的是CString结构的字段,并不包含真正的字符串
      

  3.   

    这种网络通讯数据加CString 是极极其危险跟错误,对方基本没法分析出你的CString
    我建议这样
    typedef struct
    {
      int command;
      char str[N];
    }data_struct;
    data_struct data;
    data.command=0;
    strcpy(data_struct.str,"Hello");
    if(send(sockfd_client,(void*)&data,sizeof(data_struct),0)==-1)
      

  4.   

    上面报错  send' : cannot convert parameter 2 from 'void *' to 'const char *'
      

  5.   

    if(send(sockfd_client,(void*)&data,sizeof(data_struct),0)==-1)
    写为
    if(send(sockfd_client,(char*)&data,sizeof(data_struct),0)==-1)网络中send的都应该是字节值,任何与地址及系统类型关联的变量都是很危险的
    基本类型的酸struct是没有问题的
    复杂的数据结构都是串行化以后再send