I want to send documents to my windows application via print driver. to achieve the functionality I've build v4 Print Driver and able to get driver in Print options. now i want to open windows application from Print Driver. I'm unable to find the way to connect. Print Options attached screenshot for your reference. On "print" button I want to open my windows application after selected my printer driver in Printer Options
-
I find it curious you can write a print driver (kernel mode), but you cant start a process from said driver in the users session. Surely at many places where you interacting with the internal print and spool architecture in the actual driver, you can just create a process – TheGeneral Nov 08 '21 at 07:54
-
Another way you could do this, is inject and proxy the printing apis – TheGeneral Nov 08 '21 at 09:47
-
already written print Driver using V4 Print Driver with c++ and able to see the option in "Print", and got the Print option. i didn't have any clue how can i achieve this – developer410 Nov 09 '21 at 17:03
1 Answers
From your application, you can NOT able to connect to your driver directly. Windows does not allow that. Driver will be called by print spooler service, not by any application directly. But your driver can communicate to your application thru inter-process communication, once it receives the print data.
When you print a document from any application, application submits the print job by calling Windows API that Windows spooler generates the spool data which is in XPS (it depends on the driver and print processor) format and send it to your driver (assumed that your driver is based on XPSDrv driver), your driver process the data or save the data or write it back to the spooler, spooler will send the data to the printer using the specific port monitor. You can intercept the spool data (XPS or PDF) and can use it for your purpose. This is a kind of data flow path:[![enter image description here][1]][1]
Spooler generates the spool data mostly it will be .OXPS or .XPS format which is what you would receive in your driver where you could save it to someplace and send the message back to your application thru inter-process communication. [1]: https://i.stack.imgur.com/tVHEW.png

- 360
- 3
- 11
-
I want to send the document other way around. Im sending document from print option ==» my printer. When i select my printer and click on print button it should call my windows application.currently it is going to print service and giving error ie, restart print spooler... Im missing some where the link between printer driver and windows application.. Im looking for that bridge. Note :im using xps print driver – developer410 Dec 04 '21 at 13:58
-
@developer410, you can able to send the document from your driver to your application, but it will be in the spooled data format. – Snekithan Dec 09 '21 at 21:36
-
if you found any articles you think it helps me to go further please share.i have tried all possible ways to connect print driver to application. Getting Below Error "The document Print Document, owned by RP-LPT-XX, failed to print on printer PrintDriver. Try to print the document again, or restart the print spooler. Data type: RAW. Size of the spool file in bytes: 489236. Number of bytes printed: 0. Total number of pages in the document: 6. Number of pages printed: 0. Client computer: \\RP-LPT-XX. Win32 error code returned by the print processor: 193. " – developer410 Dec 13 '21 at 12:06
-
@developer410, (1) I would get the sample code from here (https://github.com/microsoft/Windows-driver-samples/tree/master/print/SimplePipelineFilter) and build and install the driver and set the port as file port (2) After installing the sample driver, submit a print job thru any application and make sure it saves the spool data. (3) I would save the file locally and launch your application inside the driver and provide the file info. I hope this helps. – Snekithan Dec 13 '21 at 21:34