宏是声明一些动态创建需要的函数和成员变量,错误为你访问了该类的保护成员_GetBaseClass成员。

解决方案 »

  1.   

    和RTTI差不多吧,就是Runtime Type Information,动态类型识别,可以看看侯捷《深入浅出mfc》。查mfc原代码也可以
      

  2.   

    这两个宏的作用是,使由CObject类派生的类能够被动态创建。
      

  3.   

    查mfc原代码
    #define DECLARE_DYNCREATE(class_name)  DECLARE_DYNAMIC(class_name)  static CObject* PASCAL CreateObject();
    #define DECLARE_DYNAMIC(class_name) public:  static const AFX_DATA CRuntimeClass class##class_name;  virtual CRuntimeClass* GetRuntimeClass() const; #define IMPLEMENT_DYNAMIC(class_name, base_class_name)  IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, NULL)
    #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew)  AFX_COMDAT const AFX_DATADEF CRuntimeClass class_name::class##class_name = {  #class_name, sizeof(class class_name), wSchema, pfnNew,  RUNTIME_CLASS(base_class_name), NULL };  CRuntimeClass* class_name::GetRuntimeClass() const  { return RUNTIME_CLASS(class_name); } #define RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))把IMPLEMENT_DYNAMIC改成IMPLEMENT_DYNCREATE就应该ok了。
      

  4.   

    重建此工程,或重建CClientSocket类,IMPLEMENT_DYNCREATE与DECLARE_DYNCREATE对应,但写成IMPLEMENT_DYNAMIC变译时应该不会报错。
      

  5.   

    我是改成IMPLEMENT_DYNCREATE,可还是有错!
      

  6.   

    重建CClientSocket类是什么意思?我改成IMPLEMENT_DYNAMIC也还是有错!?
      

  7.   

    用向导生成的工程么?把clientsocket.h和clientsocket.cpp贴出来看看吧。
      

  8.   

    重建CClientSocket类就是说把他Delete掉后重新再建过。
    IMPLEMENT_DYNAMIC与IMPLEMENT_DYNCREATE是两个层次上的宏,IMPLEMENT_DYNAMIC用来是程序具有运行时能的动态获取程序中使用的类的信息,IMPLEMENT_DYNCREATE宏就是在IMPLEMENT_DYNAMIC的基础之上加入了动态创建类的功能,IMPLEMENT_DYNCREATE与IMPLEMENT_DYNAMIC配对在编译时不会报错,但会使程序失去动态创建CCliengSocket类的能力。
      

  9.   

    #if !defined(AFX_CLIENTSOCKET_H__BAB0BE80_A92F_11D5_9436_0050FC2C2AE7__INCLUDED_)
    #define AFX_CLIENTSOCKET_H__BAB0BE80_A92F_11D5_9436_0050FC2C2AE7__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // ClientSocket.h : header file
    //
    #include "Afx.h"
      
    class CMsg;
    class CChatServerDlg;/////////////////////////////////////////////////////////////////////////////
    // CClientSocket command targetclass CClientSocket : public CSocket
    {
    DECLARE_DYNAMIC(CClientSocet);
    // Attributes
    public:// Operations
    public:
    CClientSocket(CChatServerDlg* pDlg);
    int m_nMsgCount;
    CSocketFile* m_pFile;
    CArchive* m_pArchiveIn;
    CArchive* m_pArchiveOut;
    CChatServerDlg* m_pDlg;
    BOOL IsAborted() {return m_pArchiveOut==NULL;}
    public:
    void Initialize();
    void Abort();
    void SendMessage(CMsg* pMsg);
    void ReceiveMessage(CMsg* pMsg);
    protected:
    virtual void OnReceive(int nErrorCode);
    public:
    virtual ~CClientSocket();
        
    // Overrides
    public:
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CClientSocket)

    //}}AFX_VIRTUAL // Generated message map functions
    //{{AFX_MSG(CClientSocket)
    // 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_CLIENTSOCKET_H__BAB0BE80_A92F_11D5_9436_0050FC2C2AE7__INCLUDED_)
    // ClientSocket.cpp : implementation file
    //#include "stdafx.h"
    #include "ChatServer.h"
    #include "ClientSocket.h"
    #include "Msg.h"
    #include "ChatServerDlg.h"
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CClientSocketCClientSocket::CClientSocket(CChatServerDlg* pDlg)
    {
       m_pDlg=pDlg;
       m_nMsgCount=0;
       m_pFile=NULL;
       m_pArchiveIn=NULL;
       m_pArchiveOut=NULL;
    }CClientSocket::~CClientSocket()
    {
    if(m_pArchiveOut!=NULL)
    delete m_pArchiveOut;
    if(m_pArchiveIn!=NULL)
    delete m_pArchiveIn;
    if(m_pFile!=NULL)
    delete m_pFile;
    }
    void CClientSocket::Initialize()
    {
    // m_pFile=new CSoketFile(this);
    m_pArchiveIn=new CArchive(m_pFile,CArchive::load);
    m_pArchiveOut=new CArchive(m_pFile,CArchive::store);
    }
    void CClientSocket::Abort()
    {
    if(m_pArchiveOut!=NULL)
    {
    m_pArchiveOut->Abort();
    delete m_pArchiveOut;
    m_pArchiveOut=NULL;
    }
    }
    void CClientSocket::SendMessage(CMsg* pMsg)
    {
    if(m_pArchiveOut!=NULL)
    {
    pMsg->Serialize(*m_pArchiveOut);
    m_pArchiveOut->Flush();
    }
    }
    void CClientSocket::ReceiveMessage(CMsg* pMsg)
    {
    pMsg->Serialize(*m_pArchiveIn);
    }
    void CClientSocket::OnReceive(int nErrorCode)
    {
    CSocket::OnReceive(nErrorCode);
    m_pDlg->OnReceive(this);
    }// Do not edit the following lines, which are needed by ClassWizard.
    #if 0
    BEGIN_MESSAGE_MAP(CClientSocket, CSocket)
    //{{AFX_MSG_MAP(CClientSocket)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    #endif // 0IMPLEMENT_DYNAMIC(CClientSocket,CSocket);
    /////////////////////////////////////////////////////////////////////////////
    // CClientSocket member functions
      

  10.   

    那样delede掉不是和现在的一样吗!?
    动态创建到底是个什么概念?
      

  11.   

    在VC中删除一个玩应后再建常常会有不同的结果(也许是我的D版VC有问题),我刚才试了一下,第一次也出现你的问题,但我重新建过后又没问题了。
    动态创建是说你的程序在运行的时候能够在需要的时候创建类,而不必在程序开始时就把收有的类全部放到内存中,等着别人来调用。
    把你的IMPLEMENT_DYNAMIC(CClientSocket,CSocket);DECLARE_DYNAMIC(CClientSocet);后面的“;”去掉。
      

  12.   

    我最后的提议就是改成这样:
    //DECLARE_DYNAMIC(CClientSocet);
    //IMPLEMENT_DYNAMIC(CClientSocket,CSocket);
    不用这个功能,一般来说也可以的。
      

  13.   

    包含了AFXSOCK.H也不行!
    如果//DECLARE_DYNAMIC(CClientSocet);
    //IMPLEMENT_DYNAMIC(CClientSocket,CSocket);
    编译没错但链接时出错如下:inking...
    ListeningSocket.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CListeningSocket::GetRuntimeClass(void)const " (?GetRuntimeClass@CListeningSocket@@UBEPAUCRuntimeClass@@XZ)
    Msg.obj : error LNK2001: unresolved external symbol "public: virtual struct CRuntimeClass * __thiscall CMsg::GetRuntimeClass(void)const " (?GetRuntimeClass@CMsg@@UBEPAUCRuntimeClass@@XZ)
    PorDlg.obj : error LNK2001: unresolved external symbol "protected: void __thiscall CPortDlg::OnStopServer(void)" (?OnStopServer@CPortDlg@@IAEXXZ)
    Debug/ChatServer.exe : fatal error LNK1120: 3 unresolved externals
    Error executing link.exe.ChatServer.exe - 4 error(s), 0 warning(s)