- Get printer duplex setting.
- Posted by Jim Lawless on March 2nd, 2004
Hello, all.
I'm trying to obtain the printer duplex setting with the code below.
All that I see is a "1" no matter what duplex settings I manually
enter via the Control Panel Printers applet under Windows 2000.
Is there a newer API that I need to use? ( ...or is my code in error?
....)
Ultimately, I'd like to be able to set the printer setting as well.
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <winspool.h>
main(int argc,char **argv) {
static char *pname;
HANDLE hPrinter;
PRINTER_DEFAULTS pd;
PRINTER_INFO_2 pinfo;
DEVMODE dm;
MSG msg;
unsigned char *yDevModeData;
int i;
pname=argv[1];
if(argc<2) {
printf("Syntax: duplex printer-name\n ( i.e. duplex
\\\\001fncps01\\FNT16W04 )\n");
exit(1);
}
memset(&pd,0,sizeof(pd));
pd.DesiredAccess=(STANDARD_RIGHTS_REQUIRED | PRINTER_ACCESS_USE );
i=OpenPrinter(pname,&hPrinter,&pd);
if(i==0) {
fprintf(stderr,"Can't find printer(1).");
exit(1);
}
if(hPrinter==0) {
fprintf(stderr,"Can't find printer(2).");
exit(1);
}
i=DocumentProperties(0,hPrinter,pname,0,0,0);
if(i<0) {
ClosePrinter(hPrinter);
fprintf(stderr,"Can't access printer properties.");
exit(1);
}
yDevModeData=(unsigned char *)malloc(i);
i=DocumentProperties(0,hPrinter,pname,(PDEVMODE)yD evModeData,0,DM_OUT_BUFFER);
if(i<0) {
ClosePrinter(hPrinter);
fprintf(stderr,"Error getting dev mode data.");
exit(1);
}
memcpy(&dm,yDevModeData,sizeof(dm));
printf("Duplex: %d\n",(int)dm.dmDuplex);
printf("Device Name:%s\n",dm.dmDeviceName);
ClosePrinter(hPrinter);
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Thanks in advance.
Jim Lawless
- Posted by Sten Westerback on March 2nd, 2004
"Jim Lawless" <jimbo@radiks.net> wrote in message
news:4044716b.567296@news.east.earthlink.net...
);
Why does it matter to your code if the USER has chosen to use
both sides of the paper? Not even MS Word care about that -- it
only let you separately mirror the margins and define different
headers/footers for odd and even pages and doesn't care if
printer happen to support duplex or not.
Anyway, unless you did change the default for the printer queue
then the DM returned by your DocumentProperties() would
contain the default for the queue... which is simplex.
Try adding | DM_IN_PROMPT to the last parameter or,
just set it yourself as you want it and then read it..
- Sten
- Posted by Norman Black on March 2nd, 2004
I use the following to find the duplex setting.
In the DEVMODE structure I first look at the dmFields for the duplex
flag and then look at the dmDuplex field based on that test. The
following code is Modula-2 but I think you should be able to follow it.
info.duplex := FALSE;
IF (DM_DUPLEX BAND mode^.dmFields) <> 0 THEN
info.duplex := mode^.dmDuplex <> DMDUP_SIMPLEX;
END;
--
Norman Black
Stony Brook Software
"Jim Lawless" <jimbo@radiks.net> wrote in message
news:4044716b.567296@news.east.earthlink.net...
FFER);
- Posted by Norman Black on March 2nd, 2004
Because if you take a document with an odd number of pages and print
multiple copies then the first page will end up on the back of the last
page. You will not get a blank page on the "back" of the last page. This
has been the case for years with MS products, and likely others. MS
claims this behavior is as it was designed to be. I have not tested this
in a long time since our documentation has gone online and we no longer
use MS word for this.
There are(were) many variables on this and it depends on exactly what
the driver and printer supports. For example does the printer, driver or
software do the multiple copy operation. These days in XP, with the MS
driver, the drivers are different. With the old Lexmark driver there
were TWO options to specify how many copies. One was a direct printer
command and the other was whatever Windows and/or the driver did with
it. Using the direct printer command with odd pages and duplex
everything worked fine. With the normal copies option in print dialogs
it did not.
So if your are printing duplex with multiple copies and an odd number of
pages then if you always print a blank page then your printouts will
always work regardless of what the driver and printer hardware supports,
or if it works "correctly". Otherwise you are at someone else's mercy.
That is why one might want to know if duplex is enabled.
--
Norman Black
Stony Brook Software
- Duplex B5 printer (Printers) by Duncan Clark
- setting duplex manualy on catalyst 2950 (Routers) by raptor
- How to make duplex setting the default (Printers) by Mike Kraley
- Setting WS-2950-24 to full duplex (Routers) by Guy DeStefano
- problems querying/setting speed/duplex on WS-C3550 via SNMP (Routers) by Bruce Campbell

