PRODUCT : Borland C++ NUMBER : 1717 VERSION : All OS : WIN DATE : October 25, 1993 PAGE : 1/3 TITLE : Printing from an EasyWin Application /* ---------------------------------------------------------- *\ This is an example program that demonstrates a technique to echo output to the printer from within an EasyWin application. This is accomplished by chaining to a function pointer used internally by EasyWin. EasyWin uses the function, _WriteBuf, to handle text output. This function is pointed to by __WriteBufFPtr so, by hooking the current setting for this pointer, it is possible to add functionality ( such as printing ) when outputting via EasyWin. To run the TEST program place the modules, TESTECHO.CPP and ECHOPRNT.C in a project. To add echo printing to other EasyWin applications, include "echoprnt.h" and make calls to StartEchoPrint() and EndEchoPrint() at appropriate locations. It is also necessary to add ECHOPRNT.C to the project. A second method would be to define ECHOALWAYS and add the file ECHOPRNT.C to the project. When ECHOALWAYS is defined ECHOPRNT uses a #pragma startup and #pragma exit to invoke the ECHOPRNT functions, thereby avoiding code modifications to the existing EasyWin application. \* ---------------------------------------------------------- */ // File: TESTECHO.CPP #include #include #include "echoprnt.h" int main() { StartEchoPrint(); printf("send a test string to the printer\n"); puts("another test string\r\n"); cout << "print from C++ program" << endl; EndEchoPrint(); return 0; } PRODUCT : Borland C++ NUMBER : 1717 VERSION : All OS : WIN DATE : October 25, 1993 PAGE : 2/3 TITLE : Printing from an EasyWin Application //=================================================================== // File: ECHOPRNT.H #ifndef __ECHOPRNT_H #define __ECHOPRNT_H #ifdef __cplusplus extern "C"{ #endif void StartEchoPrint(); void EndEchoPrint(); #ifdef __cplusplus } #endif #endif //=============================================================== // File: ECHOPRNT.C #include #include #include "echoprnt.h" typedef void(*WRITEFUNC)(char*, unsigned); FILE *fprn = NULL; WRITEFUNC _SaveBufFPtr; extern WRITEFUNC __WriteBufFPtr; //Function pointer used by //EasyWin ///////////////////////////////////////////////////////////// // EchoPrint: Called by EasyWin. Sends data to printer (PRN) // and then calls original __WriteBufFPtr. void EchoPrint( char* Buffer, unsigned Count ) { // first write the buffer to the printer __WriteBufFPtr =0; PRODUCT : Borland C++ NUMBER : 1717 VERSION : All OS : WIN DATE : October 25, 1993 PAGE : 3/3 TITLE : Printing from an EasyWin Application fwrite( Buffer, Count, 1, fprn ); __WriteBufFPtr = EchoPrint; // now print it to the screen if( _SaveBufFPtr ) _SaveBufFPtr( Buffer, Count ); } ///////////////////////////////////////////////////////////// // StartEchoPrint: Called by our program to hook the EasyWin // function pointer. void StartEchoPrint() { fprn = fopen( "PRN", "w+t" ); _SaveBufFPtr = __WriteBufFPtr; __WriteBufFPtr = EchoPrint; } #ifdef ECHOALWAYS #pragma startup StartEchoPrint 64 #endif ///////////////////////////////////////////////////////////// // EndEchoPrint: Called by our program to restore the EasyWin // function pointer void EndEchoPrint() { __WriteBufFPtr = _SaveBufFPtr; if ( fprn ) { fclose( fprn ); fprn = NULL; } } #ifdef ECHOALWAYS #pragma exit EndEchoPrint 64 #endif DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.