Analysis of "establishing empty document failed"

zhaozj2021-02-16  95

Repost:

Analysis on "establishing an empty document failed"!

Many newcomers always do handle when they encounter such problems, if anyone has patience, look at the following article.

The emergence of such problems is mainly in Bool Cwinapp :: ProcessShellcommand (CCommandlineInfo & RCMDInfo);

Key content of the function: Bool Bresult = true; switch (rcmdinfo.m_nshellcommand) {case ccommandlineinfo :: filenew: // New if (! AFXGetApp () -> oncmdmsg (id_file_new, 0, null, null) onfilenew (); if (m_pmainwnd == null) BRESULT = FALSE; BREAK; CASE CCOMMANDLINFO :: FileOpen: if (! OpenDocumentfile (rcmdinfo.m_strfilename) BRESULT = false; break; through the above content we can see: If there is no map to ID_FILE_NEW There is a problem is onfilenew (); CWINAPP's default implementation for ONFileNew is to call m_pdocmanager-> onfilenew ();

We continue to analyze CDOCManager, what is it? (First, explain that CDOCManager is the main function is to help CWINApp is the management document template list and registration file type.)

// If the template list is empty if (m_templatelist.isempty ()) {trace0 ("error: no document templates registered with cwinapp./n"); afxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC); // An error is returned. Here will be established here New document error. Return;}

CDocTemplate * pTemplate = (CDocTemplate *) m_templateList.GetHead (); if (m_templateList.GetCount ()> 1) {// more than one document template to choose from // bring up dialog prompting user CNewTypeDlg dlg (& m_templateList); int nID = dlg.domodal (); if (nid == idok) PTEMPLATE = DLG.M_PSelectedTemplate; else return; // none - can operation}

Assert (PTEMPLATE! = Null); assert_kindof (cdoctemplate, PTEMPLATE);

PTEMPLATE-> OpenDocumentFile (NULL);

Through the above code. We can see that CWINAPP ONFileNew and ONFileOpen call CDOCManager virtual functions onfilenew

And onfileopen. And inside CDOCManager. Select different templates through template tables to call the document template's openDocumentFile (); if the incoming parameter null means a new file.

Let's take a look at CDOCTemplate :: OpenDocumentFile () it is the most critical function. Because he is a virtual function, we consider CSINGEDEMPLATE :: OpenDocumentFile. This function inside a piece of code: where: AFX_IDP_FAILED_TO_CREATE_DOC is the character "failed to create empty document" resource id // create a new documentpDocument = CreateNewDocument (); ASSERT (pFrame == NULL); // will be created belowbCreated = TRUE; if (pDocument == NULL) {AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC); return NULL;} ASSERT (pDocument == m_pOnlyDoc); if (pFrame == NULL) {ASSERT (bCreated); // create frame - set as main document frameBOOL bAutoDelete = pDocument -> m_bAutoDelete; pDocument-> m_bAutoDelete = FALSE; // do not destroy if something goes wrongpFrame = CreateNewFrame (pDocument, NULL); pDocument-> m_bAutoDelete = bAutoDelete; if (pFrame == NULL) {AfxMessageBox (AFX_IDP_FAILED_TO_CREATE_DOC); delete Pdocument; // explicit delete on error return null;}

Through observing the above code, we can easily see that there are two possible reasons: 1 CreateNewDocument Returns NULL 2

CreateNewFrame returns empty.

First seeing CreateNewDocument () Generally, this function has little failure. However, you can't fall lightly during debugging. Take a look at CreateNewFrame () There is a function loadFrame is the source of this "establish a new document failed" error. As long as it returns False, this prompt will pop up. Let's take a look at LOADFrame () call CFrameWnd :: Create () to create a window, and create a window fails to return FASLE. This is relatively simple to change.

Take a look at what the Create and CreateEx functions will know what is going on. *********************************************************** ********** 1 If the menu resource is not found to return false, "Establishing a Null Dilestable" hinstance hinst = afxFindResourceHandle (LPSZMENUNAME, RT_MENU); if (((HMenu = :: loadmenu (hinst, lpszMenuname) == null) {trace0 ("Warning: failed to load menu for cframewnd./N"); postncdestroy (); // perhaps delete the c Object return false;} 2 overload precomreateWindow and returned False also causes the pop-up "establishment empty document failed" 3 Returns -1 in OnCreate will also result in pop-up "establishment empty document failed". *********************************************************** *************** The above is a general reason why I have analyzed the "Establishing Null Delive" problem. Perhaps there are other reasons. I am not listed here.

.

转载请注明原文地址:https://www.9cbs.com/read-13263.html

New Post(0)