PRB: Can't Edit Linked Word 95 Documents on Machines w/ Word 97

ID: Q187920


The information in this article applies to:


SYMPTOMS

If you insert a link to a Microsoft Word 95 document into a container application running on a machine with Microsoft Word 97, when you try to open or edit the document, you will receive the following error message:

Failed to launch server application


CAUSE

This problem occurs because the container application thinks the linked document is a Word 97 document, and doesn't realize that it is actually a Word 95 document, which causes the application to throw a COleException (0x80040008 -- Linked object's source class has changed) when it tries to activate the document.


RESOLUTION

To resolve this problem, it is necessary to handle the COleException thrown by the container. See below for the code necessary to do this.


STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Copy the OClient sample from the Visual C++ CD to your hard drive.


  2. Open the OClient sample in Visual C++, compile, and run it.


  3. On the Edit menu, click Insert New Object. Click Create from File, select the Link check box, and choose a file created in Word 95. Click OK to add a link to the file.


  4. Double-click the newly created link to activate it. You receive the error "Failed to launch server application" and the document does not activate.


To correct this problem, override the DoVerb method of the CRectItem class, as follows:

  1. Clear the read-only attribute of the Rectitem.cpp, Rectitem.h, and Mainview.cpp files so that you can make necessary changes to them.


  2. Open the RectItem.cpp file and add the following code.

    NOTE: This code overrides the DoVerb method, which is inherited from COleClientItem.
    
          BOOL CRectItem::DoVerb(LONG nVerb, CView* pView, LPMSG lpMsg)
          {
             ASSERT_VALID(this);
             if (pView != NULL)
                ASSERT_VALID(pView);
             if (lpMsg != NULL)
                ASSERT(AfxIsValidAddress(lpMsg, sizeof(MSG), FALSE));
    
             TRY
             {
                Activate(nVerb, pView, lpMsg);
             }
             CATCH ( COleException, exception )
             {
    
             /*Here's the change. If the linked object's source has changed,
                re-bind it to the correct source so Word 97 launches
                correctly.*/ 
                if (COleException::Process( exception) == 0x80040008){
                   IOleLink* fOleLink;
                   m_lpObject->QueryInterface(IID_IOleLink, (void**)&fOleLink);
                   IBindCtx* fBinder;
                   CreateBindCtx(0, &fBinder);
                   fOleLink->BindToSource(OLELINKBIND_EVENIFCLASSDIFF,
                      fBinder);
                   Activate(nVerb, pView, lpMsg);
                   fOleLink->Release();
                   fBinder->Release();
                   exception->Delete ();
                }
                else
                {
                   // Catch OLE errors and report them as such.
                   if (!ReportError(exception->m_sc))
                      AfxMessageBox(AFX_IDP_FAILED_TO_LAUNCH);
                   exception->Delete ();
                   return FALSE;
                }
             }
             AND_CATCH_ALL(exception)
             {
                // Otherwise, show generic error.
                AfxMessageBox(AFX_IDP_FAILED_TO_LAUNCH);
                exception->Delete ();
                return FALSE;
             }
             END_CATCH_ALL
    
             return TRUE;
          } 


  3. Add the following function prototype to the public methods of CRectItem in the Rectitem.h file:
    
          BOOL DoVerb(LONG nVerb, CView* pView, LPMSG lpMsg); 


  4. Change the calls to DoVerb so they match the new prototype by adding a third parameter, NULL, to each. The following three calls must be changed:



  5. Recompile the OClient sample with the new changes, and run it.


  6. On the Edit menu, click Insert New Object. Click Create from File, select the Link check box, and choose a file created in Word 95. Click OK to add a link to the file.


  7. Double-click the newly created link to activate it. This time, instead of producing an error, Word 97 should launch and display the linked document, ready to be edited.


Additional query words: kbDSupport kbDSD kbVC500 kbInterop kbAutomation kbMFC kbOLE


Keywords          : 
Version           : WINDOWS:97; WINNT:5.0
Platform          : WINDOWS winnt 
Issue type        : kbprb 

Last Reviewed: July 27, 1999