Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

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
0
prangel
Asked:
prangel
  • 4
  • 3
  • 2
  • +2
1 Solution
 
jkrCommented:
Why don't you just add/show your dialog box in the 'OnBeginPrinting()' method of your CView-derived class?
0
 
prangelAuthor Commented:
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
0
 
jkrCommented:
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/
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
MadshiCommented:
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.
0
 
prangelAuthor Commented:
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
0
 
MadshiCommented:
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.
0
 
prangelAuthor Commented:
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
0
 
prangelAuthor Commented:
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
0
 
MadshiCommented:
Well, then we probably didn't understand what you really want. But nice, that you found a solution.
0
 
SpazMODicCommented:
PAQed, with points refunded (400)

SpazMODic
EE Moderator
0
 
Jan LouwerensSenior DeveloperCommented:
subscribed
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now