Board index » cppbuilder » Switching printers causes data to go into black hole.
Don Peterson
![]() CBuilder Developer |
Switching printers causes data to go into black hole.2004-07-07 05:50:51 AM cppbuilder83 Using the example in Builder 5 Developer's Guide, I was able to produce printed output from the IDE pretty easily on my development machine. But the user has a printer that operates via a USB cable. My output falls into a black hole, whereas ordinary Notepad/Wordpad works fine. I do get a brief flash of message that seems to be directing the printing toward the printer, and the printer makes a little noise, but that's it. Would you be kind enough to study my code? Why is there such a difference between printers? Thanks! char szDeviceName[CCHDEVICENAME], //Printer Name szDriverName[MAX_PATH], //Dummy variable szPortName[MAX_PATH]; //Dummy variable THandle hPrnDevMode; //Dummy variable int prtok; // For marking printing error. // Get the name of the printer. Printer()->GetPrinter(szDeviceName,szDriverName,szPortName,hPrnDevMode); HANDLE hPrinter; // Printer handle PRINTER_DEFAULTS pd; // Printer access rights for // WinNT/Win2K only, ignored by Win9x ZeroMemory(&pd, sizeof(pd)); // Initialize printer defaults pd.DesiredAccess = PRINTER_ACCESS_USE; // Initialize access rights // Open printer and get a handle to it (which is saved in hPrinter). if(OpenPrinter(szDeviceName, &hPrinter,&pd)) { DOC_INFO_1 docInfo1; // Document information ZeroMemory(&docInfo1, sizeof(docInfo1)); // Init. doc info structure // --- Setup the Doc1 information --- // Name of the Doc (which is shown in the user's Print Manager) docInfo1.pDocName = "Pantry Client Form"; docInfo1.pOutputFile = 0; // Port/File (not used) // Data are sent in RAW format. docInfo1.pDatatype = "RAW"; prtok = 1; // Initialize printing error flag. if(!StartDocPrinter(hPrinter, 1, (LPBYTE)&docInfo1)) // Start the doc. { prtok = 0; // Mark the error. } else { if (!StartPagePrinter(hPrinter)) // Notify system that we want to print. { prtok = 0; // Mark the error. } } if (prtok == 1) // If no error up to now ... { DWORD dwWritten; // Length of data actually sent // Write the data to the Printer (including carrige // returns and line feeds (New Lines)) String varbuf = "\0"; String one = "\r\n\n\n A.R. Nelson Christian Outreach Center\r\n"; String two = " Client Request Form\r\n "; . . . WritePrinter(hPrinter, (LPVOID)one.c_str(), one.Length(), &dwWritten); . . . // Write a New Page to the Printer String ff = "\f"; if(!WritePrinter(hPrinter, (LPVOID)ff.c_str(), ff.Length(), &dwWritten)) { prtok = 0; } // -------------------------------- // --- End of WritePrinter Code --- // -------------------------------- // Tell the printer we're finished printing if (!EndPagePrinter(hPrinter)) { prtok = 0; // Mark the error. } // End the document if(!EndDocPrinter(hPrinter)) { prtok = 0; } // Close the printer ClosePrinter(hPrinter); } |