Solved

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

Posted on 1997-04-21
2
928 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 181
only14 challenge 19 76
wait notify demo infinite loop 3 110
Is there a simple front-end menu system. 9 89
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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