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);就提示如上错误,请大侠多多赐教!
{
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);就提示如上错误,请大侠多多赐教!
#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 targetclass 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/////////////////////////////////////////////////////////////////////////////
// CListenSocketCListenSocket::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 functionsvoid 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 // 0void 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_)
#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 targetclass 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/////////////////////////////////////////////////////////////////////////////
// CListenSocketCListenSocket::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 functionsvoid 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 // 0void 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_)