Problem with MFC DDX

Started by
2 comments, last by JY 18 years, 9 months ago
I'm trying to retrive a member from a CDialogue, but the program crashes when trying to access entDlg after DoModal(). When debugging i see that the adress entDlg is NULL. Isn't this supposed to work, and if so, any idea what i'm doing wrong? Have i missed something? I'm using MVC++ 7.1...

CEntityDlg entDlg;

if(entDlg.DoModal() == IDOK)
{
    this->currSel = entDlg.entSelList.GetCurSel();
}

// and DoDataEchange...
void CEntityDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	DDX_Control(pDX, IDC_ENTITY_SELECT, entSelList);
}
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
Advertisement
After DoModal the HWND of the dialog is destroyed, you're only left with the member variables. You cannot access controls of the dialog anymore.

In the dialogs OnClose copy the controls values into member variables which you can access after DoModal.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

You mean copy to variables in my parent window/class?
I suppose that's a way to do it.

It's strange though...i've seen many examples that looks the same way as my does, and they is said to work, but my doesn't...
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
The call to GetCurSel will try to send a message to the list box which, after DoModal, has been destroyed. You need to store the currently selected index in the class in the OnOK method.

It's not strange, it's completely necessary.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

This topic is closed to new replies.

Advertisement