Solved

Printing to PRN with Borland c++

Posted on 1998-05-31
14
708 Views
Last Modified: 2013-12-29
I am using Borland c++ for Windows v3.1 on Win95 and am trying to print to the printer attached to parallel port 1.  The "standard" stdprn file doesn't work, so I tried explicitly opening PRN:

p = fopen("PRN", "w");
fprintf(p, "this is a test\n");
fclose(p);

but the text is written to the screen!

Does anybody know what I'm doing wrong?
0
Comment
Question by:nipper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
14 Comments
 

Author Comment

by:nipper
ID: 1713909
Edited text of question
0
 
LVL 14

Expert Comment

by:smeebud
ID: 1713910
Try setting up a generic/text printer fot prn to text, it's great.
==========
1. From a Dos Window, C:\>
In this exampe I'll use PRINT.PRN IN DIRECTORY 2 [C:\2]

YOU WOULD TYPE AT THE C:\>

C:\>PRINT C:\2\PRINT.PRN LPT1 [enter]

The lpt1 is my printer port. You would substitute LPT1 for you printer port.
It well may be the same.

 2. For making .prns to .txt, eliminating the prn altogeather..
Have you Windows 95 CD-ROM inserted.
If you are running Win95 (any version) go to start-settings-printers, click add printer
and add the printer Generic/Text Only (Manufacturer:Generic).
The next time you choose "Print to FILE" you can call the Filname.prn to Filname.txt.
Of course you do printer setup first and choose Generic/text Printer.
If you then "print" to this printer, it will create a text file.
Nice Huh!!

Files used by this printer Driver:
C:\WINDOWS\SYSTEM\TTY.DRV
C:\WINDOWS\SYSTEM\TTY.HLP
C:\WINDOWS\SYSTEM\UNIDRV.DLL
C:\WINDOWS\SYSTEM\UNIDRV.HLP
C:\WINDOWS\SYSTEM\ICONLIB.DLL

MORE OPTIONS CURTESY OF
Jon Eva  http://www.gallicrow.co.uk

1. From the Start menu, select Settings > Printers, the Printers window will
pop up, showing an icon for each of the printers you have at your disposal, plus
an icon called "Add Printer".
2. Double click on this icon.
3. The Add Printer Wizard window will pop up, click on Next.
4. Select the manufacturer and model of the printer you will eventually send the
.prn files to. Rather than scrolling through the entire list of manufacturers, just
press the first letter of their name (e.g. H for HP) on the keyboard
and the list will jump to the manufacturers starting with that letter.
5. Once the correct manufacturer / printer has been selected click on Next.
Keep the existing driver for this printer, click on Next.
You will be shown a list of ports, select the one which says:
"File: Creates a file on disk", click on Next.
6. Enter a name for this printer, e.g. "HP Laserjet (FILE)" and select whether to
use this printer as the default, click on Next.
Don't bother 'printing' a test page, click on Finish.
If you now 'print' to this printer a dialog asking you the name of the file to
print to will pop up.
=======
How can I print to the same file each time, without being prompted for a filename?

Short answer

Add a new local port named with a filename.
Long answer

Add a new printer that prints to the special "File:" port (see question 1).
From the printers' panel, right click on the printer you have just added
and select Properties.
A panel showing the properties for this printer will pop up, click on the
Details tab of this panel.
Click on the Add Port... button.
The Add Port panel will pop up, click on the Other radio button, and make
sure Local Port is highlighted, click on OK.
A small panel asking for the name of the port will pop up, enter the name of
a file in the edit box, for example C:\Output.prn.
Click on OK to dismiss the panel asking for the port name.
Click on OK to dismiss the printer properties panel.
If you now 'print' to this printer the output will be sent directly to
C:\Output.prn (or wherever), overwriting what was there before.
=========
How do I create a simple text file when "Printing to file"?
Short answer

Use the "Generic / Text" driver.
Long answer

From the Start menu, select Settings > Printers, the Printers window will
pop up, showing an icon for each of
the printers you have at your disposal, plus an icon called "Add Printer".
Double click on this icon.
The Add Printer Wizard window will pop up, click on Next.
Now select the "Generic / Text" printer driver - press the 'G' key, the list
of manufacturers should jump to
those beginning with G, highlight the one which says "Generic".
There should only be one model for the Generic manufacturer,
called "Generic / Text Only", make sure it is highlighted and click on Next.
Keep the existing driver for this printer, click on Next.
You will be shown a list of ports, select the one which says:
"File: Creates a file on disk", click on Next.
Enter a name for this printer, e.g. "Text File" and select whether to use
this printer as the default, click on Next.
Don't bother 'printing' a test page, click on Finish.
If you now 'print' to this printer a dialog asking you the name of the file
to print to will pop up.

Bud
0
 

Author Comment

by:nipper
ID: 1713911
Actually, want I want to do is print to the default printer from a program written using Borlan c++ v3.1.  As I said, I tried the sample program (fragment) listed in the text of the original question, but the output goes to the screen.

I don't want to print a .prn file - I already know how to do that.  I am writing/have written a c-program using Borland c++ v3.1 (for Windows), but the fprintf to either "stdprn" or the FILE I have opened as "PRN" (or "LPT1") prints to the screen: no output on the printer.

Unless I have totally misunderstood your answer...

Any ideas?
0
Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

 
LVL 14

Expert Comment

by:smeebud
ID: 1713912
I think you did.
If your program allows you to print to file [prn] then.
What I'm proposing is you print to text.
Maybe I'm missunderstanding you??

If you do what to print to text, then
----------
 2. For making .prns to .txt, eliminating the prn altogeather..
Have you Windows 95 CD-ROM inserted.
If you are running Win95 (any version) go to start-settings-printers, click add printer
and add the printer Generic/Text Only (Manufacturer:Generic).
The next time you choose "Print to FILE" you can call the Filname.prn to Filname.txt.
Of course you do printer setup first and choose Generic/text Printer.
If you then "print" to this printer, it will create a text file.
Nice Huh!!

Files used by this printer Driver:
C:\WINDOWS\SYSTEM\TTY.DRV
C:\WINDOWS\SYSTEM\TTY.HLP
C:\WINDOWS\SYSTEM\UNIDRV.DLL
C:\WINDOWS\SYSTEM\UNIDRV.HLP
C:\WINDOWS\SYSTEM\ICONLIB.DLL

MORE OPTIONS CURTESY OF
Jon Eva  http://www.gallicrow.co.uk

1. From the Start menu, select Settings > Printers, the Printers window will
pop up, showing an icon for each of the printers you have at your disposal, plus
an icon called "Add Printer".
2. Double click on this icon.
3. The Add Printer Wizard window will pop up, click on Next.
4. Select the manufacturer and model of the printer you will eventually send the
.prn files to. Rather than scrolling through the entire list of manufacturers, just
press the first letter of their name (e.g. H for HP) on the keyboard
and the list will jump to the manufacturers starting with that letter.
5. Once the correct manufacturer / printer has been selected click on Next.
Keep the existing driver for this printer, click on Next.
You will be shown a list of ports, select the one which says:
"File: Creates a file on disk", click on Next.
6. Enter a name for this printer, e.g. "HP Laserjet (FILE)" and select whether to
use this printer as the default, click on Next.
Don't bother 'printing' a test page, click on Finish.
If you now 'print' to this printer a dialog asking you the name of the file to
print to will pop up.

Let me know if I'm not getting what you're after
Bud
0
 
LVL 1

Expert Comment

by:delirium
ID: 1713913
Well, I don't know what exactly your program does, but wouldn't fprintf(stdprn,"text") work?
0
 

Author Comment

by:nipper
ID: 1713914
Ok - we must be misunderstanding each other.

I have a c-program, written using Borland c++ v3.1.
Borland c/c++ allows the programmer to fprintf to the "standard" file "stdprn".  Just as "stdout" is the screen, "stdprn" is the default printer.  This program works in DOS - the fprintfs to "stdprn" are sent to the printer - but under Windows95 the output to stdprn is redirected to the screen...  The same occurs if an explicit fopen of "PRN" or "LPT1" is done.


0
 
LVL 7

Expert Comment

by:busuka
ID: 1713915
I can tell you to use Int 17h, like:

void prnchar (char prch)
{
 _AH_=0; //
 _AL_=prch;
 _DX_=0; // 0 - LPT1, 1 - LPT2, etc.
 __int__(0x17);
}

or

asm
{
 xor ah,ah
 xor dx,dx
 mov al,prch
 int 17h
}

Then with simple loop you can write a function to print any string.

0
 
LVL 7

Expert Comment

by:busuka
ID: 1713916
Oops, error in registers syntax. I think you write _AX, _DX, etc.
0
 
LVL 1

Expert Comment

by:tchris
ID: 1713917
Wouldn't this question be more appropriate in the C++ group?

Most of my experience has been C++ for DOS, but it seems that Windows isn't ever gonna let you go directly to the hardware that way.  You have to use some Win API calls to get through the print manager, etc..  Windows generally doesn't like / allow your programs to access hardware directly like you do in DOS.

Terry
0
 
LVL 7

Expert Comment

by:busuka
ID: 1713918
But if your program is DOS-based and ran in DOS box under Win95
and uses direct access to h/w (like designed before all Windozes),
what will happen ? Win95 must emulate direct h/w access by
redirecting it to appropriate driver. Mea culpa, I gave C-based
answer, driving you to think that question belongs to one of C
forums. :-]
0
 
LVL 1

Expert Comment

by:tchris
ID: 1713919
If he is trying to write a DOS program and run it in a DOS box, then BC++ for Win ain't gonna get it.  That makes Win .EXE's and I don't think they will do what you describe.  If its for Windows, it will require a Win API call, if it's for DOS it will require a DOS compiler.

Terry

0
 
LVL 7

Expert Comment

by:busuka
ID: 1713920
Hint from nipper's comment:
This program works in DOS - the fprintfs to "stdprn" are
sent to the printer - but under Windows95 the output to stdprn is redirected to the screen.

Obviously EXE is DOS-executable.
0
 
LVL 1

Expert Comment

by:tchris
ID: 1713921
Doh!  I missed that comment. :(

What's the skinny on your Win95 printer setup?  Just a regular Printer-"X"-attached-to-LPT1 setup?

Terry

0
 
LVL 7

Accepted Solution

by:
busuka earned 100 total points
ID: 1713922
nipper, I believe that little piece of code, that I wrote will
help to solve your problem. Any feedback ?
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

724 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