Typical Printing Process Scenario Using a Raw Spool File
This section illustrates the major relationships between the spooler components during the printing process by walking through the sequence of calls between components during the spooling of a raw format spool file and subsequent playback (despooling) of the file to a bidirectional printer.
The following illustration shows the sequence of calls that start with an application initiating a print request by calling GDI (labeled step 1 in the illustration) and end with the local print provider writing a spool file to the disk (step 8) and starting a background thread that will eventually initiate the despooling process (step 9). The sequence of steps in the despooling process are shown in a separate illustration.
Each of the following paragraphs describes one of the calls in the spooling process.
- The application creates a DC and draws an object to the DC, for example a circle, and then calls GDI with a print request to a particular printer using that DC.
- GDI calls the printer driver with a request for instructions on how to render the circle on that particular printer.
- The printer driver returns the instructions on how to render the circle on the printer the driver is associated with. Note that all Windows 95 printer drivers are 16-bit code and communicate with 16-bit GDI.
- GDI passes the print request to 32-bit GDI because the Windows 95 spooler process is 32-bit code.
- GDI32 makes an interprocess call to the spooler process.
- SPOOL32.EXE calls the router to route the print job to the printer specified by the application. In this example, the router sends the print job to the local print provider. Note that the router could send the job to a printer on the network through the network print provider (which is not shown in the illustration). The default Windows 95 spooler spools the network jobs locally, so they show up on the local spooler queue, even those jobs bound for a Windows NT servers. A network print job is spooled and despooled on the client machine, not the server. It is only in the relatively late step of despooling that the remote print server is actually contacted. The way Windows 95 handles network print jobs contrasts with the way they are handled by Windows NT client machines, which use RPC to call the necessary printing APIs on the print server. This way, the print job never shows up on the local spooler queue and the spooling and despooling is handled by the print spooler on the print server. On Windows 95 RPC is not used by the default print spooler. A print spooler that does use RPC is available as an option for Windows 95 client machines.
- The router calls the local print provider with the print job.
- If the type of print job is not direct, the local print provider spools the print job to the disk as a raw-format spool file. Note that steps 1 through 8 can be repeated many times to build a complete spool file. In step 8, the local print provider appends each piece of the print job to the spool file until the application signals that the job is complete by issuing an EndDoc function. The difference between a direct print job and a spooled print job to the local print provider is apparent in the next illustration which shows the playback of this spooled file. When the local print provider is called by the print processor (through the router) with this same print job, the job type is direct instead of spooled. That results in the job going to the printer instead of being rewritten as another spool file.
- The local print provider starts a background thread that will determine the best time to start playing back the spool file to the printer. The next illustration shows the sequence of steps involved in playing back the raw spool file.
The following illustration shows the sequence of calls that start with the background thread application initiating the playback of a spooled file by calling a print processor (labeled step 10 in the illustration) and end with the local port monitor sending the print job through a port it controls to a connected printer (step 17).
Each of the following paragraphs describes each of the calls in the despooling process.
- The main thread determines a good time to initiate the playback of a spooled file, based on the changing state of spooler subsystem resources monitors. When it is a good time, the main thread uses a StartDoc function call to start a new thread in the print processor to playback the spooled file.
- Because it is a StartDoc case, the print processor thread invokes the local print provider with a ReadPrinter function call to read part of the spool file off the disk. (Note that in this example case of a raw spool file, the print processor does not call GDI32. In the EMF spool file case, which are played back by the default print processor supplied by Microsoft, the print processor calls GDI32 to playback the metafile.)
- Because it is a StartDoc case, the print processor thread invokes the language monitor (through the local print provider) with a WritePrinter function call to send the data through the physical port connected with the bidirectional printer originally specified in step 1 of this whole process. For a raw spool file, the default print processor simply passes the data through, without changing or interpreting any of the information. Note that a language monitor is invoked in this example scenario because the destination printer is a bidirectional printer. For nonbidirectional printers, a port monitor would be invoked instead of a language monitor. Note also that although this example scenario shows the language monitor and port monitor as separate components, they can be integrated into one monitor.
- The language monitor calls the port monitor to send the data to the printer.
- The port monitor sends the raw data through the physical port to the connected printer. Note that steps 11 through 14 are repeated until the end-of-file is reached on the spool file (or the print job is canceled). Then the playback thread is terminated.