sdi框架中 mainfrm类 弹出的模式对话框 里想找到Doc的指针  执行操作CMainFrame *pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
CRecentFileDemoDoc* pDoc = (CRecentFileDemoDoc*)(pFrame->GetActiveDocument());出现错误pFrame句柄为0
为什么呢

解决方案 »

  1.   

    CMainFrame *pFrame = (CMainFrame*)(AfxGetMainWnd( ))
      

  2.   

    果然 pFrame不是0了 不过下面还是不对 我这样改了
    CMainFrame *pFrame = (CMainFrame*)(AfxGetMainWnd());
    CRecentFileDemoDoc* pDoc = (CRecentFileDemoDoc*)(pFrame->GetActiveDocument());pDoc又非法了 晕
      

  3.   

    这样
    Unhandled exception at 0x00dd4b15 in RecentFileDemo.exe: 0xC0000005: Access violation writing location 0xdd50f000.然后程序断在objcore.cpp文件的
    if (!AfxIsValidAddress(pOb, pOb->GetRuntimeClass()->m_nObjectSize, FALSE))处
      

  4.   

    写成这样试试:
    AfxGetMainWnd()->GetActiveView()->GetDocument();
      

  5.   

    层次是这样的
    mainfrm.cpp下domodule一个对话框a  a下面某个操作后(此时a未销毁) 想写一个数据于是想找pDoc指针 
      

  6.   

    汗 找到原因了 是因为我在刚mainfrm里的creat里进的对话框   这个时候 doc  view都还没初始化呢  自然不对 
    现在改成全局变量 就好了