FIX: Word 2002 Returns an Error on Call to IPrint::Print Although Document Prints

This article was previously published under Q308937
This article has been archived. It is offered "as is" and will no longer be updated.
ActiveX Document containers that use the IPrint interface to print an embedded Word document may generate one of the following error messages when calling the IPrint::Print method:
  • HRESULT = 0x800703E6 (-2147023898)
    ERROR_NOACCESS: Invalid access to memory location.
  • HRESULT = 0x800706C6 (-2147023162)
    RPC_S_INVALID_BOUND: The array bounds are invalid.
This problem occurs if the ActiveX Document server is Word 2002 (Microsoft Office XP), and the client that uses the IPrint interface is out-of-process. The document may print, but you may report that the document cannot print, and you cannot obtain out parameters (such as the number of pages printed) from Word.
Word 2002 accidentally deletes the DVTARGETDEVICE* parameter that is passed to the IPrint::Print method. For out-of-process clients, this causes the proxy/stub code to fail on the return of the function because it tries to marshal the structure data back to the client. Although the proxy/stub DLL traps the access violation, it does not return any of the other return values to the method call and then issues the HRESULT error.

In-process callers to the method do not see this error, but the pointer that is passed to the Print method is no longer valid, and these clients may see their own access violation issues as a result.

Service Pack Information

This problem is corrected in Office XP Service Pack 3.To resolve this problem, obtain the latest service pack for Microsoft Office XP. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
307841 How to obtain the latest Office XP Service Pack

Hotfix Information

A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem.

If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, submit a request to Microsoft Customer Service and Support to obtain the hotfix.

Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site: Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.

After the hotfix is installed, the English version of this fix will have the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.   Date         Time       Size   File name   --------------------------------------------   30-Apr-2003  20:12      1,804  Hotfix.txt   29-Apr-2003  06:32      6,500  Readme.txt   29-Apr-2003  07:26  8,295,812  Winwordff.msp   29-Apr-2003  06:17  3,025,704  Winwordop.msp				
The English version of this fix should have the following file attributes or later:   Date         Time   Version          Size      File name   ----------------------------------------------------------   28-Apr-2003  21:27  10.0.5222.0    10,603,080  Winword.exe				
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Office XP Service Pack 3.
More information
If you have to maintain compatibility with all versions of Word 2002 and cannot rely on the fix, you may be able to work around the problem. To do this, pass NULL for the DVTARGETDEVICE* parameter. In this situation, Word uses the default printer of the user as the target device. Because there is no information to marshal for the structure, the error does not occur.

If you have to specify a non-default printer before calling IPrint::Print, follow these steps:
  1. Call QueryInterface on the embedded Word object for the IDispatch interface and then use the Application property to get an IDispatch interface to the server application.
  2. Use the ActivePrinter property on the Application object to set the printer name of the printer that you want to use. The string must be in the form: "[PrinterName] on [PortName]". For example, you may use "HP LaserJet 5si on LPT2".
  3. Call IPrint::Print with NULL for the DVTARGETDEVICE* parameter.

Steps to Reproduce the Problem

Note To reproduce the problem, you must have one of the following:
  • Word 2002 and an ActiveX Document container application
  • Another client that is designed to use the IPrint interface
  1. Download and then build the FramerEx Microsoft Visual C++ sample that is available through the following Microsoft Knowledge Base article:
    268470 SAMPLE: FramerEx.exe Is an MDI ActiveX Document Container Sample Written in Visual C++
  2. Modify the CFramerDocument::PrintDocObject function of the sample (print.cpp ~line 247) to display the results of the print:
      hr = pprnt->Print(PRINTFLAG_RECOMPOSETODEVICE, &ptd, &pgset, NULL,      static_cast<IContinueCallback*>(this), 1, &cPagesPrinted, &nLastPage);// Code added here to demonstrate IPrint::Print problem for Word 2002.// Word incorrectly frees memory belonging to the COM layer in ptd // marshalled across apartments. When the stub tries to marshal the // target device back across the wire, it hits an access violation. CHAR szbuffer[512]; if (FAILED(hr)) {     wsprintf(szbuffer,          "IPrint::Print returned error 0x%X! (PagesPrinted = %d, LastPage = %d)",         hr, cPagesPrinted, nLastPage); } else {     wsprintf(szbuffer,          "IPrint::Print returned successful. (PagesPrinted = %d, LastPage = %d)",         cPagesPrinted, nLastPage); } MessageBox(NULL, szbuffer, "IPrint Test",       MB_SETFOREGROUND | (FAILED(hr) ? MB_ICONHAND : MB_OK));					
  3. Compile and then run the sample. (To do this in Microsoft Visual C++, press F5).
  4. On the File menu, click New Object and then click Microsoft Word Document.

    Add some data to the blank document.
  5. On the File menu, click Print to print the document. Select a printer and then click OK.

    When the print occurs, one of the errors in the "Symptoms" section appears. Note that the number of pages that are printed (cPagesPrinted) is 0 although the print may have been successful and one or more pages may have printed.

Article ID: 308937 - Last Review: 10/26/2013 15:54:00 - Revision: 6.0

Microsoft Word 2002

  • kbnosurvey kbarchive kbautohotfix kbqfe kbhotfixserver kbactivedocs kbbug kbcontainer kbpending KB308937