DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC宏

DECLARE_DYNAMIC宏定义:

#ifdef _AFXDLL
#define DECLARE_DYNAMIC(class_name) /
protected: /
 static CRuntimeClass* PASCAL _GetBaseClass(); /
public: /
 static const CRuntimeClass class##class_name; /   //宏定义中的##用来告诉编译器,把两个字符串系在一起
 static CRuntimeClass* PASCAL GetThisClass(); /
  virtual CRuntimeClass* GetRuntimeClass() const; /

#define _DECLARE_DYNAMIC(class_name) /
protected: /
 static CRuntimeClass* PASCAL _GetBaseClass(); /
public: /
 static CRuntimeClass class##class_name; /
 static CRuntimeClass* PASCAL GetThisClass(); /
 virtual CRuntimeClass* GetRuntimeClass() const; /

#else
#define DECLARE_DYNAMIC(class_name) /
public: /
 static const CRuntimeClass class##class_name; /
 virtual CRuntimeClass* GetRuntimeClass() const; /

#define _DECLARE_DYNAMIC(class_name) /
public: /
 static CRuntimeClass class##class_name; /
 virtual CRuntimeClass* GetRuntimeClass() const; /

#endif

IMPLEMENT_DYNAMIC宏定义:

#define IMPLEMENT_DYNAMIC(class_name, base_class_name) /
 IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, NULL, NULL)                                         

其中IMPLEMENT_RUNTIMECLASS宏定义为:

#ifdef _AFXDLL
#define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew, class_init) /
 CRuntimeClass* PASCAL class_name::_GetBaseClass() /
  { return RUNTIME_CLASS(base_class_name); } /
 AFX_COMDAT const CRuntimeClass class_name::class##class_name = { /
  #class_name, sizeof(class class_name), wSchema, pfnNew, /
   &class_name::_GetBaseClass, NULL, class_init }; /
 CRuntimeClass* PASCAL class_name::GetThisClass() /
  { return _RUNTIME_CLASS(class_name); } /
 CRuntimeClass* class_name::GetRuntimeClass() const /
  { return _RUNTIME_CLASS(class_name); } /

#else
#define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew, class_init) /
 AFX_COMDAT const CRuntimeClass class_name::class##class_name = { /
  #class_name, sizeof(class class_name), wSchema, pfnNew, /
   RUNTIME_CLASS(base_class_name), NULL, class_init }; /
 CRuntimeClass* class_name::GetRuntimeClass() const /
  { return RUNTIME_CLASS(class_name); } /

#endif

其中又导出下面几个宏:

#define _RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))

#ifdef _AFXDLL
#define RUNTIME_CLASS(class_name) (class_name::GetThisClass())
#else
#define RUNTIME_CLASS(class_name) _RUNTIME_CLASS(class_name)
#endif

 

你可能感兴趣的:(DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC宏)