// This is a sample of how to print text to the printer using WriteFile. // // Compile this with // bcc32 -tWE thisfile.cpp // bcc -tWE thisfile.cpp // // Created by George Cross, Borland C++ Developer Support, December 1996 #define STRICT #define UNICODE //for windows.h #define _UNICODE //for tchar.h #define __TRACE //for checks.h #include #include //for unicode RTL string functions #include //for diagnostic macros int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { //Below is the string which will send a carriage return, line feed //and a form feed the printer. // \r = carriage return // \n = line feed // \x0c = form feed TCHAR buf[] = __TEXT("Testing WriteFile to print to the printer.\r\n\x0c"); unsigned long nbyteswritten, ntotalbytes; OFSTRUCT of; HFILE hFile = OpenFile("lpt1", &of, OF_READWRITE); WriteFile((HANDLE) hFile, buf, sizeof(buf), &nbyteswritten, NULL); ntotalbytes += nbyteswritten; _lclose(hFile); TRACE(ntotalbytes << " bytes were sent to the printer"); return 0; }