Google Answers Logo
View Question
 
Q: litmus test to determine printing capability on a windows application ( Answered 4 out of 5 stars,   0 Comments )
Question  
Subject: litmus test to determine printing capability on a windows application
Category: Computers > Programming
Asked by: whitney-ga
List Price: $25.00
Posted: 13 Nov 2002 15:52 PST
Expires: 13 Dec 2002 15:52 PST
Question ID: 107219
how can i programatically in C administer a litmus test for whether a
particular windows process has been developed to use a local or remote
printer?  for example, applications like windows media player or
instant messenger generally have no business using a printer whereas a
word processor or internet browser would have components to access the
printer.

Request for Question Clarification by spot_tippybuttons-ga on 14 Nov 2002 05:40 PST
Could you help me better understand what you are looking for? Do you
mean "How do I tell, programmatically, if an application has printer
support compiled into it?" or do you mean something else, such as "How
do I tell, programmatically, if an application *should* (or should
not) be accessing the printer, regardless of if it is able to?"
 
Thank you.

Clarification of Question by whitney-ga on 14 Nov 2002 07:47 PST
the first one you mentioned, that is, "does an application have
printer support compiled into it?"  thanks.
Answer  
Subject: Re: litmus test to determine printing capability on a windows application
Answered By: spot_tippybuttons-ga on 14 Nov 2002 11:11 PST
Rated:4 out of 5 stars
 
Because most applications do not access the printer hardware directly
and instead use the Windows API to perform printer-related tasks, the
easiest way to determine programmatically if an application has
printer support is to check the applications import table for
printer-related API calls. The most obvious function to check for is
StartDoc, which is required for basic printing. StartDoc is exported
by gdi32.dll as StartDocA for standard applications and as StartDocW
for unicode applications.

Because many applications store their printer-related code in separate
DLLs you will need to write your own dependency walker in order to
locate all of the imports for a given application.

Writing a dependency walker is a fairly straightforward task. In
short, you examine the import tables of the application in question
and determine what other processes are linked. You then examine the
import tables of all of the processes you discovered in the first
import table. You do this recursively until you have discovered the
dependencies of all of the processes, or you have reached whatever
recursion depth you feel comfortable quitting at.

Parsing an executable's import table is a bit tricky, but fortunately
there are a fair number of source code examples available. The MSDN
provides a very thorough, easy to read example named YAHU that
supports practically every executable format you are likely to ever
encounter. (http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarwbgen/html/msdn_exeform.asp)

The only limitation with this method is that you may occasionally get
"false positives" from a few types of applications. For example,
applications that embed Internet Explorer as a control will appear to
be able to print, because obviously Internet Explorer can. Truth be
told, functionally there is no reason why these applications could not
print; they simply do not present the option to the user. I am not
sure that there is a way to separate out these applications
programmatically with *any* method as, again, technically speaking
these apps could print if they really wanted to.

If you would like to manually review the import tables for the
applications you are thinking of processing programmatically to see if
this method will work for you, you can do so with a free application
by Steve Miller named Dependency Walker.
(http://www.dependencywalker.com/)

I hope this answers your question. If you need any further information
or specific details, do not hesitate to ask.

Good luck with your project!

Spot


"StartDoc", MSDN Library
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_95sz.asp

Extending Apihijack
http://www.codeguru.com/mfc/comments/28299.shtml

Wingdi.h
Microsoft VisualStudio Windows Header File

"YAHU, or Yet Another Header Utility", MSDN Library
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarwbgen/html/msdn_exeform.asp

Dependency Walker
http://www.dependencywalker.com/

Search Strategy:
StartDoc import
://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&q=StartDoc+import

executable header utility import address source code
://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&q=executable+header+utility+import+address+source+code

Request for Answer Clarification by whitney-ga on 15 Nov 2002 08:15 PST
hi,

everything looks great, but i've run YAHU and it is not obvious to me
where it is exposing the import table parsing functionality.  could
you point me to either the code or directions on how to bring up that
info?

Request for Answer Clarification by whitney-ga on 15 Nov 2002 10:07 PST
never mind, i found the source to matt pietrek's depends.exe:
http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0297/hood/hood0297.htm

thanks!

Clarification of Answer by spot_tippybuttons-ga on 16 Nov 2002 01:30 PST
Cool! I'm glad you found it.

Just in case you were still interested in YAHU, the source file most
relevant to what you want to do is peview.cpp. In particular, you
should review peview.cpp, line 327, CPEView::DumpImportsSection. This
function dumps the import section for binaries that are in portable
executable format.

Have a great day,

Spot
whitney-ga rated this answer:4 out of 5 stars
well done.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy