Intermec 6100 Reference Guide

Page of 328
SECTION 3
Supporting Windows Applications
PEN*KEY
R
 6100 Computer Programmer’s Reference Guide    3-25
Basic Windows Printing
Once Windows is loaded, printing is accomplished through the standard printing
API.  No special processing by the application is needed. The following sequence
demonstrates the correct method for printing under Windows:
1. Create a device context for the printer.  GetPrinterDC() creates the device
context.
2. Set up the device context with the desired fonts, etc.  Keep in mind that difĆ
ferent fonts cause Windows to print completely in graphics mode, which
may provide less performance than desired.  SelectObject(...) sets the deĆ
sired font.
3. Set an abort procedure to handle errors during printing and allow the user
to cancel the print job.  SetABortProc(...) sets an abort procedure.
4. Begin the printing operation by calling StartDoc(...) to inform GDI that you
want every output to be one job.
5. Begin each page of output by calling StartPage(...) to allow GDI to begin
sending data to the printer on a pageĆbyĆpage basis.
6. Create your page using standard GDI API like TextOut(...).  The output opĆ
erations used take text and other objects and convert them into a binary
data stream that contains printerĆspecific escape codes.  This data is
spooled" until the entire page is composed.
7. Use EndPage(...) to finish off a page.  The entire page is then sent to the
printer.  A form feed is generated to move the paper to the top of the next
page.
8. Use EndDoc() to complete the printing operation.  AbortDoc() can cancel a
job.  GDI cleans things up, if possible.
9. Free the instance of your abort procedure using FreeProcInstance(...).
Refer to the Windows SDK manual for more API information.
Default Error Handling Mode
Once the drivers are loaded as defined above, no special processing by the apĆ
plication is needed.  This makes it possible for offĆtheĆshelf packages to take adĆ
vantage of NPCP.  In this mode, all printerĆrelated errors are handled by the
NPCP driver.  A message is displayed and the user has the ability to Cancel or
Retry.  If the user selects Retry, the driver attempts to continue printing.  If the
user selects Cancel, the driver attempts to clean up as best it can.  The standard
Windows API returns a standard error, indicating that a problem occurred.  This
is the application's signal to abort the print job.
Application-Defined Error-Handling Mode
This is probably the most common mode of operation.  In this mode, the applicaĆ
tion can link to the NPCP driver in the same manner that it would link to any
Windows DLL.  Once linked, the application can use the driver's API to perform
various operations.  The application registers a callback with the driver. The apĆ
plication needs to perform the following actions to define a new error handler:
1. Link to driver and obtain PrtService entry point.
2. Call PrtService to enable the driver using PRT_ENABLE (0x0001).
3. Call PrtService to register the new handler using PRT_SETPROC (0x0010)
and the address of the new handler.  The new handler should have the
following prototype:
extern “C” WORD _export FAR PASCAL ShowPrtError (WORD wCurErr)
3. Windows
Applications