Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a printer is attached

Is there a way in Windows (which works in Windows CE) to check if a printer is attached and communicating to LPT1 in C++?


[Edit] More info:

We are currently working with a generic Windows CE printer driver - pcl.dll - by passing it into CreateDC, to get the DC for the printer.

We can't call PrintDlg() to show the print dialog because it is "too complicated looking," but we also can't call it with PD_RETURNDEFAULT because we do not want to use the default printer. So, we are manually setting up a DEVMODE structure to pass in to CreateDC.

After we have the DC, we call GetDeviceCaps() to get the info for the printer (such as page-width, etc), then StartPage()/EndPage()/ExtTextOut() to print.

However, if there is no printer attached, the program freezes for about a minute before giving an "Abort/retry/fail?" dialog (I don't know what point in this process it is freezing). Other software doesn't freeze when you attempt to print, so there must be a way of preventing this...

like image 518
BlueRaja - Danny Pflughoeft Avatar asked Sep 16 '10 13:09

BlueRaja - Danny Pflughoeft


1 Answers

When you work with printers in Windows you actually never supposed to work with the port directly, but through the printer driver interface. This obsoletes the knowledge of how to communicate and gives you a toolbox that is the same for all printers, regardless of brand and port.

The Windows API gives you many possibilities to extract extra information from the driver. During my 14 years of printer development, Microsoft has never added support for rich printer status (although I don't know if they have changed that in Windows 7). We, as many other printer developers had to extend the printer driver to present more information to the application.

You should ask your printer developer if they have a Windows CE driver. I'm not sure if the DEVICE_CHANGE message is generated when plugging in /out a parallel printer. It does for USB printers (No need to mess around in the registry).

You can read more about the Printing subsystem here

like image 196
Max Kielland Avatar answered Oct 10 '22 08:10

Max Kielland