Solved

CMultiDocTemplate->OpenDocumentFile() Failure after installing Visual C++ 5.0

Posted on 1997-04-21
2
890 Views
Last Modified: 2013-11-20
I create an MDI app as shown in CFooApp::InitInstance below.
Then, when the user clicks on "file open", using the ::OnFileOpen method shown
below I create a CMultiDocTemplate instance and then call the OpenDocumentFile member, to create the document and view. The OpenDocumentFile call creates the document
calling the CreateNewDocument member, but fails during the
call to the CreateNewFrame member.
This worked well when I had Visual C++ 4.2 installed. The moment I installed Version 5.0 I have had this problem. Moreover when I call GetLastError after
the failure it returns 0, which indicates that the last call was successful.
After installing Version 5.0, it fails if it is built using V5.0 or V4.2.

--------Code snippet-------------------

BOOL CFooApp::InitInstance()
{
      CMultiDocTemplate* pDocTemplate;
      pDocTemplate = new CMultiDocTemplate(
            IDR_HOOKTYPE,
            RUNTIME_CLASS(CFooDoc),
            RUNTIME_CLASS(CFooMDIChildWnd),
            RUNTIME_CLASS(CFooView));
      pDocTemplate->SetContainerInfo(IDR_FOO_CNTR_IP);
      pDocTemplate->SetServerInfo(
            IDR_FOO_SRVR_EMB, IDR_FOO_SRVR_IP,
            RUNTIME_CLASS(COleIPFrameWnd));
      AddDocTemplate(pDocTemplate);
      
      ................
      ...............
      ..............
      ............
      ..........
}

void CFoo::OnFileOpen()
{
       
      CFileDialog open(TRUE);

      static char szFilter[] =
                 "TXT Files(*.txt)\0*.txt\0" \
                         "RTF Files *.rtf)\0*.rtf\0" \
                     "All Files (*.*)\0*.*\0\0";
      open.m_ofn.lpstrFilter = szFilter;
      open.m_ofn.lpstrTitle  =
            "Open an ASCII or Rich Text Format (RTF) file";

      if (open.DoModal() == IDOK)
      {
            CWinApp            *theApp = AfxGetApp();
            POSITION      docPosition =                 theApp->GetFirstDocTemplatePosition();

            // Create new window and initialize
            if (docPosition != NULL)
            {
                  CMultiDocTemplate *pDocTemplate;
                  CFooDoc              *pDoc;
                  CFooView          *pView;

                  // Create a new document
                  pDocTemplate = (CMultiDocTemplate*)theApp->GetNextDocTemplate(docPosition);
                  pDoc = (CFooDoc*)pDocTemplate->OpenDocumentFile(NULL, TRUE);

            }      
      }
}



0
Comment
Question by:joevas
2 Comments
 
LVL 1

Accepted Solution

by:
jmmougeolle earned 200 total points
Comment Utility
First of all there is no change between MFC 4.x and MFC 5.0 in CreateNewFrame, source code is completely the same!

So your problem may come from somewhere else!

What you could do is:

1) Execute that program, in debug mode within DevStudio, and look out the Output Debug Window to see all the TRACE the MFC dump there. MFC use to write there everythings that goes wrong, in your case it could help you to find if as an example, it failed because of a not found resource ID.

2) Never trust in GetLastError when you are calling the MFC framework, especially when it's not documented in the HELP resource that you could use it and interpret it for that specific feature. For your problem  not an Windows API failed. It may be just something not found, or bad initialized inside the MFC Framewrk.!

3) What's CFoo Class? What is it inherited from? Why don't you simply use directly the CWinApp::OnFileOpen method that do all the job for you?
If you don't do that, just to be able to add your own Extent (RTF TXT) in the OpenDialog Option, there is an easier way to do it!
What you got to do for that is:
Create 2 CMultipleDocTemplate beside only one, one using IDR_HOOKTYPE, and the other one using a new Resource ID: IDR_HOOKTYPE_RTF as an example.
Duplicate all the resources named IDR_HOOKTYPE (you will have to duplicate, Icon, Menu, and a string in the String table).
In the String resource, you have to change the Document description for both of them to one using TXT and Text document and the other one working on RTF and Rich text File document.
And don't forget to add both of them using the AddDocTemplate!
Then The MFC will do all the job for you, as you let it call the CWinApp:OnFileOpen in response to the ID_FILE_OPEN command.


0
 

Author Comment

by:joevas
Comment Utility
A look at the trace helped me locate the problem. The OLE Widget that I was using was probably incompatible with Visual C++ V5.0. The moment I updated the widget to the latest version it magically worked. Thanks for the quick response.  
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now