本文介绍了使用FromName()创建CRuntimeClass *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天,
我正在尝试使用名为Class,CMyClass的字符串创建一个CRuntimeClass指针,如下所示
Good day,
I am trying to create a CRuntimeClass pointer using a string with the name of the Class, CMyClass, as per below
CRuntimeClass * pClass = CRuntimeClass::FromName(L"CMyClass");
CMyClass已经被声明为DYNCREATE,基类为CRecordView。
无论花费多少精力,特定指针都会返回NULL。
在调试时,我注意到了以下代码:
QUOTE
CMyClass has been already declared as DYNCREATE with base class CRecordView.
No matter all efforts spent, specific pointer returns as NULL.
On debugging, i have noticed that in the following code:
QUOTE
CRuntimeClass* PASCAL CRuntimeClass::FromName(LPCSTR lpszClassName)
{
CRuntimeClass* pClass=NULL;
ENSURE(lpszClassName);
// search app specific classes
AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
AfxLockGlobals(CRIT_RUNTIMECLASSLIST);
for (pClass = pModuleState->m_classList; pClass != NULL;
pClass = pClass->m_pNextClass)
{
if (lstrcmpA(lpszClassName, pClass->m_lpszClassName) == 0)
{
AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
return pClass;
}
}
UNQUOTE
变量m_classList不包含我的CMyClass。
非常感谢任何帮助。
UNQUOTE
variable m_classList do NOT contain my CMyClass.
Any help is much appreciated.
推荐答案
这篇关于使用FromName()创建CRuntimeClass *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!