宏是声明一些动态创建需要的函数和成员变量,错误为你访问了该类的保护成员_GetBaseClass成员。
解决方案 »
- 与delphi中Inherited相同作用的函数在VC中是哪个函数?
- 1万可用分,大家要多少我就散多少(二)
- 明白了,散分
- 系统托盘怎样弹出气球提示?
- VC写的DLL如何在VB中调用?比如一个函数有CString类型,VB能调吗?怎样声明?
- 自己写录音程序
- 如果我dll中资源ID和我的EXE里资源ID发生冲突,如何解决 ?
- 恳请高手帮忙
- 求助
- 我想结合主域服务器的组、用户等,一句话,就是能用API完成域用户管理器的工作,是不是很复杂呢?另外,我是针对NT4,并不是对于WIN2000(因为WIN2000可以用ADSI),怎么办呢?C++的高手们可以写一段程序给我学习吗?急死人了!!!
- 俄罗斯方块难题--如何同时响应两人的击键
- 我想做个计划任务程序,不知怎样做更简介些?
#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了。
IMPLEMENT_DYNAMIC与IMPLEMENT_DYNCREATE是两个层次上的宏,IMPLEMENT_DYNAMIC用来是程序具有运行时能的动态获取程序中使用的类的信息,IMPLEMENT_DYNCREATE宏就是在IMPLEMENT_DYNAMIC的基础之上加入了动态创建类的功能,IMPLEMENT_DYNCREATE与IMPLEMENT_DYNAMIC配对在编译时不会报错,但会使程序失去动态创建CCliengSocket类的能力。
#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
动态创建到底是个什么概念?
动态创建是说你的程序在运行的时候能够在需要的时候创建类,而不必在程序开始时就把收有的类全部放到内存中,等着别人来调用。
把你的IMPLEMENT_DYNAMIC(CClientSocket,CSocket);DECLARE_DYNAMIC(CClientSocet);后面的“;”去掉。
//DECLARE_DYNAMIC(CClientSocet);
//IMPLEMENT_DYNAMIC(CClientSocket,CSocket);
不用这个功能,一般来说也可以的。
如果//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)