How to create own XP printer driver

10,706

Solution 1

What you need is not a printer driver. One named it Print Monitor. It is a DLL, which will be loaded in Spooler.exe process. The DLL gives Spooler at the initialisation phase a logical names of ports like LPT1:, FILE:, SPSPort: etc. The optput prepared with a printer driver must be send in any way to a destination device. This work does print monitors like "Standard TCP/IP Port" or "Local Port".

To write printer monitor you need download and install Windows Driver Kit (WDK or some time ago DDK see http://www.microsoft.com/whdc/devtools/WDK/default.mspx). More information about writing printer monitor see http://msdn.microsoft.com/en-us/library/ff563806(v=VS.85).aspx. Print Monitor is a DLL with some exported function (see http://msdn.microsoft.com/en-us/library/ff549405(v=VS.85).aspx). I recomment you to start with modifying of Local Monitor example LocalMon which full source sode you find after installing of WDK (see http://msdn.microsoft.com/en-us/library/ff556478(v=VS.85).aspx).

The most practical problem with writing of printer monitor is requirement of writing a real multithreaded DLL. You must be very carefull, understand and use EnterCriticalSection in all you functions. For debugging of printer monitor you should connect Visual Studio Debugger to the process Spooler. The rest is the same as writing of a standard windows Win32/Win64 DLL running.

UPDATED: One more small remark. If you don't want that the printer driver do anything with the data sent to the printer you can use generic printer driver. You will find it under "Generic" manufacture, printer with the name "Generic / Text Only". Examine some driver settings which you has (like CR LF settings)

Solution 2

While I can't offer any specific advice, if I wanted to do what you describe, the first thing I would do is read through the source for PDFCreator — it's a Windows print driver which can spit out PDFs.

Solution 3

Combine these programs, first cpri (for access through your code to a printer device)

It's in C language

http://sourceforge.net/projects/cpri/

then you can use

http://sourceforge.net/projects/pdfcreator

to get a virtual printer to generate the pdf, xps format output

Share:
10,706
CJ7
Author by

CJ7

Updated on June 05, 2022

Comments

  • CJ7
    CJ7 about 2 years

    How would I create my own XP printer driver which will do the following:

    • print to file (probably XPS format)
    • put this file into a password protected ZIP file
    • email the zip file to a configured email address
  • Jason
    Jason about 14 years
    PDFCreator is internally using RedMon(pages.cs.wisc.edu/~ghost/redmon) to capture print data. Go for RedMon directly, it's also an opensource project works as a Port Monitor.
  • egrunin
    egrunin about 14 years
    This is the correct answer, I've done things like this. But you don't want to do any more than necessary inside the spooler process: after you grab the data, start a new process that does the zipping and emailing.
  • Stobor
    Stobor about 14 years
    @Jason: +1 - I specifically recommend redmon. In fact, you should submit that as an answer.
  • Oleg
    Oleg about 14 years
    @egrunin: Good suggestion to make more complex work inside a separate processes! I wrote also many year ago a Print Monitor and I can say that the most complex problem is debugging in a multi-thread multiuser environment. Starting of the separate processes can make debugging easier.
  • Nicolai Lissau
    Nicolai Lissau over 10 years
    All of the links in this article are dead. Any possible update?
  • Oleg
    Oleg over 10 years
    @Attaque: The current version of WDK can be downloaded from here. The documentation of Print Monitor is currently here. The reference on the LOCALMON example in WDK is here. The links can be broken of cause some years later. One can just search in Internet for the terminology (like "Printer Monitor" or "Port Monitor") which I used in my answer.
  • Nicolai Lissau
    Nicolai Lissau over 10 years
    The links are up and running again. May have been my connection. I apologize.