Solved

Intercepting print jobs by hooking createDCW and createDCA

Posted on 2006-06-09
3
1,173 Views
Last Modified: 2013-12-03
I have been trying to implement password protected printing by hooking createDCW and createDCA and either ‘doing nothing’ or passing the call onto the OS depending on whether the correct password has been entered.

‘doing nothing’ appeared to work, and prevent printing, for applications like Notepad, but caused problems with apps like MS Excel which would get stuck in a loop showing an error.

So in the hook I tried returning NULL, the value returned by createDCW and createDCA if they fail. This caused MS Excel to simply close after trying to print.

I then tried repeating the createDCW/ createDCA as normal, but following it with an AbortDoc, but this seems to allow the print job to get to the print queue, even though abortdoc returns 1.

Any suggestions to what is going wrong?
0
Comment
Question by:PeteMulford
  • 2
3 Comments
 
LVL 3

Expert Comment

by:Mikeh926
ID: 16886192
It sounds like Excel just can't handle the NULL returned from CreateDC. You really need to not change any return codes from the API so that applications think that everything is ok.

Can I suggest that you hook EndDoc()? Return a value that indicates success to the application, but if you want to prevent printing call AbortDoc() from inside your hook.

Mike.
0
 

Author Comment

by:PeteMulford
ID: 16893176
so allow the startdoc, startpage stuff to be sent, but when the enddoc is sent send an abortdoc as well?
0
 
LVL 3

Accepted Solution

by:
Mikeh926 earned 500 total points
ID: 16893196
Yes, allow the app to think that it's printed.

In your EndDoc() hook, call AbortDoc() and do not call the original EndDoc(). Instead just return the code for success to the app. The app will think it's printed, so no error messages will be displayed, but you can abort the print job.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now