Link to home
Start Free TrialLog in
Avatar of prangel
prangel

asked on

Need to hook in during NT40 print operations . . .

Hi!  Thanks for helping me out!

NT4.0, MSVC++6, MFC.  

I need to be able to present my users with a 'Fill in the blanks.' style dialog box each time they print from any application at any time.  I should present this dialog box whether the print job is going to a local printer or to a network printer.  

What would be the appropriate place to hook into the printing process?  Should the monitoring of the hook point be done with a service or what?  It would be great if you have some MFC code to support your answer!

Thanks a million for your help!

prangel
Avatar of jkr
jkr
Flag of Germany image

Why don't you just add/show your dialog box in the 'OnBeginPrinting()' method of your CView-derived class?
Avatar of prangel
prangel

ASKER

Hi JKR,

Thanks for your comment.  That would be great if I only needed to present the dialog box from some application that I am writing, but as I said in my question 'any application at any time'.  I guess that my wording could have been clearer . . .  I meant that I need to intercept all print requests from all applications.

prangel
Sorry, I missed the 'any application' part :o)

In this case, you might want to take a look into the Detours library, which allows hooking virtaully anything on NT-based systems: http://research.microsoft.com/sn/detours/
Or look at my API hooking package, which has some advantages over Detours:

http://help.madshi.net/Data/madCodeHook.htm

My package is available for Delphi and C++. It's free for non-commercial usage.

Regardless of whether you will be using my package or Detours, both packages only handle API hooks in the current process. That means you will have to put your hooking stuff into a little dll and inject your dll into every running process (my package has a InjectLibrary function for that purpose). You'll also have to watch out for new processes. Maybe you can misuse SetWindowsHookEx for that purpose. I've planned to automize this system-wide problem in a future version of my package, but I've no idea when I will find the time to do so...

Regards, Madshi.
Avatar of prangel

ASKER

Hi Madshi and JKR,

I appriciate you taking the time to comment on my question.  I have looked at Madshi's CodeHook and it looks good, but I need a system-wide hook in NT4 and Win98.  Thanks anyway.

I am not have any trouble developing a system-wide hook, I just don't know what to look for in my CALLBACK function to trap all printing processes.  And, I'm not sure whether to use WH_SYSMSGFILTER or WH_MSGFILTER or what in SetWindowsHookEx()!  Any help there?

Thanks,

prangel
I think the CBT hook is the one that would fit best, because it helps putting your dll into every process which creates a new window.

Which API should you use in order to intercept the printing? Well, that's kind of difficult. I guess you should try to hook CreateDC. The second parameter "lpszDevice" will be the name of the printer. If this parameter is empty, don't show your box, then it's no printer device context.

In win98 hooking CreateDC is a bit dangerous, because it's a shared API. You can't even do that with Detours. My library can do it, but you have to really really make sure that your dll correctly unhooks before unloading. Otherwise the system might get unstable...

This kind of stuff is really difficult, prepare for some ugly problems.

Regards, Madshi.
Avatar of prangel

ASKER

I really want to thank all who have puzzeled over my little problem, but it looks like I have managed to find a way to do it on my own.  By using FindFirstPrinterChangeNotification() and FindNextPrinterChangeNotification() it looks like I can get all the printer event notification that I need.

Once again, thanks for your help!

prangel
Avatar of prangel

ASKER

I really want to thank all who have puzzeled over my little problem, but it looks like I have managed to find a way to do it on my own.  By using FindFirstPrinterChangeNotification() and FindNextPrinterChangeNotification() it looks like I can get all the printer event notification that I need.

Once again, thanks for your help!

prangel
Well, then we probably didn't understand what you really want. But nice, that you found a solution.
ASKER CERTIFIED SOLUTION
Avatar of SpazMODic
SpazMODic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
subscribed