Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Called by the framework to exchange and validate dialog data.

virtual void DoDataExchange(
   CDataExchange* pDX 



A pointer to a CDataExchange object.

Never call this function directly. It is called by the UpdateData member function. Call UpdateData to initialize a dialog box's controls or retrieve data from a dialog box.

When you derive an application-specific dialog class from CDialog, you need to override this member function if you wish to utilize the framework's automatic data exchange and validation. The Add Variable wizard will write an overridden version of this member function for you containing the desired "data map" of dialog data exchange (DDX) and validation (DDV) global function calls.

To automatically generate an overridden version of this member function, first create a dialog resource with the dialog editor, then derive an application-specific dialog class. Then use the Add Variable wizard to associate variables, data, and validation ranges with various controls in the new dialog box. The wizard then writes the overridden DoDataExchange, which contains a data map. The following is an example DDX/DDV code block generated by the Add Variable wizard:

void CPenWidthsDlg::DoDataExchange(CDataExchange* pDX)
      DDX_Text(pDX, IDC_THIN_PEN_WIDTH, m_nThinWidth);

      DDV_MinMaxInt(pDX, m_nThinWidth, 1, 20); 

      DDX_Text(pDX, IDC_THICK_PEN_WIDTH, m_nThickWidth);

      DDV_MinMaxInt(pDX, m_nThickWidth, 1, 20); 

The DoDataExchange overridden member function must precede the macro statements in your source file.

For more information on dialog data exchange and validation, see Displaying and Manipulating Data in a Form and Dialog Data Exchange and Validation. For a description of the DDX_ and DDV_ macros generated by the Add Variable wizard, see Technical Note 26.

Community Additions

© 2015 Microsoft