Solved

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

Posted on 1997-04-21
2
908 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
ID: 1301126
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
ID: 1301127
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
post4 challenge 28 93
Annoying "thing" blocks my view 4 81
Not needed 13 93
Problem to open Excel file 15 95
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 …
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

17 Experts available now in Live!

Get 1:1 Help Now