I have been on this for almost 2 days, and I haven't accomplish anything!!
I have been assigned to write a program to count number of pages printed on windows OS.
As far as I know, I need to intercept printing events and count them internally. which I should use FindFirstPrinterChangeNotification
and FindNextPrinterChangeNotification
.
I have assigned a callback function PrinterNotifyWaitCallback
with following signature, and it gets fire multiple times when a printing event happens.
public void PrinterNotifyWaitCallback(Object state, bool timedOut) { ... }
Problem:
I have some clue on why a printing event would fire PrinterNotifyWaitCallback
multiple times, BUT I cannot distinguish the actual printing callback event among those multiple callbacks, which obviously it has to do with Object state
but there is zero document on how to achieve my objective, which is counting the printed pages.
Questions:
- How to distinguish the actual printing callback of
PrinterNotifyWaitCallback
to count the total printed# of pages system wide? - Is there any other better way to accomplish the task?
I have found the solution roughly through
WMI
. For what it's worth I came up with following to count the printed pages.