问题描述:
对话框上有一控件,不绑定变量时,程序正常,绑定后,程序错误,出现对话框:Debug Assertion Failed!  File:dlgdata.cpp Line: 43,点击对话框的忽略,出现:试图执行系统不支持的操作提示对话框。程序代码:
(1)对话框代码:
CMainDlg为对话框,m_e为控件IDC_STATIC_E的CString型变量。对话框上原有,四个按钮。
CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMainDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMainDlg)
m_e = _T("");
//}}AFX_DATA_INIT
}
void CMainDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMainDlg)
DDX_Text(pDX, IDC_STATIC_E, m_e);
//}}AFX_DATA_MAP
}BOOL CMainDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
//{{AFX_MSG_MAP(CMainDlg)
ON_BN_CLICKED(IDC_BUTTON_SDOC, OnButtonSdoc)
ON_BN_CLICKED(IDC_BUTTON_INPUT, OnButtonInput)
ON_BN_CLICKED(IDC_BUTTON_SET, OnButtonSet)
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()(2)此程序为单文档程序,对话框是后加上去的,程序运行从主框架的BOOL CSStar08App::InitInstance()开始:
BOOL CSStar08App::InitInstance()
{
::CoInitialize(NULL);
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings();  // Load standard INI file options (including MRU) // Register the application's document templates.  Document templates
//  serve as the connection between documents, frame windows and views. //CMainDlg *maindlg = new CMainDlg;
//maindlg->Create(IDD_DIALOG_MAIN,NULL);
    //maindlg->ShowWindow(SW_SHOW);
CMainDlg maindlg;
if(maindlg.DoModal() == IDOK)
{
CInDlg maindlg;
     if(maindlg.DoModal() == IDOK)
{
    CSingleDocTemplate* pDocTemplate;
           pDocTemplate = new CSingleDocTemplate(
     IDR_MAINFRAME,
     RUNTIME_CLASS(CSStar08Doc),
     RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CSStar08View));
         AddDocTemplate(pDocTemplate);
   
          // Parse command line for standard shell commands, DDE, file open
         CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);         // Dispatch commands specified on the command line
        if (!ProcessShellCommand(cmdInfo))
    return FALSE;         // The one and only window has been initialized, so show and update it.
        m_pMainWnd->ShowWindow(SW_SHOW);
        m_pMainWnd->UpdateWindow();           m_pMainWnd->SetWindowText("SStar08 信息集成平台");
        m_pMainWnd->UpdateWindow();
}
}
return TRUE;
}
试图调试找错:设置断点单步调试:
BOOL CSStar08App::InitInstance()
{
::CoInitialize(NULL);//此行设置了断点
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings();  // Load standard INI file options (including MRU) // Register the application's document templates.  Document templates
//  serve as the connection between documents, frame windows and views. //CMainDlg *maindlg = new CMainDlg;
//maindlg->Create(IDD_DIALOG_MAIN,NULL);
    //maindlg->ShowWindow(SW_SHOW);
CMainDlg maindlg;
if(maindlg.DoModal() == IDOK)
{
CInDlg maindlg;
     if(maindlg.DoModal() == IDOK)
{
    CSingleDocTemplate* pDocTemplate;
           pDocTemplate = new CSingleDocTemplate(
     IDR_MAINFRAME,
     RUNTIME_CLASS(CSStar08Doc),
     RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CSStar08View));
         AddDocTemplate(pDocTemplate);//在此行出现错误对话框:Unhandled exception in ...:0xC000005:Access Violation
   
          // Parse command line for standard shell commands, DDE, file open
         CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);         // Dispatch commands specified on the command line
        if (!ProcessShellCommand(cmdInfo))
    return FALSE;         // The one and only window has been initialized, so show and update it.
        m_pMainWnd->ShowWindow(SW_SHOW);
        m_pMainWnd->UpdateWindow();           m_pMainWnd->SetWindowText("SStar08 信息集成平台");
        m_pMainWnd->UpdateWindow();
}
}
return TRUE;
}
在错误对话框中点击确定,程序跳转到: 
APPUI2.CPP中:void CWinApp::AddDocTemplate(CDocTemplate* pTemplate)
{
if (m_pDocManager == NULL)
m_pDocManager = new CDocManager;
m_pDocManager->AddDocTemplate(pTemplate);//黄色箭头指向这里
}继续调试再次出现Unhandled exception in ...:0xC000005:Access Violation错误.

解决方案 »

  1.   

    HWND hWndCtrl;
    m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
    if (hWndCtrl == NULL)
    {
    TRACE1("Error: no data exchange control with ID 0x%04X.\n", nIDC);试试看先把关联的变量删除,然后把变量的ID换一下,比如IDC_STATIC_EE,在关联,rebuild all
      

  2.   

    把DDX_Text(pDX, IDC_STATIC_E, m_e)先注释掉看看是否出错,如果不出错,再把CString m_e定义注释掉看看是否出错。
      

  3.   

    上面写错了,更正一下:
    把DDX_Text(pDX, IDC_STATIC_E, m_e)先注释掉看看是否出错,如果还是出错,再把CString m_e定义注释掉看看是否出错。
      

  4.   

    IDC_STATIC_E是个什么控件的ID号,怎么像个静态文本??
      

  5.   

    m_e为控件IDC_STATIC_E的CString型变量
    这是个什么控件?static text?我记得static text不能绑定变量的吧
      

  6.   

    可以直接给IDC_STATIC控件绑定数值型变量吗? 我还没用过。最好是绑定一个Control型变量!
      

  7.   

    是不是手动修改过resource.h,rebuild all 试试。
      

  8.   

    我也怀疑是控件的问题
    不过,楼主定义对话框名字的时候,
    CMainDlg maindlg; 
    if(maindlg.DoModal() == IDOK) 

    CInDlg maindlg; 
        if(maindlg.DoModal() == IDOK) 
    { 两个名字都是maindlg,不太好!建议改一下!
    楼主可以考虑去掉上面的几句调试一下,可以通过,说明就是对话框的问题!
      

  9.   

    仔细检查DDX这一部分的变量名,类型等DDX_Text(pDX, IDC_STATIC_E, m_e); 
      

  10.   

    AddDocTemplate应该还可以跟踪进去的,检查一下pTemplate是否为NULL,估计是资源被改了。
      

  11.   

    MFC的代码不会出问题,应该是自已写了什么东西。
      

  12.   


    CStatic在设定好自己的 ID后也是可以绑定变量的。
    如果问题不在代码那里,很有可能是因为在ResourceView内修改控件的时候,把控件ID改了,导致控件不匹配,当程序运行的时候找不到对应控件而出错。
        这种情况本人在之前也遇到过,如果之前有程序备份并且备份的程序是正常的,那就直接还原不必在这个问题上兜圈子浪费时间,因为的确难找。
      

  13.   

    这个应该是思路的问题。 最好不要在initinstance之前做过多的 mfc操作。因为很多mfc内部不公开的部分,都需要初始化之类的操作。 而很多的MFC功能,都依赖于MFC内部的这些不公开部分。
    这个例子里面,就是在初始化文档模板前, 执行了复杂的MFC操作。 要知道 CDialog.DoModal() 是典型的对话框类型应用,而你最终用的是单文档模板应用。 两个类型的应用,其内部依赖的全局不公开MFC变量难免会冲突。基本上,是这种使用方式违背了MFC的设定路线,需要调整的是思路,而不是错误。有耐心的话,可以一步步跟进入看看到底是那些MFC变量冲突了。
      

  14.   

    可能是你写的某个IDC_XXX,该ID控件在对话框上没有
      

  15.   

    楼主修改过Static控件的ID或者变量名称吧
    打开.rc文件看看是不是以前的控件ID还存在
      

  16.   

    把DDX_Text(pDX, IDC_STATIC_E, m_e)先注释掉看看吧在