DDX Problem in MFC Dialog

DDX Problem in MFC Dialog

Kyudos
Advisor Advisor
994 Views
2 Replies
Message 1 of 3

DDX Problem in MFC Dialog

Kyudos
Advisor
Advisor

We have a custom DDX function for values in the  MFC dialogs of our ARX. In ACAD 2018 calling CDataExchange::Fail in that function causes ACAD to crash.

 

I worked around it by adding a try...catch around the DDX function (it catches an 'unknown' error), so from that point of view I'm OK.

 

But, has anyone else experienced this? Or know why it might be happening? In this instance I was using DDX outside of the dialog DoDataExchange function - might that be an issue?

0 Likes
Accepted solutions (1)
995 Views
2 Replies
Replies (2)
Message 2 of 3

moogalm
Autodesk Support
Autodesk Support

Hi,

 

As always I need a sample project that I can reproduce the behavior, I don't know your custom DDX implementation,  or what validation of input is going there.

 

Put a break point in  

 "%VCINSTALLDIR%\Tools\MSVC\14.14.26428\atlmfc\src\mfc\dlgdata.cpp" 
and check for call stack.
void CDataExchange::Fail()
{
	if (!m_bSaveAndValidate)
	{
		TRACE(traceAppMsg, 0, "Warning: CDataExchange::Fail called when not validating.\n");
		// throw the exception anyway
	}
	else if (m_idLastControl != NULL)
	{
		// restore focus and selection to offending field
		HWND hWndLastControl;
		m_pDlgWnd->GetDlgItem(m_idLastControl, &hWndLastControl);
		if (hWndLastControl != NULL)
		{
			::SetFocus(hWndLastControl);
			if (m_bEditLastControl) // select edit item
				::SendMessage(hWndLastControl, EM_SETSEL, 0, -1);
		}
	}
	else
	{
		TRACE(traceAppMsg, 0, "Error: fail validation with no control to restore focus to.\n");
		// do nothing more
	}

	AfxThrowUserException();
}
0 Likes
Message 3 of 3

Kyudos
Advisor
Advisor
Accepted solution

I re-coded to avoid calling  CDataExchange:: Fail outside of DoDataExchange... seems to have done the trick.

0 Likes