Solved

Intercepting print jobs by hooking createDCW and createDCA

Posted on 2006-06-09
3
1,179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

25 Experts available now in Live!

Get 1:1 Help Now