debug assertion failed MFC
场景:MFC Debug Assertion Failed!解决办法
MFC Debug Assertion Failed!
出错部分代码如下:
CClientSocket 类
图片1

图片2

图片3

图1图2出错相关代码:
图3出错相关代码
------解决方案--------------------
以后出现这种问题一定要把调用堆栈贴出来。
MFC Debug Assertion Failed!
出错部分代码如下:
bool LinkLicenseServer()
{
if(!AfxSocketInit())
{
AfxMessageBox(L"Error 201:Socket Initial Failed!");
return false;
}
CClientSocket *clientSocket;
clientSocket = new CClientSocket();
clientSocket->AsyncSelect(FD_READ|FD_WRITE|FD_OOB); //在此弹出图片1和2
CString m_strServer=LicenseIP;
long licport = _wtol(LicensePort);
if(!clientSocket->Create()) //在此第三张图片弹出两遍
{
::AfxMessageBox(L"Error 202:Connect to the License server failed!");
return false;
}
if(!clientSocket.Connect(m_strServer,licport))
{
::AfxMessageBox(L"Error 203:Connect to the License server failed!");
return false;
}
......
}
CClientSocket 类
#include "StdAfx.h"
#include "ClientSocket.h"
#include "tagHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CClientSocket::CClientSocket(void)
{
}
CClientSocket::~CClientSocket(void)
{
}
void CClientSocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CString Msg;
char buff[1000];
memset(buff,0,sizeof(buff));
Receive(buff, sizeof(buff),2);
Msg =CString(buff).Mid(1);
long t1=GetTickCount();
while(Msg.GetLength()!=buff[0])
{
long t2=GetTickCount();
if((t2-t1)/1000>5)
{
this->Close() ;
return;
}
Receive(buff, sizeof(buff),2);
Msg =CString(buff).Mid(1);
}
Receive(buff, sizeof(buff),0);
receivecheck=Msg;
isreceivecheck=true;
CSocket::OnReceive(nErrorCode);
}
图片1
图片2
图片3
图1图2出错相关代码:
BOOL CAsyncSocket::AsyncSelect(long lEvent)
{
ASSERT(m_hSocket != INVALID_SOCKET);//第386行
_AFX_SOCK_THREAD_STATE* pState = _afxSockThreadState;
ASSERT(pState->m_hSocketWindow != NULL);//第389行
return WSAAsyncSelect(m_hSocket, pState->m_hSocketWindow,
WM_SOCKET_NOTIFY, lEvent) != SOCKET_ERROR;
}
图3出错相关代码
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
{ ASSERT(afxCurrentInstanceHandle != NULL);//第21行
return afxCurrentInstanceHandle; }
mfc
断言
------解决方案--------------------
以后出现这种问题一定要把调用堆栈贴出来。