I have to create an instance of my own MFC deriverd class.
The only thing I know is the classname as a string, this is read out from a XML document.
Are there any methodes like in Java loadClassByName(string) to create a new object?
If your MFC class is derived from CObject you can use the MFC Dynamic creation method by mapping the string class name of your classes to the following sample code from MSDN:
To dynamically create an object given its run-time class
Use the following code to dynamically create an object by using the CreateObject function of the CRuntimeClass. Note that on failure, CreateObject returns NULL instead of raising an exception:
CRuntimeClass* pRuntimeClass = RUNTIME_CLASS( CMyClass );
CObject* pObject = pRuntimeClass->CreateObject();
ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CMyClass ) ) );
You could also roll your own factory technique using C++ RTTI information. That would take a little more development but would not be tied to MFC.
Not realy. The problem is that "MyClass" ist a string and MyClass isn't
But I found a solution. Every CRuntimeClass struct contains the members:
LPCSTR m_lpszClassName & CRuntimeClass* m_pNextClass
If I get one CRuntimeClass*, I can handle through the list.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.