Debug Assertion Failed错误

tang800710 2007-12-24 01:46:02
void CListenSocket::OnAccept(int nErrorCode)
{
CSessionSocket * pSession = new CSessionSocket(m_pDlg);
if (this->Accept (* pSession))
{
pSession->AsyncSelect(FD_READ);
m_pDlg->m_Sessions.AddTail (pSession);
}
CAsyncSocket::OnAccept(nErrorCode);
}

代码一执行到m_pDlg->m_Sessions.AddTail (pSession);就提示如上错误,请大侠多多赐教!
...全文
4317 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuflyme 2011-09-25
  • 打赏
  • 举报
回复
使用了野指针。
lovecjj 2011-05-25
  • 打赏
  • 举报
回复
我也遇到了相同的问题,求指教
tang800710 2007-12-24
  • 打赏
  • 举报
回复
#if !defined(AFX_LISTENSOCKET_H__7D60E31E_EF9F_4E4A_9FA1_2E285DD53095__INCLUDED_)
#define AFX_LISTENSOCKET_H__7D60E31E_EF9F_4E4A_9FA1_2E285DD53095__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ListenSocket.h : header file
//

class CSocketServerDlg;

/////////////////////////////////////////////////////////////////////////////
// CListenSocket command target

class CListenSocket : public CAsyncSocket
{
// Attributes
public:
CSocketServerDlg * m_pDlg;
// Operations
public:
CListenSocket();
CListenSocket(CSocketServerDlg*);
virtual ~CListenSocket();

// Overrides
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListenSocket)
public:
virtual void OnAccept(int nErrorCode);
//}}AFX_VIRTUAL

// Generated message map functions
//{{AFX_MSG(CListenSocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG

// Implementation
protected:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LISTENSOCKET_H__7D60E31E_EF9F_4E4A_9FA1_2E285DD53095__INCLUDED_)


// ListenSocket.cpp : implementation file

#include "stdafx.h"
#include "SocketServer.h"
#include "SocketServerDlg.h"
#include "ListenSocket.h"
#include "SessionSocket.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CListenSocket

CListenSocket::CListenSocket()
{
}

CListenSocket::CListenSocket(CSocketServerDlg *dlg)
{
m_pDlg=dlg;
}

CListenSocket::~CListenSocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CListenSocket, CAsyncSocket)
//{{AFX_MSG_MAP(CListenSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0

/////////////////////////////////////////////////////////////////////////////
// CListenSocket member functions

void CListenSocket::OnAccept(int nErrorCode)
{
CSessionSocket * pSession = new CSessionSocket(m_pDlg);
if (this->Accept (* pSession))
{
pSession->AsyncSelect(FD_READ);
m_pDlg->m_Sessions.AddTail (pSession);
}
CAsyncSocket::OnAccept(nErrorCode);
}
#if !defined(AFX_SESSIONSOCKET_H__1366CC59_9BCB_4BA4_B4BF_6E49EB705E14__INCLUDED_)
#define AFX_SESSIONSOCKET_H__1366CC59_9BCB_4BA4_B4BF_6E49EB705E14__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SessionSocket.h : header file
//

#include "SocketServerDlg.h"

/////////////////////////////////////////////////////////////////////////////
// CSessionSocket command target
//class CSocketServerDlg;

class CSessionSocket : public CAsyncSocket
{
// Attributes
public:
CSocketServerDlg * m_pDlg;
char m_szMsg[4096];
// Operations
public:
CSessionSocket();
CSessionSocket(CSocketServerDlg *);
virtual ~CSessionSocket();

// Overrides
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSessionSocket)
public:
virtual void OnReceive(int nErrorCode);
//}}AFX_VIRTUAL

// Generated message map functions
//{{AFX_MSG(CSessionSocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG

// Implementation
protected:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SESSIONSOCKET_H__1366CC59_9BCB_4BA4_B4BF_6E49EB705E14__INCLUDED_)

// SessionSocket.cpp : implementation file
//

#include "stdafx.h"
#include "SocketServer.h"
#include "SessionSocket.h"
#include "SocketServerDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSessionSocket
CSessionSocket::CSessionSocket(CSocketServerDlg * dlg)
{
this->m_pDlg = dlg;
memset(this->m_szMsg,0,sizeof(this->m_szMsg));
}

CSessionSocket::CSessionSocket()
{
}

CSessionSocket::~CSessionSocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CSessionSocket, CAsyncSocket)
//{{AFX_MSG_MAP(CSessionSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0

void CSessionSocket::OnReceive(int nErrorCode)
{
this->Receive(this->m_szMsg,sizeof(this->m_szMsg),0);
m_pDlg->m_List.InsertString(0,this->m_szMsg);
CAsyncSocket::OnReceive(nErrorCode);
}


// SocketServerDlg.h : header file
//

#if !defined(AFX_SOCKETSERVERDLG_H__51F36F4F_2EDC_484C_B2B2_BAB539C74AFC__INCLUDED_)
#define AFX_SOCKETSERVERDLG_H__51F36F4F_2EDC_484C_B2B2_BAB539C74AFC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ListenSocket.h"
//#include "SessionSocket.h"

/////////////////////////////////////////////////////////////////////////////
// CSocketServerDlg dialog
class CSessionSocket;
class CSocketServerDlg : public CDialog
{
// Construction
public:
CSocketServerDlg(CWnd* pParent = NULL); // standard constructor
CPtrList m_Sessions;
// Dialog Data
//{{AFX_DATA(CSocketServerDlg)
enum { IDD = IDD_SOCKETSERVER_DIALOG };
CListBox m_List;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSocketServerDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;
UINT m_nPort;
CListenSocket m_Listen;

// Generated message map functions
//{{AFX_MSG(CSocketServerDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnList();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SOCKETSERVERDLG_H__51F36F4F_2EDC_484C_B2B2_BAB539C74AFC__INCLUDED_)

tang800710 2007-12-24
  • 打赏
  • 举报
回复
#if !defined(AFX_LISTENSOCKET_H__7D60E31E_EF9F_4E4A_9FA1_2E285DD53095__INCLUDED_)
#define AFX_LISTENSOCKET_H__7D60E31E_EF9F_4E4A_9FA1_2E285DD53095__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ListenSocket.h : header file
//

class CSocketServerDlg;

/////////////////////////////////////////////////////////////////////////////
// CListenSocket command target

class CListenSocket : public CAsyncSocket
{
// Attributes
public:
CSocketServerDlg * m_pDlg;
// Operations
public:
CListenSocket();
CListenSocket(CSocketServerDlg*);
virtual ~CListenSocket();

// Overrides
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListenSocket)
public:
virtual void OnAccept(int nErrorCode);
//}}AFX_VIRTUAL

// Generated message map functions
//{{AFX_MSG(CListenSocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG

// Implementation
protected:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LISTENSOCKET_H__7D60E31E_EF9F_4E4A_9FA1_2E285DD53095__INCLUDED_)


// ListenSocket.cpp : implementation file

#include "stdafx.h"
#include "SocketServer.h"
#include "SocketServerDlg.h"
#include "ListenSocket.h"
#include "SessionSocket.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CListenSocket

CListenSocket::CListenSocket()
{
}

CListenSocket::CListenSocket(CSocketServerDlg *dlg)
{
m_pDlg=dlg;
}

CListenSocket::~CListenSocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CListenSocket, CAsyncSocket)
//{{AFX_MSG_MAP(CListenSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0

/////////////////////////////////////////////////////////////////////////////
// CListenSocket member functions

void CListenSocket::OnAccept(int nErrorCode)
{
CSessionSocket * pSession = new CSessionSocket(m_pDlg);
if (this->Accept (* pSession))
{
pSession->AsyncSelect(FD_READ);
m_pDlg->m_Sessions.AddTail (pSession);
}
CAsyncSocket::OnAccept(nErrorCode);
}
#if !defined(AFX_SESSIONSOCKET_H__1366CC59_9BCB_4BA4_B4BF_6E49EB705E14__INCLUDED_)
#define AFX_SESSIONSOCKET_H__1366CC59_9BCB_4BA4_B4BF_6E49EB705E14__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SessionSocket.h : header file
//

#include "SocketServerDlg.h"

/////////////////////////////////////////////////////////////////////////////
// CSessionSocket command target
//class CSocketServerDlg;

class CSessionSocket : public CAsyncSocket
{
// Attributes
public:
CSocketServerDlg * m_pDlg;
char m_szMsg[4096];
// Operations
public:
CSessionSocket();
CSessionSocket(CSocketServerDlg *);
virtual ~CSessionSocket();

// Overrides
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSessionSocket)
public:
virtual void OnReceive(int nErrorCode);
//}}AFX_VIRTUAL

// Generated message map functions
//{{AFX_MSG(CSessionSocket)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG

// Implementation
protected:
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SESSIONSOCKET_H__1366CC59_9BCB_4BA4_B4BF_6E49EB705E14__INCLUDED_)

// SessionSocket.cpp : implementation file
//

#include "stdafx.h"
#include "SocketServer.h"
#include "SessionSocket.h"
#include "SocketServerDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSessionSocket
CSessionSocket::CSessionSocket(CSocketServerDlg * dlg)
{
this->m_pDlg = dlg;
memset(this->m_szMsg,0,sizeof(this->m_szMsg));
}

CSessionSocket::CSessionSocket()
{
}

CSessionSocket::~CSessionSocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CSessionSocket, CAsyncSocket)
//{{AFX_MSG_MAP(CSessionSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0

void CSessionSocket::OnReceive(int nErrorCode)
{
this->Receive(this->m_szMsg,sizeof(this->m_szMsg),0);
m_pDlg->m_List.InsertString(0,this->m_szMsg);
CAsyncSocket::OnReceive(nErrorCode);
}


// SocketServerDlg.h : header file
//

#if !defined(AFX_SOCKETSERVERDLG_H__51F36F4F_2EDC_484C_B2B2_BAB539C74AFC__INCLUDED_)
#define AFX_SOCKETSERVERDLG_H__51F36F4F_2EDC_484C_B2B2_BAB539C74AFC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ListenSocket.h"
//#include "SessionSocket.h"

/////////////////////////////////////////////////////////////////////////////
// CSocketServerDlg dialog
class CSessionSocket;
class CSocketServerDlg : public CDialog
{
// Construction
public:
CSocketServerDlg(CWnd* pParent = NULL); // standard constructor
CPtrList m_Sessions;
// Dialog Data
//{{AFX_DATA(CSocketServerDlg)
enum { IDD = IDD_SOCKETSERVER_DIALOG };
CListBox m_List;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSocketServerDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;
UINT m_nPort;
CListenSocket m_Listen;

// Generated message map functions
//{{AFX_MSG(CSocketServerDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnList();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SOCKETSERVERDLG_H__51F36F4F_2EDC_484C_B2B2_BAB539C74AFC__INCLUDED_)

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧