Writing the basics of Windows Port Monitor
I'm trying to find a basic example, tutorial, or blog post on how to write a printer port monitor. I downloaded the Windows DDK and dug through localmon, but it looks like this example is much more complex than just the nuts and bolts basics, and as far as I understand it is slightly different from the OEM port monitor due to the way it handles the registry key and enumeration of ports. Does anyone know of a blog post, tutorial, or even a book that reads to the reader through basic code to get the same thing? I found several links talking about conceptual stuff, but don't understand anything about the code.
a source to share
I wrote my data from specs , there really aren't many APIs to implement.
The only thing that brings people up regularly is EnumPorts, the spooler allocates enough memory for ALL ports, not just you. So you need to make sure you fill all lines from the end of the buffers, don't put them right after your structures.
It doesn't talk about it in the specs, but you can safely put the interface and server functions in the same DLL.
It is also possible to create one port monitor that supports NT and later port monitors such as Windows 2000.
The code in RedMon is much easier to read than the localmon example, which is worth checking out before you start. It's pretty good, because you can compile it in VS, you don't need to use the DDK to build it.
a source to share
I can recommend http://www.codeproject.com/KB/printing/wpa.aspx , which describes how to write a printer driver and also has good hints on what is needed to create a monitor port.
But I believe that a good tutorial in this area is not available on the internet (I would be glad to find someone who can show me that I am wrong). So when I had to tackle this task, I was forced to do it with difficulty: I carefully read the MSDN explanations from this point onwards: http://msdn.microsoft.com/en-us/library/ff561109.aspx . In parallel with reading MSDN, I also checked the code in the DDK you mentioned and try to understand it. I'm sure this solution might work for you as well.
a source to share
I was in the same territory for a serial printer. The best example I found was in this article in Dr Dobbs Journal . The good part is that both the serial port driver and the user space management program are covered, and the project can also be used as an example of how to configure Visual Studio to compile the driver. It's also a bit tricky to find. The article discusses an old NT style driver that worked well for me on XP.
The CodeProject contains many articles about writing drivers and programs to interact with them. They include the source code, and most of them are related to the new WDM and WDF style drivers.
OSROnline is another good resource, especially for discussing specific problems and common mistakes. They also have some useful utilities that you will need.
Some of the most clearly written and understandable driver codes I have come across were example code by Mark Russinovich. Although Microsoft removed the entire source when they bought Sysinternals, some of the best examples can still be found in the cache here and there.
The drivers are pretty interesting. Whatever you do, do it in a virtual machine. Actually.
a source to share