Microsoft KB Archive/187920

= PRB: Cannot Edit Linked Word 95 Documents on Machines w/ Word 97 =

Article ID: 187920

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q187920



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 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.



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:  Clear the read-only attribute of the Rectitem.cpp, Rectitem.h, and Mainview.cpp files so that you can make necessary changes to them.  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; }                     Add the following function prototype to the public methods of CRectItem in the Rectitem.h file: BOOL DoVerb(LONG nVerb, CView* pView, LPMSG lpMsg);  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:   Line 612 of Mainview.cpp should be changed to: pItem->DoVerb(OLEIVERB_SHOW, this, NULL); </li>  Line 642 of Mainview.cpp should be changed to: m_pSelection->DoVerb(iVerb, this, NULL); </li>  Line 179 of Rectitem.cpp should be changed to: DoVerb(OLEIVERB_HIDE, NULL, NULL); </li></ul> </li> Recompile the OClient sample with the new changes, and run it.</li> 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.</li> 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.</li></ol>

Keywords: kbautomation kbinterop kbprb KB187920

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.