JHuang
asked on
How to output a string to printer directly?
I want to make a program to output a string to the printer directly under DOS.
I remember it may like:
fprintf(??????, "%s", "Hello\n");
I can't remeber the ?????? now. Please help me.
I remember it may like:
fprintf(??????, "%s", "Hello\n");
I can't remeber the ?????? now. Please help me.
pls to refer the c or c++ book, or you just refer to chapter 5 or 6
in c/ctt
in c/ctt
ASKER
Tahnk you for your attention.
Unfortunately, I haven't any reference book in hand. I can't find it in the HELP, either. I need use this function right now. Would you please tell me the exact function?
Thank you!
Unfortunately, I haven't any reference book in hand. I can't find it in the HELP, either. I need use this function right now. Would you please tell me the exact function?
Thank you!
in theory, stdprn is the standard printer (after including <stdio.h>), so that fprintf(stdprn,"%s \n", "hello"); should be what you are looking for. Please let me know if it doesn't work.
ASKER
I've tried: fprintf(stdprn, "%s\n", "Hello");
But the compiler says that stdprn is an "undeclared identifier".
In fact, I am using VC60 to make a simple console test program. Just a simple testing, but it doesn't work. It made me crazy.
I am using WIN 98.
You may use VC60 "WIN32 CONSOLE APPlication" to verify that.
Thank you!
But the compiler says that stdprn is an "undeclared identifier".
In fact, I am using VC60 to make a simple console test program. Just a simple testing, but it doesn't work. It made me crazy.
I am using WIN 98.
You may use VC60 "WIN32 CONSOLE APPlication" to verify that.
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do you have access to another compiler? This is wierd, but I checked with Borland CV++ v5.02, which is all that I have in the office at the moment & it also gives an error! Even though I can position the cursor on "stdprn" & hit ctrl-F1 for context sensitive help; it says that all I need to do is include stdio.h.
The solution may depend on how desparate you are <g>. You could either D/L GNU's g++ or other free compiler. DO you want to mix output to screen & printer, or all to printer (in which case you could use a batch file to redirect output to LPT1:).
Hmm, try peeking about in stdio.h - you may have to #define or #undef a few things to get it working. Basically, you are looking for something like this:
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
The solution may depend on how desparate you are <g>. You could either D/L GNU's g++ or other free compiler. DO you want to mix output to screen & printer, or all to printer (in which case you could use a batch file to redirect output to LPT1:).
Hmm, try peeking about in stdio.h - you may have to #define or #undef a few things to get it working. Basically, you are looking for something like this:
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
I HAVE THE SAME PROBLEM IF GOT THAT PLEASE MAIL THE CODE TO MY MAIL skumar@iicindia.com
ASKER
beddot:
You are right! But how can I find the Pinter device name.
Like you said "/* supposing LPT1 is the name of the printer driver */"
I tried LPT1, it works. How can I use the other printer driver, like Microsoft Fax?
I will grade you next time.
Thank you for your help.
You are right! But how can I find the Pinter device name.
Like you said "/* supposing LPT1 is the name of the printer driver */"
I tried LPT1, it works. How can I use the other printer driver, like Microsoft Fax?
I will grade you next time.
Thank you for your help.
ASKER
graham K:
I checked "stdio.h".
I only found:
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
I couldn't find
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
It seems VC6.0 has deleted stdprn from the system.
That's why I can't use stdprn in VC 6.0.
Thank you and good luck!
I checked "stdio.h".
I only found:
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
I couldn't find
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
It seems VC6.0 has deleted stdprn from the system.
That's why I can't use stdprn in VC 6.0.
Thank you and good luck!
o.k, you're using VC & I'm using Borland. I found this Borland FAQ page on the WEB. Maybe you need to compile a DOS program, not a console app?
from http://www.borland.com/devsupport/bcppbuilder/faq/FAQ2019C.html
Question and Answer Database
FAQ2019C.txt STDPRN and STDAUX
Category :C/C++ Language Issues
Platform :All
Product :BC++ 5.x
Question:
Why doesn't STDPRN (from STDIO.H) work in my Win32 Console
Program or my EasyWin Program?
Answer:
The stdprn and stdio macros that are defined in STDIO.H will
only work properly when the program is compiled as a DOS
executable.
There are two reasons for this :
1) The section that defines those macros is wrapped in two
important #ifdef's. The sections dealing with these lines
are not indented, while the rest of the sections of the header
file are indented. The ellipsis (...) indicates that a section
of the header file has been omitted due to it's lack of
relevance to the current topic. Following the header section
is an explanation of each section and it's importance.
The two important #ifdef's have C++ comments following them to
point out this fact.
#if !defined(__FLAT__) // first relevant ifdef
...
#if !defined( _RTLDLL) // second relevant ifdef
extern FILE _RTLENTRY _streams[];
extern unsigned _RTLENTRY _nfile;
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
#else
#ifdef __cplusplus
extern "C" {
#endif
FILE far * far _RTLENTRY __getStream(int);
#ifdef __cplusplus
}
#endif
#define stdin __getStream(0)
#define stdout __getStream(1)
#define stderr __getStream(2)
#endif /* _RTLDLL */
...
#else /* defined __FLAT__ */
...
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
...
#endif /* __FLAT__ */
Now, for the explanation. The first relevant ifdef
is #if !defined(__FLAT__). The section enclosed by this
ifdef will ONLY be used if the FLAT memory model is
not used. This means that it will only work in 16-bit code,
because the FLAT memory model only applies to 32-bit programs.
This means that the section which includes the #defines for
STDPRN and STDAUX will ONLY occur if __FLAT__ is not defined.
This is because STDPRN and STDAUX are not clearly defined
in Win32. A workaround for this would be to do an fopen(lpt1,
etc etc), or to do a CreateFile
The second pertinent ifdef is #if !defined( _RTLDLL).
The section enclosed by this ifdef will ONLY be used if
_RTLDLL is not defined, which means that you are linking with
the STATIC version of the Borland Run Time Library.
(RTLDLL is short for DLL version of Run Time Library)
The EasyWin framework that allows DOS programs to be
run as 16-bit Windows programs in an inactive window has
a modification that redirects STDPRN, STDAUX, and STDERR to
STDOUT.
from http://www.borland.com/devsupport/bcppbuilder/faq/FAQ2019C.html
Question and Answer Database
FAQ2019C.txt STDPRN and STDAUX
Category :C/C++ Language Issues
Platform :All
Product :BC++ 5.x
Question:
Why doesn't STDPRN (from STDIO.H) work in my Win32 Console
Program or my EasyWin Program?
Answer:
The stdprn and stdio macros that are defined in STDIO.H will
only work properly when the program is compiled as a DOS
executable.
There are two reasons for this :
1) The section that defines those macros is wrapped in two
important #ifdef's. The sections dealing with these lines
are not indented, while the rest of the sections of the header
file are indented. The ellipsis (...) indicates that a section
of the header file has been omitted due to it's lack of
relevance to the current topic. Following the header section
is an explanation of each section and it's importance.
The two important #ifdef's have C++ comments following them to
point out this fact.
#if !defined(__FLAT__) // first relevant ifdef
...
#if !defined( _RTLDLL) // second relevant ifdef
extern FILE _RTLENTRY _streams[];
extern unsigned _RTLENTRY _nfile;
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
#else
#ifdef __cplusplus
extern "C" {
#endif
FILE far * far _RTLENTRY __getStream(int);
#ifdef __cplusplus
}
#endif
#define stdin __getStream(0)
#define stdout __getStream(1)
#define stderr __getStream(2)
#endif /* _RTLDLL */
...
#else /* defined __FLAT__ */
...
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
...
#endif /* __FLAT__ */
Now, for the explanation. The first relevant ifdef
is #if !defined(__FLAT__). The section enclosed by this
ifdef will ONLY be used if the FLAT memory model is
not used. This means that it will only work in 16-bit code,
because the FLAT memory model only applies to 32-bit programs.
This means that the section which includes the #defines for
STDPRN and STDAUX will ONLY occur if __FLAT__ is not defined.
This is because STDPRN and STDAUX are not clearly defined
in Win32. A workaround for this would be to do an fopen(lpt1,
etc etc), or to do a CreateFile
The second pertinent ifdef is #if !defined( _RTLDLL).
The section enclosed by this ifdef will ONLY be used if
_RTLDLL is not defined, which means that you are linking with
the STATIC version of the Borland Run Time Library.
(RTLDLL is short for DLL version of Run Time Library)
The EasyWin framework that allows DOS programs to be
run as 16-bit Windows programs in an inactive window has
a modification that redirects STDPRN, STDAUX, and STDERR to
STDOUT.
You said:
I tried LPT1, it works. How can I use the other printer driver, like Microsoft Fax?
Remember you are under DOS, and no other driver than dos drivers are available: so you can't use a special driver that should be accessible under windows;
if LPT1 is the good name of the DOS driver toward parallel interface, and permit to issue ASCII characters, we can't do better !
you must write your own program to drive special printer.
:-(
one phrase of the FAQ above confirms what bedot says : "This is because STDPRN and STDAUX are not clearly defined in Win32", so it looks like you either have to live with the restriction of "lpt1" only, or make your application not be console mode (perhaps you could give it an invisible, one by one pixel, window? but that adds lots of new windows type events to handle & it won't run under DOS any more).
The following link shows the results of a search for "stdprn console" at DejaNews http://x34.deja.com/=dnc/qs.xp?ST=PS&svcclass=dnyr&QRY=stdprn+console&defaultOp=AND&DBS=1&OP=dnquery.xp&LNG=ALL&subjects=&groups=&authors=&fromdate=&todate=&showsort=score&maxhits=25&uniq=941639103.1389363281
these are no stdprn entries at either CodeGuru or KBcafe.
Hmm, could you output to "prn", or other environment variable and make sure that the environment variable points where you want it to? No, probably not. Stupid idea; sorry.
The following link shows the results of a search for "stdprn console" at DejaNews http://x34.deja.com/=dnc/qs.xp?ST=PS&svcclass=dnyr&QRY=stdprn+console&defaultOp=AND&DBS=1&OP=dnquery.xp&LNG=ALL&subjects=&groups=&authors=&fromdate=&todate=&showsort=score&maxhits=25&uniq=941639103.1389363281
these are no stdprn entries at either CodeGuru or KBcafe.
Hmm, could you output to "prn", or other environment variable and make sure that the environment variable points where you want it to? No, probably not. Stupid idea; sorry.
ASKER
Thank you
ASKER