CRuntimeClass

CRuntimeClass does not have a base class.

Each class derived from CObject is associated with a CRuntimeClass structure that you can use to obtain information about an object or its base class at run time. The ability to determine the class of an object at run time is useful when extra type checking of function arguments is needed, or when you must write special-purpose code based on the class of an object. Run-time class information is not supported directly by the C++ language.

The structure has the following members:

LPCSTR m_lpszClassName

A null-terminated string containing the ASCII class name.

int m_nObjectSize

The size of the object, in bytes. If the object has data members that point to allocated memory, the size of that memory is not included.

UINT m_wSchema

The schema number ( –1 for nonserializable classes). See the IMPLEMENT_SERIAL macro for a description of the schema number.

CObject* ( PASCAL* m_pfnCreateObject )( )

A function pointer to the default constructor that creates an object of your class (valid only if the class supports dynamic creation; otherwise, returns NULL).

CRuntimeClass* ( PASCAL* m_pfn_GetBaseClass )( )

If your application is dynamically linked to the AFXDLL version of MFC, a pointer to a function that returns the CRuntimeClass structure of the base class.

CRuntimeClass* m_pBaseClass

If your application is statically linked to MFC, a pointer to the CRuntimeClass structure of the base class.

Feature Only in Professional and Enterprise Editions   Static linking to MFC is supported only in Visual C++ Professional and Enterprise Editions. For more information, see .

CObject* CreateObject( );

Classes derived from CObject can support dynamic creation, which is the ability to create an object of a specified class at run time. Document, view, and frame classes, for example, should support dynamic creation. The CreateObject member function can be used to implement this function and create objects for these classes during run time. For more information on dynamic creation and the CreateObject member, see and in Visual C++ Programmer’s Guide.

BOOL IsDerivedFrom( const CRuntimeClass* pBaseClass) const;

Returns TRUE if the class of the class member calling IsDerivedFrom is derived from the base class whose CRuntimeClass structure is given as a parameter. IsDerivedFrom walks from the member's class up the chain of derived classes all the way to the top and returns FALSE only if no match is found for the base class.

Note   To use the CRuntimeClass structure, you must include the IMPLEMENT_DYNAMIC, IMPLEMENT_DYNCREATE, or IMPLEMENT_SERIAL macro in the implementation of the class for which you want to retrieve run-time object information.

For more information on using CRuntimeClass, see the article in Visual C++ Programmer’s Guide.

Hierarchy Chart

See Also   CObject::GetRuntimeClass, CObject::IsKindOf, RUNTIME_CLASS, IMPLEMENT_DYNAMIC, IMPLEMENT_DYNCREATE, IMPLEMENT_SERIAL