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. 7/2/98 10:32:32 AM
Last Modified: 01-SEP-99