Duplex and DeviceCapabilities

C

Carolin

Hi All

Word 2003, XP
Networked printers with local drivers.

I'm trying to query a printer to establish if duplex is available.
Everything I've researched points me in the direction of DeviceCapabilities.
However, I can't get it to work. I've included two calls for comparison.
The iBins call is working and correctly returns a value dependent on the
printer provided. The iDuplex call returns -1 which indicates a failed call.
Any assistance is greatly appreciated.

Private Const DC_BINS = 6
Private Const DM_DUPLEX = &H1000
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
ByVal dev As Long) As Long

iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
DC_BINS, ByVal vbNullString, 0)

iDuplex = DeviceCapabilities(sCurrentPrinter, sPort, _
DM_DUPLEX, ByVal vbNullString, 0)
 
J

Jonathan West

Carolin said:
Hi All

Word 2003, XP
Networked printers with local drivers.

I'm trying to query a printer to establish if duplex is available.
Everything I've researched points me in the direction of
DeviceCapabilities.
However, I can't get it to work. I've included two calls for comparison.
The iBins call is working and correctly returns a value dependent on the
printer provided. The iDuplex call returns -1 which indicates a failed
call.
Any assistance is greatly appreciated.

Private Const DC_BINS = 6
Private Const DM_DUPLEX = &H1000
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
ByVal dev As Long) As Long

iBins = DeviceCapabilities(sCurrentPrinter, sPort, _
DC_BINS, ByVal vbNullString, 0)

iDuplex = DeviceCapabilities(sCurrentPrinter, sPort, _
DM_DUPLEX, ByVal vbNullString, 0)

Controlling the Printer from Word VBA
Part 2: Using VBA to control Duplex, Color Mode and Print Quality
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=116

As far as I can remember, the only way to know if the printer has duplex
capability is to to set the printer to duplex, and then read the duplex
setting back and see if it has stuck.
 
C

Carolin

Hi Jonathan

Unfortunately this didn't work. My test printer was not capable of duplex
printing. I set it to duplex and then read the property back. It returned a
value of 2, indicating it was set to duplex. When I looked at the properties
of the printer, it was set to single sided and a message was displayed that
advised me that it was switched to single. I OK'd the message and the
properties appeared to be OK. I re-ran my code to return the property value
(I did not reset it to duplex merely read back the value). It was still
returning 2. The properties dialog again displayed the message.

At least if an error was returned when setting duplex I could trap it. But
it doesn't. Very frustrating.
 
J

Jonathan West

Carolin said:
Hi Jonathan

Unfortunately this didn't work. My test printer was not capable of duplex
printing. I set it to duplex and then read the property back. It
returned a
value of 2, indicating it was set to duplex. When I looked at the
properties
of the printer, it was set to single sided and a message was displayed
that
advised me that it was switched to single. I OK'd the message and the
properties appeared to be OK. I re-ran my code to return the property
value
(I did not reset it to duplex merely read back the value). It was still
returning 2. The properties dialog again displayed the message.

At least if an error was returned when setting duplex I could trap it.
But
it doesn't. Very frustrating.

Unfortunately, if the printer driver lies to you, there isn't much you can
do about it.
 
C

Carolin

Jonathan, I've had success!!!!

By setting the Duplex constant to 7 rather than &H1000 I was able to return
the duplex capability. I haven't tested that the new constant setting will
work with the property calls, but I'm happy to set two constants if I have to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top