Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi guys,

I have made a number of Wizards, the second set was very similar to the first but with extensions. I wanted to use some of the common CPropertyPages with both Wizards (different property sheets).

This worked OK so I thought maybe I could derive my second CPropertySheet from my first!

First Wizard:-
C#
class CWizardSheet_ONE : public CPropertySheet
{
        DECLARE_DYNAMIC(CWizardsheet_ONE)
   public:
        CString m_csUsername;
...



Second Wizard:-
C#
class CWizardSheet_TWO : public CWizardSheet_ONE ) //CPropertySheet
{
        DECLARE_DYNAMIC(CWizardSheet_TWO)
...


It all seemed to work well when I tried accessing data using an instance of the first derivation of CPropertySheet.

BOOL CSetupWizPage02::OnKillActive()
{
    UpdateData( TRUE );
    CWizardSheet_ONE *ptParent  = (CWizardSheet_ONE *)this->GetParent();
    ptParent->m_csUsername   = m_csUsername;


I wanted to update a CWizardSheet_ONE variable when swapping to the next page.

I thought I could access these inherited variables by using the pointer returned by GetParent() in my CPropertyPage - the code below worked when the the Page was used by the CWizardSheet_ONE ..

BOOL CSetupWizPage02::OnKillActive()
{
	UpdateData( TRUE );
	CWizardSheet_ONE *ptParent	= (CWizardSheet_ONE *)this->GetParent();

	ptParent->m_csUsername	= m_csUsername;


But when I used the above page in CPropertySheet_TWO, the pointer returned by GetParent() was not to the base of CPropertSheet_TWO - it appears as though CPropertySheet inheritance is handled.
Any suggestions would be of interest.

Cheers!
Posted
Updated 18-Feb-11 11:06am
v4
Comments
Manfred Rudolf Bihy 18-Feb-11 6:34am    
Edit: Fixed code markup and minor spelling and grammar.
Manfred Rudolf Bihy 18-Feb-11 6:37am    
"that's when the problem started." is not as informative as you may think. If you would care to elaborate what your exact problems are we might be able to help you better. Edit your question ("Improve question") and state the exact source of your problem. Give as much detail as you've available like error messages, stack trace etc..

1 solution

The problem is that GetParent doesn't get the parent class in the inheritance hierarchy, it gets the parent window in the window hierarchy. I suspect that the wizard is not a child of any other window, so GetParent will return NULL. Accessing something through a NULL pointer will crash your application. Even if the wizard is a child of another window GetParent returns a HWND, which is not an instance of CWizardSetup. Trying to access a member of CWizardSetup through the window handle will return random data, rather than the required attribute.

This is much more complicated than you need anyway. Provided m_rtLocalStreamAccount is either protected or public (preferably the former), then you just use it directly, e.g.

class CWizardSetup : public CPropertySheet
{
...

protected:
  StreamAccount  m_rtLocalSTreamAccount;
};

class CWizardRpcSetup : public CWizardSetup
{

  void MyFunction()
  {
     DoSomethingWithTheLocalStream(m_rtLocalSTreamAccount);
  }

};


You could use this->m_rtLocalSTreamAccount if you really wanted to, but this is unnecessary.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900