MFC: Access Violation when accessing parent dialog


I'm trying to access the parent dialog from a child dialog using something like this...

double y = ((ParentDialogPointer *)GetParent())->m_l;

Now this code works from one of my child dialog files, but for the other one I get an access violation.

Any ideas why?

Thanks in advance!
Who is Participating?
mrjoltcolaConnect With a Mentor Commented:
Depending on how you create the child dialog, the parent window might not be of type ParentDialogPointer. The parent could be the application, for a modeless dialog. What type of dialogs, and how are you creating?
alb66Connect With a Mentor Commented:
May be you hadn't set the parent for one dialog
Ally86Author Commented:
I believe they are Modal Dialogs... Looking at the code for the resource file "MP.rc" the top of the dialog is set as  "DS_MODALFRAME".

I think the parent is the application, the dialogs are created using ...

 create = new NeXus();
   if(create!= NULL)
      BOOL ret = create->Create(IDD_DIALOG4,this);
      if(!ret)   //Create failed.
         AfxMessageBox("NeXus is Currently not Available");

How would I go about setting the parent ?

Any more info needed I'll be happy to tell!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.