PRB: RestoreDC() Fails Across Printer Pages

Last reviewed: November 12, 1995
Article ID: Q139005
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with Microsoft Windows 95 version 4.0

SYMPTOMS

The RestoreDC() function returns failure when attempting to restore a printer Device Context (DC) that was saved by calling the SaveDC() function in Windows 95 version 4.0.

NOTE: This occurs only for applications marked as 4.0 applications.

CAUSE

RestoreDC() fails if the specified state instance does not exist on the GDI instance stack. Specifically, RestoreDC() fails on a printer DC if the StartPage() function is called between a call to the SaveDC() and a call to RestoreDC(). The RestoreDC() function fails because the StartPage() function in Windows 95 deletes any DC state instances that have been saved for that DC.

RESOLUTION

Applications use the StartPage() and EndPage() functions to indicate page separations on printer DCs. It is therefore necessary for applications written for Windows 95 to reinitialize a printer DC by selecting GDI objects and resetting mapping modes and other DC and GDI object attributes after every call to StartPage().

STATUS

This behavior is by design.

MORE INFORMATION

When Windows 95-based applications print, they spool to Enhanced Metafile (EMF) spool files by default. Spooling to an EMF requires a clean DC so that each call to the StartPage() function restores the printer DC to its default state.

In addition to restoring the default state of the DC, Windows 95 also empties the stack of DC states that may have been saved by calling the SaveDC() function. This prevents applications from setting up a DC prior to a call to StartPage() and restoring the selected objects and attributes after the call to StartPage() with RestoreDC(). However, as long as the SaveDC() and RestoreDC() functions are called between StartPage()/EndPage() pairs, they will succeed and properly save and restore DC states for the printer DC.

Typically, applications should allocate GDI resources prior to the start of a document or page and reuse these resources to initialize a printer DC at the start of every page in a document.


Additional reference words: 4.00 Windows 95 difference blank page output
KBCategory: kbprint kbgraphic kbprb
KBSubcategory: GdiDc GdiPrn


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 12, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.