求救,unhandled exception 错误。

marshallshenzhe 2008-11-13 11:21:37
大体代码如下:
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:
SplitterWnd wndSplitter;
..........
};
void CMainFrame::Onsend()
{
// TODO: Add your command handler code here
//MessageBox("hello");
SplitterWnd &sw=wndSplitter;
sw.ChangeView(0,1,RUNTIME_CLASS(CRecsms));
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!wndSplitter.CreateStatic(this, 1, 2)) return false;
................
}
void SplitterWnd::ChangeView(int row, int col,CRuntimeClass* pViewClass)
{
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CView)));

CView* pView = STATIC_DOWNCAST(CView, GetPane(row, col));
CFrameWnd* pFrame = pView->GetParentFrame();
ASSERT(pFrame);

// set up create context to preserve doc/frame etc.
CCreateContext cc;
memset(&cc, 0, sizeof(CCreateContext));
cc.m_pNewViewClass = pViewClass;
cc.m_pCurrentDoc = pView->GetDocument();
cc.m_pNewDocTemplate = cc.m_pCurrentDoc ?
cc.m_pCurrentDoc->GetDocTemplate() : NULL;
cc.m_pCurrentFrame = pFrame;

DeleteView(row, col); // delete old view

VERIFY(CreateView(row, col, // create new one
pViewClass,
CSize(0,0), // will fix in RecalcLayout
错误发生处: &cc));
// delete &cc;
RecalcLayout(); // recompute layout

// initialize the view
CWnd* pWnd = GetPane(row, col);
if (pWnd)
pWnd->SendMessage(WM_INITIALUPDATE);
}
我把窗口分割成左右两个,通过void CMainFrame::Onsend() 切换右边视图窗口,其中SplitterWnd::ChangeView(int row, int col,CRuntimeClass* pViewClass)是从另外的工程复制过来的,并且在那里运行良好。为什么在我这里运行到“错误发生处:”就出现
Unhandled exception in 文件名.exe(MFC42D.DLL):0x0000005 Access Violation?有什么办法可以解决?谢谢先!!
...全文
455 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
palmax 2008-11-13
  • 打赏
  • 举报
回复
0x0000005 Access Violation
这是典型的内存访问冲突,要么指针非法,要么越界

别人的代码都没有理解就复制过来。。。。
菜牛 2008-11-13
  • 打赏
  • 举报
回复
先调试定位在哪一句出现错误。
marshallshenzhe 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yayafu 的回复:]
非法指针,内存越界,自己调试
[/Quote]
大虾说清楚点啊,我是菜鸟
yayafu 2008-11-13
  • 打赏
  • 举报
回复
非法指针,内存越界,自己调试
marshallshenzhe 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 Mackz 的回复:]
先调试定位在哪一句出现错误。
[/Quote]

VERIFY(CreateView(row, col, pViewClass, CSize(0,0), &cc));

就是这一句出错啊,但是我在调试窗口里没发现参数cc有什么不对啊,成员都正确。

16,472

社区成员

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

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

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