Solved

Intercepting print jobs by hooking createDCW and createDCA

Posted on 2006-06-09
3
1,200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 …
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 Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

734 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