Solved

Intercepting print jobs by hooking createDCW and createDCA

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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