void CDsDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
CFdfdDoc* pDoc;
CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd;
         CFdfdView *pView=(CFdfdView *)pMain->GetActiveView();
         (CFdfdDoc*) pDoc=pView->GetDocument();
}编译没有错误,为什么在运行时点击该按钮出错呢?

解决方案 »

  1.   

    Debug下调试一下啊,看看哪一步获取得到的指针为NULL
      

  2.   

    恩,sdi工程,我不怎么会调试啊 ,悲剧了
      

  3.   

    我试了一下
     CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd->GetActiveDocument();
    获取当前文档指针,
    也提示错误啊
    error C2065: 'm_pMainWnd' : undeclared identifier
    error C2227: left of '->GetActiveDocument' must point to class/struct/union
      

  4.   

    我试了一下(CFdfdDoc*) pDoc=(CFrameWnd *)m_pMainWnd->GetActiveDocument();
    获取当前文档指针,
    也提示错误啊
    error C2065: 'm_pMainWnd' : undeclared identifier
    error C2227: left of '->GetActiveDocument' must point to class/struct/union