[comp.sys.ibm.pc] MS-DOS interception of PRN

josephc@tybalt.caltech.edu (Joseph I. Chiu) (05/08/90)

Okay, I promised to let you guys know what came out of this, so here it goes.

BACKGROUND:

   I was working with my own set of pritner graphics routines to output raster
image on the LaserJet.  The problem that I was having was that while certain
images printed out perfectly fine, other images would cause a garbled printout
to occur.  The work I was doing was under C, using the stdprn file stream,    
with binary (i.e., no translation) write mode.

THE PROBLEM:

   I did a hex dump of the data going to the printer and compared that against
the data that was supposed to be going to the printer.  Apparently, when DOS
sees the character 0x1A (that's the EOF, or Ctrl-Z), it refuses to send it
to the printer, and stops sending data until it gets a LF or a CR (or another
white-space character, I suppose).

THE TEMPORARY FIX

   The first fix information I received was from a few users who suggested I
take a file with data redirected from my printer and to use COPY /B FILE PRN
to copy the data to the printer in DOS's binary mode.  This works fine.  So
now, it verified that the problem wasn't my programming, per se.

THE FIX

   One respondent gave me the clue I needed. (Sorry, can't remember your name
right now, but THANK YOU!)  The trick is to make a call to DOS Int21h Func44h.
The IOCTL handler.  By calling the IOCTL handler, you can make the printer
handler to NOT ACT UPON CONTROL CHARACTERS.  In other words, an EOF gets sent
to the printer as an EOF, instead of having it intercepted by the handler as
'stop sending data to printer'.

THE FUNCTION CALL

void set_ioctl (FILE *printerstream) {
   union REGS reg;

   reg.h.ah = 0x44;
   reg.h.al = 0x01; /* DOS: IOCTL - Set Device Data */
   reg.x.bx = fileno (printerstream); /* Get file handle */
   reg.x.dx = 0xA2; /* Raw, uncooked, write only */
   intdos (&reg,&reg);
   return;
}  /* TurboC 2.0, MSC 5.1 */

This works very well.  ( IOCTL data from MS-DOS Encyclopaedia by uSoft Press)

Good luck to all who're doing graphics work.  This should clear the roadway.

-Joseph

-------------------------------------------------------------------------------
 I wish I was somewhere else, walking down a strange new street...
 Hearing words that I have never heard before, from a girl I've yet to meet...
   - It Might As Well Be Spring (Rodgers & Hammerstein II)
-------------------------------------------------------------------------------
 JosephC @ Romeo.Caltech.Edu   My opinions, all mine, and you can't have them!
-------------------------------------------------------------------------------