A9S6
A9S6

Reputation: 6675

Writing a Windows Printer Driver

I want to write a application in C++ or C# that will behave as a printer driver when installed. It will be available in the drop down list in Print dialog but instead of printing it will call into my code.

I think there may be some interfaces that Windows provide to write printer drivers.

Upvotes: 15

Views: 25471

Answers (2)

Snekithan
Snekithan

Reputation: 500

What you are asking is not available in Windows. You could have your own printer driver developed using PostScript, UniDrv, XPSDrv driver. When the driver is installed as part of the Add Printer which will create a print queue with the driver. Discovery and device installation is another topic. This driver will be called by the Windows Print system when print job is submitted from your app. Windows Print system consist of Print Spooler, Print Processor, Port Monitor, Language Monitor. When your app call Win32 or .NET print APIs which will call common print dialog or Modern Print Dialog component to display the print dialog interface which list the printers. When you submit the print job, spooler generates the spool data in XPS format and sent it to your driver. Your driver process the driver and write out to the spooler or save it to file depends on the port configuration.

Upvotes: 0

dirkgently
dirkgently

Reputation: 111288

Windows provides loads of interfaces. Do you know what sort of a printer driver you want to write? At present, Windows supports three flavors of printer drivers -- PostScript, Unidrv and XPSDrv (the latter on XP/2003 Server with EP 1.0 and upwards only). Most of the time, it suffices to write a driver plug-in instead. Read up on INF architecture to know these things get installed, specially the section on minidrivers.

As suggested, you will need the WDK to be able to build a driver or a plug-in thereof. Note that drivers do not use the Visual Studio IDE or compilers. The WDK comes with a compiler of its own. You can always hook up the latter with VS, but that's a different story.

The WDK has setups to target different OS-es. You will have to know which OS (or set of OS-es) you want to address and choose the appropriate setup.

I want to write a simple driver that will displays in the list of printers.

I don't see how that will be helpful. If you are writing a driver, why would you want a list of all other drivers present on the system?

Printing to this driver will call into my code so that I can do stuff like create a PDF of the document, calling the Web Service etc.

Interesting! You can achieve all those things in a UI plug-in. An UI plug-in is a dll that is loaded when you select the Advanced driver properties.

To get started with UI plug-ins take a look at the sample oemui source code in the WDK.

Upvotes: 21

Related Questions