title: Moving data from a CDateTimeCtrl to a CTime object in VC++ 6
body: <p>Working with VS6 I noticed that some of my dialog boxes would crash when the date was changed in a CDateTimeCtrl object.  Investigating this revealed that the call to DDX_DateTimeCtrl was moving 12 bytes of data onto a CTime object that is 4 bytes wide.  Can anyone explain why this might be happening?  Does anyone know how to correct it?</p>
  
  <p>Header:</p>
  
  <pre><code>#if !defined(AFX_DATEDIALOG_H__B9373304_D774_4447_A4D1_BB4E1FB3404F__INCLUDED_)
  #define AFX_DATEDIALOG_H__B9373304_D774_4447_A4D1_BB4E1FB3404F__INCLUDED_
  
  #if _MSC_VER &gt; 1000
  #pragma once
  #endif // _MSC_VER &gt; 1000
  // DateDialog.h : header file
  //
  
  /////////////////////////////////////////////////////////////////////////////
  // CDateDialog dialog
  
  class CDateDialog : public CDialog
  {
  // Construction
  public:
      CDateDialog(CWnd* pParent = NULL);   // standard constructor
  
  // Dialog Data
      //{{AFX_DATA(CDateDialog)
      enum { IDD = IDD_DIALOG_DATE };
      CDateTimeCtrl   m_StartDate;
      CDateTimeCtrl   m_EndDate;
      CTime   m_tmEndDate;
      CTime   m_tmStartDate;
      //}}AFX_DATA
  
  
  // Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CDateDialog)
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      //}}AFX_VIRTUAL
  
  // Implementation
  protected:
  
      // Generated message map functions
      //{{AFX_MSG(CDateDialog)
      afx_msg void OnButtonBack();
      afx_msg void OnDatetimechangeEndDate(NMHDR* pNMHDR, LRESULT* pResult);
      afx_msg void OnDatetimechangeStartDate(NMHDR* pNMHDR, LRESULT* pResult);
      afx_msg void OnCloseupStartDate(NMHDR* pNMHDR, LRESULT* pResult);
      afx_msg void OnCloseupEndDate(NMHDR* pNMHDR, LRESULT* pResult);
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
  private:
      // the range limits for the dates; these are set to the values found
      // in m_tmStartDate and m_tmEndDate in OnInitDialog
      CTime m_tmStart;            // beginning of the range
      CTime m_tmEnd;              // end of the range
  };
  
  //{{AFX_INSERT_LOCATION}}
  // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  
  #endif // !defined(AFX_DATEDIALOG_H__B9373304_D774_4447_A4D1_BB4E1FB3404F__INCLUDED_)
  
  Code:
  
  // DateDialog.cpp : implementation file
  //
  
  #include "stdafx.h"
  #include "CustomerSales.h"
  #include "DateDialog.h"
  
  #ifdef _DEBUG
  #define new DEBUG_NEW
  #undef THIS_FILE
  static char THIS_FILE[] = __FILE__;
  #endif
  
  /////////////////////////////////////////////////////////////////////////////
  // CDateDialog dialog
  
  
  CDateDialog::CDateDialog(CWnd* pParent /*=NULL*/)
      : CDialog(CDateDialog::IDD, pParent)
  {
      //{{AFX_DATA_INIT(CDateDialog)
      m_tmEndDate = 0;
      m_tmStartDate = 0;
      //}}AFX_DATA_INIT
  }
  
  
  void CDateDialog::DoDataExchange(CDataExchange* pDX)
  {
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CDateDialog)
      DDX_Control(pDX, IDC_START_DATE, m_StartDate);
      DDX_Control(pDX, IDC_END_DATE, m_EndDate);
      DDX_DateTimeCtrl(pDX, IDC_END_DATE, m_tmEndDate);
      DDX_DateTimeCtrl(pDX, IDC_START_DATE, m_tmStartDate);
      //}}AFX_DATA_MAP
  }
  
  
  BEGIN_MESSAGE_MAP(CDateDialog, CDialog)
      //{{AFX_MSG_MAP(CDateDialog)
      ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack)
      ON_NOTIFY(DTN_DATETIMECHANGE, IDC_END_DATE, OnDatetimechangeEndDate)
      ON_NOTIFY(DTN_DATETIMECHANGE, IDC_START_DATE, OnDatetimechangeStartDate)
      ON_NOTIFY(DTN_CLOSEUP, IDC_START_DATE, OnCloseupStartDate)
      ON_NOTIFY(DTN_CLOSEUP, IDC_END_DATE, OnCloseupEndDate)
      //}}AFX_MSG_MAP
  END_MESSAGE_MAP()
  
  /////////////////////////////////////////////////////////////////////////////
  // CDateDialog message handlers
  
  void CDateDialog::OnButtonBack() 
  {
      // exit with our buton ID
      EndDialog(IDC_BUTTON_BACK);
  }
  
  void CDateDialog::OnDatetimechangeEndDate(NMHDR* pNMHDR, LRESULT* pResult) 
  {
      if(m_EndDate.GetMonthCalCtrl() == NULL)
      {
          UpdateData();
  
          if(m_tmStartDate &gt; m_tmEndDate)
              m_tmStartDate = m_tmEndDate;
  
          UpdateData(FALSE);
      }
  
      *pResult = 0;
  }
  
  void CDateDialog::OnDatetimechangeStartDate(NMHDR* pNMHDR, LRESULT* pResult) 
  {
      if(m_StartDate.GetMonthCalCtrl() == NULL)
      {
          UpdateData();
  
          if(m_tmEndDate &lt; m_tmStartDate)
              m_tmEndDate = m_tmStartDate;
  
          UpdateData(FALSE);
      }
  
      *pResult = 0;
  }
  
  void CDateDialog::OnCloseupStartDate(NMHDR* pNMHDR, LRESULT* pResult) 
  {
      UpdateData();
  
      if(m_tmEndDate &lt; m_tmStartDate)
          m_tmEndDate = m_tmStartDate;
  
      UpdateData(FALSE);
  
      *pResult = 0;
  }
  
  void CDateDialog::OnCloseupEndDate(NMHDR* pNMHDR, LRESULT* pResult) 
  {
      UpdateData();
  
      if(m_tmStartDate &gt; m_tmEndDate)
          m_tmStartDate = m_tmEndDate;
  
      UpdateData(FALSE);
  
      *pResult = 0;
  }
  </code></pre>