Developing a custom printer driver for Windows - windows

For the needs of my software I need to create a printer driver which will allow me to save all the images which are sent to it to files and then open my program's window letting the user to do something with the rendered pages.
I have found this article, but the sample uses the FILE: port, while I need to make my own port, dump the images to files and run an executable. However, I think I can accomplish my task by doing that in the driver's code, but I am not really sure that it is a good decision, since it is a driver, even though it is a user-mode driver.
I would be glad to hear any advice on my problem. Thanks in advance.

You need a port monitor, not a driver. See my answer to this question. You can use RedMon, but I recommend using the sample port monitor found in the WDK instead.

If you are OK with using XPS as format you can use the Github project: Microsoft/Windows-driver-samples/print/XPSDrvSmpl
https://github.com/Microsoft/Windows-driver-samples/tree/master/print/XPSDrvSmpl
Installer: http://wixtoolset.org/
Application: Listen to internal port
Flow: Install printer and application from a single installer. User prints something with your driver and while the application listens to the internal port. When data is sent the application picks it up. This is for XPS, can be converted to PDF, but the flow is similar no matter what you are printing. If you need anything else check out Microsoft/Windows-driver-samples/print/ on GitHub or other sources specific to your needs.

Related

See what com ports an application is calling?

I have an application in windows, that opens a com port. It attempts to call a comport, then fails and prompts me with an error.
The issue is this is very legacy software that we no longer have the source code for. I'm wondering if anyone knows of a way that can trace, or follow a program calling a com port to find out what com port its attempting to allocate.
Appearantly you can use Process Explorer (as called out in this post) to search for processes using serial ports. It sounds like you should be able to use the same searching concept called out the other post to find what you need.
I actually gave up on this solution and re-wrote the entire program in a week, it had to be done due to binary compatibility issues with the PCI cards.

Writing a virtual printer driver for windows

I am new to windows development and I am trying to write a user-mode windows(XP, Vista & 7) virtual printer driver. My aim is to intercept the output being sent to the hardware printer by a third party app and add some extra data(text + graphics) to that output towards the end of the output. Then send the final payload to be printed by the hardware printer. Note that my data would not be added to every print out from the machine but just from a particular third party app.
I want to add my extra data to the print output before it gets converted to any Page Description Language(PDL). Can I do this? Would I be able to predictably add my extra data at the end of the output with proper formatting? If yes, then what kind of driver would I need to write and at what layer of the architecture ?
Is there a better way to do the same thing then writing a user-mode printer driver?
Finally, is there a sample code, online blog or book which can help me with this ?
I think you'd be better off getting the application to write to a generic Postscript driver and post-processing the resulting Postscript rather than trying to make sense of the data written to a printer driver; there are excellent open-source tools available for manipulating Postscript.
This page describes setting up a driver on Windows that will produce Postscript although you will want to do something else with the Postscript other than sending it to another printer as described there.
I don't think you need a driver. Just use the standard Postscript driver provided with the WDK, adding .PPD and .INF files to name it and specify characteristics, and then put your code in a port monitor. Port monitors are considerably easier to build and maintain than print drivers.

How can we receive a volume attaching notification

When a volume is attached to file system, on Windows,
the Window explorer detects the volume and refreshes automatically.
I wonder the technique.
How do an program(include device driver) get the notification?
-Of course, it doesn’t mean a polling. I want to get an event(or a message).
I would like to get the notification when a network volume(like SMB) is attached.
Thanks in advance.
You're going to have to do some research, but basically you just need to register with the Windows IO Manager so that when the device is connected, some part of your code is called. RegisterDeviceNotification() is probably a good place to get started. When the device is connected, the IO Manager will send you a message, so you should make sure you have a proper callback setup for the message.
It would not hurt to read up on Windows Devices Services from the Windows System API. Depending on what you are doing, you may or may not need a driver as the generic driver provided by Microsoft is often good enough. For drivers, check out the Windows Driver Kit, it contains an excellent collection of sample drivers, as well as Win32 code for interfacing with drivers and working with hardware.
Good luck!

Making a soft copy(file) of everything printed to any printer from a Windows workstation?

I have been looking into the possibility of creating a soft copy(image/EMF file) of everything printed from Windows - for archival purposes. Does anyone know if it is possible to create a hooking DLL that can grab the printed data in such a general way?
A low tech way of solving it might be to install pdf printer driver as the default printer and remove all others and set it up to automatically write all the files to certain directory on the network and then write a tiny app on another computer to monitor that folder for changes and if any new pdfs appear just print them out to a real printer.
Edit: Otherwise there's apparently something called the Print Monitor API. Here's an article that describes using that from VC++ 6 and seems to be pretty much what you want (assuming it's still supported by the OS you use).
Having looked at this problem in more detail the best solution seems to handle it through Spooler notifications in the Win32.

How can I redirect Windows COM port output to a file?

Is there a simple way of redirecting serial port output to a file, that I can put into place on a test Windows desktop system without changing any code?
I'm trying to debug a problem in a serial receipt printer module and I don't have the real device handy today. I don't want to start making any changes to the code if I can help it, I just want to capture what is currently being output at the moment so that I can review it in a file.
It's Windows XP, if that makes any difference.
Another option is through command line:
type com1: >> data.log
Another option: Use putty and turn on logging.
A quick google led me to RS232 Data Logger - I haven't tried it, but if it does what it says on the tin it should be OK for you. Edit: it appears to be incoming, not outgoing. Might be worth a try though :-)
You could run the printer module in a VM. VMWare allows you to redirect serial ports to files and named pipes.
Similar to VMWare, Virtual PC (& Virtual Server) can also redirect a COM port to a text file and setup is very simple.
I think in the control pandel, printers, you can add manual printer and install dummay one
So you can printing to a file for example
If you are developer use Serial Port component from .NET or if you don't are a developer and only want get information to file use windows HyperTerminal
I don't know if you can redirect COM ports but you can use com0com for that kind of job.
For example, you can pair (COM1, COM2), so you can write to COM1 and read from COM2.

Resources