Solved

DOS C sending to printer in Visual C++

Posted on 1997-04-21
7
369 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

810 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