The first Assert fails, and before I put in the Asserts the assignment
of dlg.ChosenInterface=9 failed to affect the actual ChosenInterface
in the MFC_WinPCap dialog.

I apologize if this has been asked before; my searches came up with
nothing useful.

Thanks.

10-04-2007, 07:07 PM

unix

Re: How do I access one dialog's data from another dialog?

Dingus wrote:[color=blue]
> I have an MFC app, and the main dialog is called MFC_WinPCap.
>
> The MFC_WinPCap dialog calls a 2nd dialog, Prompt_For_Interface_Dlg
> (named so because it will prompt the user for a network interface).
>
> I need the second dialog to access data in the first dialog.
>
> In Prompt_For_Interface_Dlg::OnInitDialog(), I made the follwing code
> to attempt to access the data in the MFC_WinPCap dialog.
>
> CWnd* pMainDlg = GetDlgItem(IDD_MFC_WINPCAP_DIALOG);
> ASSERT(pMainDlg);
> CMFC_WinPCapDlg dlg = dynamic_cast<CMFC_WinPCapDlg*>(pMainDlg);
> ASSERT(dlg);
> dlg.ChosenInterface=9;
>
> The first Assert fails, and before I put in the Asserts the assignment
> of dlg.ChosenInterface=9 failed to affect the actual ChosenInterface
> in the MFC_WinPCap dialog.
>
> I apologize if this has been asked before; my searches came up with
> nothing useful.
>
> Thanks.[/color]

You have multiple coding problems in trying to do this, and design
problems in wanting to do it. One way to do what you are asking is

CMFC_WinPCapDlg* pdlg = (CMFC_WinPCapDlg*)AfxGetMainWnd();

Note it returns a pointer - your cast attempts to convert a pointer into
an object - which is invalid.

There are 3 or 4 ways a user can cancel a dialog. Your dialog should
not be changing anything in the main dialog, because then cancel will
fail to cancel the user's changes. Instead, save the result in a member
variable and let the main dialog read and copy that variable if (and
only if) IDOK is returned by DoModal.

--
Scott McPhillips [VC++ MVP]

10-04-2007, 07:07 PM

unix

Re: How do I access one dialog's data from another dialog?

"Scott McPhillips [MVP]" <scottmcp@mvps.org.nothere> wrote in message news:<Nd-dncNdXc_hC_bdRVn-uA@comcast.com>...
[color=blue]
> You have multiple coding problems in trying to do this, and design
> problems in wanting to do it. One way to do what you are asking is
>
> CMFC_WinPCapDlg* pdlg = (CMFC_WinPCapDlg*)AfxGetMainWnd();
>
> Note it returns a pointer - your cast attempts to convert a pointer into
> an object - which is invalid.
>
> There are 3 or 4 ways a user can cancel a dialog. Your dialog should
> not be changing anything in the main dialog, because then cancel will
> fail to cancel the user's changes. Instead, save the result in a member
> variable and let the main dialog read and copy that variable if (and
> only if) IDOK is returned by DoModal.[/color]

Thank you Scott, you are right. I started this approach with a desire
to fill a ComboBox in the new dialog with data from the 1st dialog,
and I kinda went too far.