自己建立一个对话框类CimportFileDlg,在importFileDlg.h文件中加入CView *m_pView;
然后在importFiledlg.cpp中加入#include "TestDoc.h"和#include "TestView.h"两个头文件,
然后在TestView.h文件中又#include "TestDoc.h",响应
void CImportFileDlg::OnOK() 
{
CTestView *pView = (CTestView *)m_pView;
CTestDoc *pDoc = (CTestDoc *)pView->GetDocument(); CDialog::OnOK();
}断点调试,当执行到CTestDoc *pDoc = (CTestDoc *)pView->GetDocument();时出错:
Unhandled exception in Test.exe:0xc00000005 Access Violation
然后跳转到
CTestDoc* CTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
return (CTestDoc*)m_pDocument;
}
晕,真不知道为何会这样!

解决方案 »

  1.   

    可是程序在编辑时不会报错,我想用pDoc指针调其下的函数.想了一中午,都没想明白问题出在哪里了!
      

  2.   

    很明显,你的CView *m_pView只有声明没有定义.
    导致这句:CTestView *pView = (CTestView *)m_pView; 这里得到的pView失败.
    从而这句:CTestDoc *pDoc = (CTestDoc *)pView->GetDocument();
    出现未处理异常.
      

  3.   

    m_pView 有指向 真正的view 吗?
      

  4.   

    CimportFileDlg dlg;
    dlg.m_pView = GetActiveView();dlg.DoModal();