Visual c++ getFirstDoctTemplatePosition()返回NULL

Visual c++ getFirstDoctTemplatePosition()返回NULL,visual-c++,mfc,activex,ocx,Visual C++,Mfc,Activex,Ocx,我有一个MFC来显示图形数据。我创建了OCX,用于在另一个应用程序中显示图形。在普通exe中,我有一个右键单击弹出菜单来执行一些操作。但是当我在另一个应用程序中使用OCX时,当我右键单击应用程序崩溃时。我通过如下调试得到了细节: POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); // here GetFirstDocTemplatePosition() returns NULL so the below line cra

我有一个MFC来显示图形数据。我创建了OCX,用于在另一个应用程序中显示图形。在普通exe中,我有一个右键单击弹出菜单来执行一些操作。但是当我在另一个应用程序中使用OCX时,当我右键单击应用程序崩溃时。我通过如下调试得到了细节:

POSITION  pos = AfxGetApp()->GetFirstDocTemplatePosition();
// here GetFirstDocTemplatePosition() returns NULL so the below line crashes.
CDocTemplate* doc_template = AfxGetApp()->GetNextDocTemplate(pos);
我不明白为什么GetFirstDoctTemplatePosition()返回NULL。我为exe和OCX创建了单独的菜单。单独的资源文件。 如: 我的应用程序是MyGraph,然后我为OCX创建了MyGraphOCX.sln,为OCX创建了resource_OCX.h、MyGraphOCX.rc

POSITION CWinApp::GetFirstDocTemplatePosition() const
{
    if (m_pDocManager == NULL)
        return NULL;
    return m_pDocManager->GetFirstDocTemplatePosition();
}
这里的
mupdocmanager
NULL
。我不明白为什么这是空的


请提供您的宝贵建议

您是在哪里创建文档模板的?显示代码。这是主应用程序的文档模板,我试图在其中调用OCX.CSingleDocTemplate*pDocTemplate;pDocTemplate=new CSingleDocTemplate(IDR_大型机、运行时_类(CMyAppDoc)、运行时_类(CMainFrame),//主SDI帧窗口运行时_类(CMainAppView));如果(!pDocTemplate)返回FALSE;addDoctTemplate(pDocTemplate);