If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: creating an instance of a mfc derived class.

Originally Posted by D_Drmmr

So make it public. You're allowed to alter the generated code, you know.

Oh, ok, for some reason I thought that might foobar the MFC framework that made it protected. Wonder why the derived CFormView class has a protected ctor and the other derived classes don't. Maybe I should also create one with CFormView inside the doc/template and trace thru and see how it gets created.

Anyhow I'll try it uprotected and see if something gets infected. Thanks.

Re: creating an instance of a mfc derived class.

When all else fails, RTFM. That would be quicker, easier and more productive than posting here, and really should be done first. Don't confuse the forum with MSDN.

"Your derived class must supply its own constructor. In the constructor, invoke the constructor, CFormView::CFormView, with the resource name or ID as an argument as shown in the preceding class overview."

Re: creating an instance of a mfc derived class.

Originally Posted by J_W

Oh, ok, for some reason I thought that might foobar the MFC framework that made it protected. Wonder why the derived CFormView class has a protected ctor and the other derived classes don't. Maybe I should also create one with CFormView inside the doc/template and trace thru and see how it gets created.

I think the idea is (was) that you only instantiate the class using the CRuntimeClass interface. IIRC this is also how the doc template framework does it. However, the CRuntimeClass design is so hopelessly outdated that there is little point in using it in your own code.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: creating an instance of a mfc derived class.

Originally Posted by GCDEF

When all else fails, RTFM. That would be quicker, easier and more productive than posting here, and really should be done first. Don't confuse the forum with MSDN.

"Your derived class must supply its own constructor. In the constructor, invoke the constructor, CFormView::CFormView, with the resource name or ID as an argument as shown in the preceding class overview."

Ok point taken, will do. However many times on here I do get good input on here as to specifically where to RTFM, as your current post content (in addition to the RTFM) helps also. Thanks.

Originally Posted by D_Drmmr

I think the idea is (was) that you only instantiate the class using the CRuntimeClass interface. IIRC this is also how the doc template framework does it. However, the CRuntimeClass design is so hopelessly outdated that there is little point in using it in your own code.

Thank you, so then I would be just as well off (or better off if I do not need to reference an IsKindOf ..etc ) to just create the object straight out with my own new MyClassName
-----------------------------------------------
Anyhow just for curiousity I did this before unprotected the derived ctor as D_Drmmr suggested.

I created a separate project with the derived formview inside the Doc/Template (no second view).
As one would figure the object creation is originated from the Doc/Template code framework, tracing shows the template creation is first started and then eventually all classes within the template are then instantiated.

So anyhow I went back to my original project where my derived formview was outside the doc/template as a second view and just put the derived ctor public instead of the VS generated protected. It compiled ok and "appears" to run ok, with zero exit codes and the following printouts from the ctor, dtors.
(edit original errant paste)
From the CViewSwitchApp ctor
Just entering App InitInstance
From the ViewForm ctor
From the CMainFrame ctor
From the CViewSwitchView ctor
From the ViewForm dtor
From the CViewSwitchView dtor
From the CMainFrame dtor
-----
(the default dtor for the app class was not in code)
Note: the 2nd viewfrom class object was embedded as a member of the app class
and instanciated right after the doc/template comletion in the app's
InitInstance function. (show below)

AddDocTemplate(pDocTemplate);
ViewForm My_2nd_ViewObj;

====
Sorry for any redundance, you guys have been a great help to me. This is a great forum.