Sending Output to a Printer

Last reviewed: July 22, 1997
Article ID: Q23976
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50 | 1.00 2.00 2.10 4.00
MS-DOS                      | WINDOWS   | WINDOWS NT
kbprg kbfasttip

The information in this article applies to:

  • Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, versions 1.0 and 1.5
  • Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, and 4.0

SUMMARY

This article presents three methods an application can use to send output to a printer.

MORE INFORMATION

Method 1

The first method uses the fprintf() function with the preopened "stdprn" stream. The following code example demonstrates this technique:

   #include <stdio.h>
   main()
   {
      fprintf(stdprn, "a line of text\n");
   }

This method works only in the MS-DOS operating system because the "stdprn" stream is not defined by Microsoft Windows or Microsoft Windows NT.

Method 2

Another method uses the fopen() function to open the LPT1, LPT2, or PRN device as a file and uses the fprintf() function to write data to the file handle returned by fopen(). The following code example demonstrates this technique:

   #include <stdio.h>
   main()
   {
      FILE *stream;

      stream = fopen("PRN", "w");
      fprintf(stream, "a line of text\n");
   }

This method works in Windows NT as well as the MS-DOS and Windows operating systems.

Method 3

Finally, in MS-DOS, an application can use the int86() or int86x() functions to call one of the following BIOS printer services provided by Interrupt 17h:

   service 0: send byte to the printer.
   service 1: initialize the printer.
   service 2: get printer status.

REFERENCES

For more information on the int86() and int86x() functions, refer to the Microsoft C "Run-Time Library Reference" manual.


Additional reference words: kbinf 1.00 1.50 2.00 2.10 4.00 5.10 6.00 6.00a
6.00ax 7.00
KBCategory: kbprg kbfasttip
KBSubCategory: CLngIss
Keywords : kbfasttip kbprg
Version : 5.10 6.00 6.00a 6.00ax 7.00 | 1.
Platform : MS-DOS NT WINDOWS


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: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.