Microsoft KB Archive/308937

From BetaArchive Wiki

Article ID: 308937

Article Last Modified on 10/23/2006



APPLIES TO

  • Microsoft Word 2002 Standard Edition



This article was previously published under Q308937


SYMPTOMS

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.

CAUSE

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.

RESOLUTION

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 now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Public Update or Service Patch that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site:

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

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
                

STATUS

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.


Keywords: kbqfe kbhotfixserver kbactivedocs kbbug kbcontainer kbpending KB308937