Solved

Need to hook in during NT40  print operations . . .

Posted on 2002-07-15
12
291 Views
Last Modified: 2013-12-03
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
Comment
Question by:prangel
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7154856
Why don't you just add/show your dialog box in the 'OnBeginPrinting()' method of your CView-derived class?
0
 

Author Comment

by:prangel
ID: 7154888
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
 
LVL 86

Expert Comment

by:jkr
ID: 7154907
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
 
LVL 20

Expert Comment

by:Madshi
ID: 7156392
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
 

Author Comment

by:prangel
ID: 7159833
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 20

Expert Comment

by:Madshi
ID: 7161403
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
 

Author Comment

by:prangel
ID: 7162423
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
 

Author Comment

by:prangel
ID: 7162434
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
 
LVL 20

Expert Comment

by:Madshi
ID: 7162629
Well, then we probably didn't understand what you really want. But nice, that you found a solution.
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 9743409
PAQed, with points refunded (400)

SpazMODic
EE Moderator
0
 
LVL 1

Expert Comment

by:jansuper
ID: 9743475
subscribed
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now