试图用以下代码遍历所有文档,却提示如下错误,实不知如何解决,请各位看看为何?
void CMainFrame::OnNewproject()
{
CWinApp *pApp = AfxGetApp(); POSITION pos = pApp->GetFirstDocTemplatePosition();
while ( pos != NULL )
{
CDocTemplate *pTemplate=pApp->GetNextDocTemplate(pos);
CArticleDoc *pDoc=(CArticleDoc*)pTemplate;
bool b = pDoc->IsModified();
//pDoc->OnCloseDocument();
}
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

解决方案 »

  1.   

    POSITION doctempos=GetFirstDocTemplatePosition( );
    bool bdocopen=false;
    while(doctempos)
    {
    CDocTemplate* pdoctemp= GetNextDocTemplate( doctempos );
    POSITION docpos=pdoctemp->GetFirstDocPosition();
    while(docpos)
    {
    CDocument* pdoc =pdoctemp->GetNextDoc();

    }
    }
      

  2.   

    Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
    能说说引发这个问题的原因吗?
      

  3.   

    CArticleDoc *pDoc=(CArticleDoc*)pTemplate; that error is caused by invalid type cast