请问CRuntimeClass::CreateObject怎么总返回NULL
目前有个需求想采用字符串的方式创建对象,用CRuntimeClass::CreateObject("classname");总是返回NULL
class A:public CObject
{
DECLARE_DYNCREATE(A)
};
IMPLEMENT_DYNCREATE(A,CObject)
///
A* a=CRuntimeClass::CreateObject("A");
返回一个NULL,就是说在Runtime那个列表里没有找到A这个类。
但是MSDN中有下文,模拟试验了一下,也同样返回空指针,请问为什么呢
// 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();