关于单步调试出现access violation对话框的问题

jimu8130 2009-08-31 11:13:45
在调试别人的程序(以下是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);
}


请问导致以上现象是什么原因,怎么解决?
...全文
260 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimu8130 2009-09-02
  • 打赏
  • 举报
回复
有没有人过来看看帮忙下?这个问题有这么难嘛?
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 vercitti 的回复:]
>>单步调试的时候添加了一个watch,但是其value字段报错

VS调试的?还watch啥
鼠标晃过去看看值 就是报错也有个value的吧 0x00000000?


[/Quote]
呵呵,有的时候不是你移动上去就有值的,所以才加watch,估计你误解我说的”报错“的意思,它不是指程序报错,而是value字段本身报错获取不到值:

m_pMainWnd CXX0033: Error: error in OMF type information
m_hWnd CXX0033: Error: error in OMF type information
vercitti 2009-09-01
  • 打赏
  • 举报
回复
>>单步调试的时候添加了一个watch,但是其value字段报错

VS调试的?还watch啥
鼠标晃过去看看值 就是报错也有个value的吧 0x00000000?

jimu8130 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 vercitti 的回复:]
m_pMainWnd初始化不正常

跟进后m_hWnd的值是多少
[/Quote]
单步调试的时候添加了一个watch,但是其value字段报错

[Quote]
应该是创建主窗口的时候有问题,没有创建成功,是不是加了什么特别的控件什么的
[/Quote]
这位大哥能不能再详细点了,比如如何看特别的控件?就我看代码除了加了个splash的窗体就没其他控件了,何况我在主窗体的构造函数以及oncreate函数部分加了断点,但是并没有进来就报错
dirdirdir3 2009-09-01
  • 打赏
  • 举报
回复
应该是创建主窗口的时候有问题,没有创建成功,是不是加了什么特别的控件什么的..........
vercitti 2009-09-01
  • 打赏
  • 举报
回复
m_pMainWnd初始化不正常

跟进后m_hWnd的值是多少
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 youyifang 的回复:]
看看1楼的吧
[/Quote]

引用 1 楼 conry 的回复:
CMainFrame的代码都加什么东西了
应该是CMainFrame创建失败


我在CMAINFrame的构造函数以及oncreate的首行语句均下了断点,可是并没有执行到那就已经报错了
youyifang 2009-09-01
  • 打赏
  • 举报
回复
看看1楼的吧
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 youyifang 的回复:]
后面还有一个定义
[/Quote]

你的意思是改成这样?最前面的那个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);
youyifang 2009-09-01
  • 打赏
  • 举报
回复
后面还有一个定义
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 youyifang 的回复:]
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);把这行移到窗口显示之后,
同时,ParseCommandLine(cmdInfo); 前面的注释掉看看.
[/Quote]
兄弟你肯定没仔细看代码吧?enable那个方法使用cmdInfo这个变量!
youyifang 2009-09-01
  • 打赏
  • 举报
回复
CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);把这行移到窗口显示之后,
同时,ParseCommandLine(cmdInfo); 前面的注释掉看看.
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
有没有人来帮忙看看
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 conry 的回复:]
CMainFrame的代码都加什么东西了
应该是CMainFrame创建失败
[/Quote]
我在CMAINFrame的构造函数以及oncreate的首行语句均下了断点,可是并没有执行到那就已经报错了

[Quote=引用 2 楼 arong1234 的回复:]
个人怀疑下面代码有问题:
        CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);
在MFC种,ParseCommandLine需要框架已经被建立,而你这段代码加在最前方,很显然不满足这个条件
楼主看看call stack,看看是在InitInstance那行调用进入你那个异常点的,很怀疑你这个splash window component是否可以这么用
[/Quote]
我也不太清楚,不过无论是我去掉前面还是后面的parse或者全部删除掉,依然会报错。

由于本人刚接触vc开发,所以有的太深的调试估计是做不来了。
jimu8130 2009-09-01
  • 打赏
  • 举报
回复
还有没有人过来看看?
arong1234 2009-08-31
  • 打赏
  • 举报
回复
而且你有俩ParseCommandLine
arong1234 2009-08-31
  • 打赏
  • 举报
回复
个人怀疑下面代码有问题:
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
在MFC种,ParseCommandLine需要框架已经被建立,而你这段代码加在最前方,很显然不满足这个条件
楼主看看call stack,看看是在InitInstance那行调用进入你那个异常点的,很怀疑你这个splash window component是否可以这么用
Conry 2009-08-31
  • 打赏
  • 举报
回复
CMainFrame的代码都加什么东西了
应该是CMainFrame创建失败

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧