Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Call this function to retrieve the CRuntimeClass structure associated with the familiar name.

static CRuntimeClass* PASCAL FromName( 
   LPCSTR lpszClassName  
static CRuntimeClass* PASCAL FromName( 
   LPCWSTR lpszClassName  


The familiar name of a class derived from CObject.

A pointer to a CRuntimeClass object, corresponding to the name as passed in lpszClassName. The function returns NULL if no matching class name was found.

// This example creates an object if CAge is defined.

CRuntimeClass* pClass = CRuntimeClass::FromName(_T("CAge"));
if (pClass == NULL)
   // not found, display a warning for diagnostic purposes
   AfxMessageBox(_T("Warning: CMyClass not defined"));
   return NULL;

// attempt to create the object with the found CRuntimeClass
CObject* pObject = pClass->CreateObject();

This method is not supported on Smart Devices because, in order for this method to return a class object, the returned class must use the DECLARE_SERIAL, IMPLEMENT_SERIAL macros, which are not supported for devices.

Header: afx.h

© 2016 Microsoft