• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1069
  • Last Modified:

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

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
joevas
Asked:
joevas
1 Solution
 
jmmougeolleCommented:
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
 
joevasAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now