CRuntimeClass::FromName

CRuntimeClass::FromName

Visual Studio 2005
其他版本
此主题尚未评级 评价此主题

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 
);

Parameters

lpszClassName

The familiar name of a class derived from CObject.

Return Value

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.

Example
// This example creates an object if CMyClass is defined.

CRuntimeClass* pMyRTClass= pMyObject->GetRuntimeClass();

CRuntimeClass* pClass = pMyRTClass->FromName("CMyClass");
if (pClass == NULL)
{
   // not found, display a warning for diagnostic purposes
   AfxMessageBox("Warning: CMyClass not defined");
   return NULL;
}

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

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.

See Also

Reference

CRuntimeClass Structure
Hierarchy Chart
CRuntimeClass::m_lpszClassName

Other Resources

CRuntimeClass Members

你可能感兴趣的:(CRuntimeClass::FromName)