OVERLAPPED over;
ZerMemory(&over,sizeof(OVERLAPPED));
WSASend(s, &DataBuf, 1, &SendBytes, 0,&over, NULL);
这样能成功.
如果不执行ZerMemory(&over,sizeof(OVERLAPPED));
WSASend就会失败,错误是"句柄无效",请问高手这是为什么?
还有,如果同时执行两次WSASend,OVERLAPPED只有一个,能成功吗?系统是怎样分别出哪次WSASend?
谢谢!
======================================================================================
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
DWORD Offset;
DWORD OffsetHigh;
HANDLE hEvent;
} OVERLAPPED;
注意结构里有HANDLE hEvent
当没使用ZeroMemory时,hEvent被填充为0xCCCCCCCC,或其他的,就会出现"句柄无效"的错误
======================================================================================
但使用了ZeroMemory时,hEvent被填充为0x00000000,也不是一个有效的句柄呀,继续.
======================================================================================
sdk的代码中hEvent = NULL。这就是原因!因为你可以不使用事件的,看msdn吧!