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 *'
{
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 *'
解决方案 »
- internetsession类连接代码异常怎么会被触发?
- 急!急!急!添加有DataGrid控件的应用程序打包后,在别的机器上不能显示出控件,使用静态链接库编译也不行。。。
- 有没有直接双击我的电脑’后出来的一样的系统窗口的WINAPI
- 响应WM_MOUSEWHEEL消息的问题
- 如何调用存储过程,并取得存储过程的返回的数据。
- 高手回帖啊!!用VC编程,怎样预防编辑框的*号密码被其他程序获得啊??
- 窗口一变化,窗口中的东东就没有了,求助。
- 如何改变框架初始大小啊?
- 请问一个字串问题
- 如何实现(调用shell)“发送到”快捷菜单
- 有没朋友使用过winrar的unrar.dll库?
- 请教一个简单问题
int send(
SOCKET s,
const char FAR *buf,
int len,
int flags
);
这样做是错的,发过去的里面包含的是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)
写为
if(send(sockfd_client,(char*)&data,sizeof(data_struct),0)==-1)网络中send的都应该是字节值,任何与地址及系统类型关联的变量都是很危险的
基本类型的酸struct是没有问题的
复杂的数据结构都是串行化以后再send