I am trying to send raw bytes to a printer. I have tried various printers and nothing seems to work. OpenPrinter
returns a valid handle and both StartDocPrinter
and StartPagePrinter
succeed. Even WritePrinter
succeeds and writer as many bytes as there was passed in and a print job appears in the spooler window. All appears like a success and still nothing gets printed.
I know writing raw bytes to printer is really printer-specific so I have tried printing to a file and sending those file's contents to WritePrinter
. All appears fine and still no printout. What could be wrong? All sample code I have found so far does this 100% the same as I did. Here is the code:
if (OpenPrinter(printerName, &printer, NULL))
{
DOC_INFO_1 docInfo = {L"Print Job", NULL, L"RAW"};
DWORD printJob = StartDocPrinter(printer, 1, (LPBYTE) &docInfo);
if (printJob != 0)
{
if (StartPagePrinter(printer))
{
DWORD written = 0;
if (WritePrinter(printer, (LPVOID) (LPCSTR) str, str.GetLength(), &written))
{
}
EndPagePrinter(printer);
}
EndDocPrinter(printer);
}
ClosePrinter(printer);
}
[Edit] Printer: Canon iP4200