Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1997-04-21
2
Medium Priority
?
1,045 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Loops Section Overview
Suggested Courses

963 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