Reputation: 143
I am developing a device on ARM platform with Windows CE 6.0. One of the goals is to provide the user a possibility to print directly from the device (and not only text!). It means, that Windows will have to handle various types of printers. How can I realize such a functionality?
My guesses are: - PCL printing (can you still get a PCL printer?) - Network printing (how to do it - any example?)
Thanks!
Upvotes: 2
Views: 4728
Reputation: 143
Printing is possible under Windows CE 6.0. There is an example of PCL driver in "\WINCE600\PUBLIC\COMMON\OAK\DRIVERS\PRINTER\PCL". To include it in the OS Design set SYSGEN_PRINTING, SYSGEN_PCL and SYSGEN_USB_PRINTER to 1 in Configuraiton Properties --> Environment. It will result in compiling the sample and adding pcl.dll to OS Design. USB Printer Class driver will be also added.
Above action let us print text in ASCII code:
// initialize printing
//hPrinter = CreateFile(L"LPT1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
//if (hPrinter == NULL) RETAILMSG(TRUE, (L"Error in OnClick5 (GUI): CreateFile() returned NULL"));
// print text WORKS
//WriteFile(hPrinter, szText, sizeof(szText), &cBytes, NULL);
// close printer port
//CloseHandle(hPrinter);
But to print for example BMP files, we need to really use the PCL driver (look at the following code). The problem is, that I cannot get rid of a bug: StartDoc() always returns "The network request is not supported". What is the proper way to start the print job?
LPVOID lpMsgBuf = NULL;
HDC hdc = NULL;
DOCINFO di;
DEVMODE dm;
// initialize DEVMODE struct
memset(&dm, 0, sizeof(DEVMODE));
wcscpy(dm.dmDeviceName, L"Hewlett-Packard LaserJet P3010 Series");
dm.dmSize = sizeof(DEVMODE);
dm.dmPaperSize = DMPAPER_A4;
dm.dmPrintQuality = DMRES_DRAFT;
dm.dmFields = DM_PAPERSIZE | DM_PRINTQUALITY;
//PAGESETUPDLG psd;
//memset(&psd, 0, sizeof(psd));
//psd.hwndOwner = NULL;
//psd.hDevMode = NULL;
//psd.hDevNames = NULL;
//psd.Flags = PSD_RETURNDEFAULT;
//psd.lStructSize = sizeof(psd);
//PageSetupDlg(&psd);
//RETAILMSG(TRUE, (L"GUI: PageSetupDlg() result 0x%x", CommDlgExtendedError()));
//if (psd.hDevMode == NULL) return -1;
//DEVMODE* lpdm = (DEVMODE*)psd.hDevMode;
DEVMODE* lpdm = &dm;
// initialize device context
hdc = CreateDC(L"pcl.dll", L"Printer", L"LPT1:", lpdm);
if (hdc == NULL) {
RETAILMSG(TRUE, (L"GUI: CreateDC() error 0x%x", GetLastError()));
return -1;
}
// register abort procedure
SetAbortProc(hdc, AbortProc);
// initialize DOCINFO struct
memset(&di, 0, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = L"logo.bmp";
di.lpszOutput = NULL;
di.lpszDatatype = 0;
di.fwType = 0;
// print file
if (StartDoc(hdc, &di) <= 0) {
RETAILMSG(TRUE, (L"Error in OnClick5 (GUI): StartDoc() returned non-positive value"));
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL);
RETAILMSG(TRUE, ((LPWSTR)lpMsgBuf));
LocalFree( lpMsgBuf );
DeleteDC(hdc);
return -1;
}
Upvotes: 4