在调试别人的程序(以下是InitInstance函数) // CG: The following block was added by the Splash Screen component.
\
{
\
CCommandLineInfo cmdInfo;
\
ParseCommandLine(cmdInfo);
\\
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
\
}
AfxInitRichEdit();
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. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSEGDDoc),
RUNTIME_CLASS(CMainFrame),       // main SDI frame window
RUNTIME_CLASS(CSEGDView));
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;
try{
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
}
// catch(...)
catch( CException*   e )
{
TRACE("InitInstance Error!\n"); 
AfxMessageBox("系统初始化出错!"); 
}
return TRUE;一旦运行到showwindow那行的时候就会跳出unhandled exception mfc42d.dll access violation的对话框,若是继续执行则会跳到winocc.cpp中BOOL CWnd::ShowWindow(int nCmdShow)
{
  ASSERT(::IsWindow(m_hWnd));-----》黄色箭头移动到这里了。 if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
请问导致以上现象是什么原因,怎么解决?

解决方案 »

  1.   

    CMainFrame的代码都加什么东西了
    应该是CMainFrame创建失败
      

  2.   

    个人怀疑下面代码有问题:
            CCommandLineInfo cmdInfo;
            ParseCommandLine(cmdInfo);
    在MFC种,ParseCommandLine需要框架已经被建立,而你这段代码加在最前方,很显然不满足这个条件
    楼主看看call stack,看看是在InitInstance那行调用进入你那个异常点的,很怀疑你这个splash window component是否可以这么用
      

  3.   

    我在CMAINFrame的构造函数以及oncreate的首行语句均下了断点,可是并没有执行到那就已经报错了我也不太清楚,不过无论是我去掉前面还是后面的parse或者全部删除掉,依然会报错。由于本人刚接触vc开发,所以有的太深的调试估计是做不来了。
      

  4.   

    CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);把这行移到窗口显示之后,
    同时,ParseCommandLine(cmdInfo); 前面的注释掉看看.
      

  5.   

    兄弟你肯定没仔细看代码吧?enable那个方法使用cmdInfo这个变量!
      

  6.   


    你的意思是改成这样?最前面的那个cmdinfo的两行代码注释掉了,但是运行到showwindow的时候仍然报同样的错误。      CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);
        
        // Dispatch commands specified on the command line
    //    if (!ProcessShellCommand(cmdInfo))
    //        return FALSE;
        try{
            m_pMainWnd->ShowWindow(SW_SHOW);        
            m_pMainWnd->UpdateWindow();                m_pMainWnd->ShowWindow(SW_SHOW);

    m_pMainWnd->UpdateWindow(); CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
      

  7.   


    引用 1 楼 conry 的回复:
    CMainFrame的代码都加什么东西了 
    应该是CMainFrame创建失败 
    我在CMAINFrame的构造函数以及oncreate的首行语句均下了断点,可是并没有执行到那就已经报错了 
      

  8.   

    m_pMainWnd初始化不正常跟进后m_hWnd的值是多少
      

  9.   

    单步调试的时候添加了一个watch,但是其value字段报错这位大哥能不能再详细点了,比如如何看特别的控件?就我看代码除了加了个splash的窗体就没其他控件了,何况我在主窗体的构造函数以及oncreate函数部分加了断点,但是并没有进来就报错
      

  10.   

    >>单步调试的时候添加了一个watch,但是其value字段报错VS调试的?还watch啥
    鼠标晃过去看看值 就是报错也有个value的吧 0x00000000?
      

  11.   

    呵呵,有的时候不是你移动上去就有值的,所以才加watch,估计你误解我说的”报错“的意思,它不是指程序报错,而是value字段本身报错获取不到值:m_pMainWnd CXX0033: Error: error in OMF type information
    m_hWnd CXX0033: Error: error in OMF type information