我写了一个程序,刚才运行还是好的,加了个静态框控件添了两句代码再点“!”就没反应了。设断点跟踪进去,发现当应用程序对象实例初始化程序运行到m_pMainWnd = &dlg;这一句时提示“Access Violation...”。我把应用程序对象实例初始化程序贴上,大家帮忙看看。
BOOL CFourDvcCptApp::InitInstance()
{
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 CFourDvcCptDlg dlg;
m_pMainWnd = &dlg;/****运行到这一句出问题****/
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}

解决方案 »

  1.   

    问题应该是出在 CFourDvcCptDlg 里,帖相关代码看
      

  2.   

    应该是和CFourDvcCptDlg的构造函数有关系吧,我把这段代码贴出来。
    CFourDvcCptDlg::CFourDvcCptDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CFourDvcCptDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CFourDvcCptDlg)
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    m_Drag=0;
    m_HCursor=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
    }
    后加的代码删掉也不行。另外,我刚才用“编译”菜单下的“重建全部”命令编译了一下又能运行了,怪事!