WSARecv 报 access violation 错误

使用事件模型写了一个可设置超时的Socket类,使用时老是要包First-chance exception at 什么access   violation错误

在debug->exceiptions...里勾上access   violation异常后,发现异常在WSARecv处,

        int rc = WSARecv(m_ConnSocket,
                        (WSABUF *)&_wsabufex,
                        1,
                        NULL, //lpNumberOfBytesRecvd
                        &Flags,
                        &m_RecvOverlapped,
                        NULL);

msdn里说当m_RecvOverlapped不为null时,lpNumberOfBytesRecvd可以为null:

"lpNumberOfBytesRecvd

A pointer to the number, in bytes, received by this call if the receive operation completes immediately. If the lpOverlapped parameter is non-NULL, this parameter is optional and can be set to NULL."

我信了。但这恰恰是报错的原因,传一个值进去后,解决了

        int rc = WSARecv(m_ConnSocket,
                        (WSABUF *)&_wsabufex,
                        1,
                        &NumberOfBytesRecvd,
                        &Flags,
                        &m_RecvOverlapped,
                        NULL);

你可能感兴趣的:(exception,socket,null,Access)