Solved

DOS C sending to printer in Visual C++

Posted on 1997-04-21
7
373 Views
Last Modified: 2013-12-14
I need help programming in Visual C++ std 4.0 for win 95.  I'm using the C language, and I need to know how to send text to the printer.  fprintf(stdprn,...) doesn't work.  Is there any other way I can get my txt to the printer.  NOTE: I need to be able to send variables with the text as well... thanx.  Let me know if you'd like to see my source code... well the general format of each of my statements is

fprintf(stdprn, "Message!  [Variable: %d]", [aVar]);

Thanx
Direwolf
direwolf@emapnet.com
0
Comment
Question by:direwolf
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250049
Here is your answer straight from VC help...  
PSS ID Number: Q23976
Article last modified on 11-07-1995
 
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
 

 
----------------------------------------------------------------------
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
=============================================================================
Copyright Microsoft Corporation 1995.

0
 

Author Comment

by:direwolf
ID: 1250050
Perhaps I should give you my source code, because this is not working.  Though I will give you credit, at least it will compile.  Here's my code:

// structure of the output variable

struct tgChr {
      char name[31];
      int fi;
      int dx;
      int in;
      int ju;
      int ps;
      int ch; };

// Code of program...

void printCharacter()
{
      FILE *stream;
      puts("Get Ready to Print\nPress Return to Print");
      fflush(stdin);
      getchar();
      fflush(stdin);
      puts("Printing Character...");
      stream = fopen("PRN", "w");
      fprintf(stream, "The Game Character\n");
      fprintf(stream, "File created with The Game Character Generater\n");
      fprintf(stream, "VERSION for DOS.\n");
      fprintf(stream, "by Andrew Gould\n");
      fprintf(stream, "Name: \t\t%s\n", curChar.name);
      fprintf(stream, "Fitness: \t%d\n", curChar.fi);
      fprintf(stream, "Dexterity: \t%d\n", curChar.dx);
      fprintf(stream, "Intelligence:\t%d\n", curChar.in);
      fprintf(stream, "Judgement:\t%d\n", curChar.ju);
      fprintf(stream, "Psyche:\t\t%d\n", curChar.ps);
      fprintf(stream, "Charisma:\t%d\n", curChar.ch);
      puts("Printing competed.");
}

My variables are all there... the point where this fails in frpintf.c is _ASSERT(str != NULL) [line 56]

Perhaps you can figure it out now?  Your other answer did not work...
0
 

Author Comment

by:direwolf
ID: 1250051
Adjusted points to 30
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250052
Have you captured your printer .. perhaps PRN only works when a printer is caputred (check your printer properties)
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1250053
Note: that the "str" referred to in the assert if your "stream" variable - ie. your fopen failed.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 30 total points
ID: 1250054
Try capturing your printer as LPT1 first.No try opening LPT1 in your program.Don't forget to check for a successful open.
0
 

Author Comment

by:direwolf
ID: 1250055
It worked... here's the syntax:

FILE * printer;
printer = fopen("LPT1", "a"); // or LPT2
fprint(printer, "TEXT [%conversion...]"[, aVar[,...]]);
fclose(printer);

Thanx for your help...
Direwolf
direwolf@emapnet.com
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to show menu 5 96
Problem to scan all sheets 3 118
Memory going from 12gb to 64gb or 96gb. worth it? 15 213
MySQL recovery 7 27
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question