Printer Driver Setup and 64-bit Implications

Printer Driver Setup
and 64-bit Implications
Outline
Development
Understanding how to write a printer driver for 64-bit
systems
What’s different and what stays the same
Setup
Guidance for installing 64-bit drivers and “additional
drivers”
How to write an INF that installs 64-bit and 32-bit
versions of a printer driver
Goals
Understand how to develop printer drivers for 64bit Windows
Understand differences in printing in native mode
and across the Windows thunking layer
Create an INF that installs 32-bit and 64-bit print
drivers
Identify the changes made in Windows Server
2003 SP1 and Windows XP Professional 64-bit
Edition to facilitate cross-platform driver
installation
64-bit Printer Driver Development
Overview
The Windows Printing Subsystem is at feature parity
between x64 and x86 versions of the OS
64-bit drivers are required to print from 64-bit Windows
Special cases while printing across the thunking layer
Some 64-bit specific INF requirements
Line servers, such as File and Print servers are in the
sweet spot for the price/performance ratio of the x64
platform
Will be a key segment for the future
Driver availability is critical to adoption of 64-bit platform
Breadth of Applications
Supported 64-bit Architectures
Versatile
Mainstream
32-bit x86
64-bit x64
Most Scalable
64-bit IPF
Scalability
x64 Platform Options
x64 hardware supports multiple configurations
Extends hardware investment by allowing
gradual migration to 64-bit computing
32-bit Stack
Hybrid Stack
32-bit
64-bit Stack
x64
Applications
32-bit
Windows Edition
32-bit
x64
x64
Device Drivers
32-bit
x64
x64
x64
x64
x64
PC Hardware
x64
Print Driver Development for 64-bit
No special requirements to build printer driver
code for x64
If you can write a printer driver for 32-bit, you can
write one for 64-bit
Follow regular porting guidelines
Windows XP Professional x64 Edition ships with
thousands of printer drivers
Porting to x64 architecture was relatively
straightforward
Print system components are the same as 32-bit
Coding Guidelines
Use Windows 64- and 32-bit safe data types
Examine all pointer usage, especially pointer
arithmetic
Remove inline assembly code (use intrinsics or
native assembly code)
Use #if defined (__AMD64__) for x64 specific
code
No __x64__ definition
Use #if defined(__IA64__) for Itanium specific
code
Build environment for x64 is AMD64
Areas for Caution While Developing
64-bit Print Drivers
Location of binaries
System32 and Syswow64 directories
Use Dirids rather than full paths in infs
Thunking layer
There are some GDI printing callbacks which work
differently in the thunking case compared to the native
case
DrvDocumentEvent
Extended escapes
Printing Across the Thunking Layer
If you load/run a 32-bit application on the 64-bit platform
some calls need to be translated from 32-bit mode to
64-bit mode
This translation is called thunking
WOW64 is the main Windows 64-bit thunking layer
Runs Windows NT x86 binaries
No support for mixing of 32-bit and 64-bit code within a process
User/kernel transitions are thunked to account for structure
differences and transition between instruction sets
Only a few dlls are thunked: ntdll.dll, user.dll, gdi.dll are the main
ones
On 64-bit Windows, GDI is a 64-bit component
While printing from a 32-bit application, interactions with
GDI are managed by the WOW64 thunking layer
GDI:DrvDocumentEvent
Some printer drivers make GDI callbacks from a UI
module during printing
For example to add a watermark, to do some types of ICM profile
matching, to do certain types of run time job accounting
Typically made from DrvDocumentEvent
Not part of the original design intent of the API
This call is made across the thunking layer from
application space to driver space
GDI must marshall the state of any data across the thunking layer
in order to have the data available for the print driver.
Problem: the data is essentially unbounded
Extremely difficult (trending towards unachievable) to accurately
marshall all data
Extended Escapes
DrvDocumentEvent calls which use ExtEscapes
are supported
Enables the majority of call back scenarios
http://msdn.microsoft.com/library/default.asp?url=/librar
y/en-us/graphics/hh/graphics/drvrfnc_ffc39ed1-d1b84e3d-b0a3-515b90cd6c8f.xml.asp for details on the
available parameters
Other uses of DrvDocumentEvent callbacks are
not supported in the current release across the
thunking layer
Several thousand drivers have been tested
Very low numbers of functional problems found
Mitigations and Drawbacks
Mitigations
This entire problem set only affects printing from a 32bit app on 64-bit Windows, and within that space only
affects “advanced” printing features
It is possible to work around the limitations by
designing the driver differently
Use print processor
Application level watermarks
64-bit applications do not show these problems
Development of x64 applications will minimize the
impact of this limitation
Drawbacks
In some cases more than a simple driver recompile is
required to get the same printing experience
Value add applications may need to be ported to 64-bit
to ensure the same functionality is available
Installing 64-bit Printer Drivers
Introduction
We expect mixed 32-bit and 64-bit environments
for many years
Printing is unique among device classes
To support Point & Print, non-native platform printer drivers may
be loaded onto a system as “additional drivers”
The challenge:
How do I write an INF that loads an x64 driver on any platform?
How do I write an INF that installs an x86 driver on an x64
platform?
The answer:
Use INF decorations
What’s mandatory, what’s not
What works on what versions of Windows
64-bit Drivers
How to install x64 and x86 drivers
There are no setup differences between AMD64 and
Intel EM64T
The examples show how to install the x86 and
x64 version of a driver from one INF
Itanium isn’t covered in the examples in this
presentation but the logic Is the same
There is more Itanium-specific information in the Driver
Development Kit (DDK)
Some INF Terminology
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
Manufacturer
Section
Model Section
x64 = NTamd64
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme100PS]
CopyFiles = DriverFile.DLL
[SourceDisksFiles.amd64]
<location of driver files on media>
DDInstall Section
SourceDisksFiles
Section
INF Decorations are Required on x64
An x64 driver must use a decorated Model
section on the following platforms:
Windows Server 2003 SP1
Windows XP Professional x64 Edition
…and future versions of Windows
The x64 Editions of Windows will not recognize
drivers that are not decorated correctly
Decorations will be required for Itanium (ia64)
drivers on Longhorn
So - how do you write an INF that works on
Windows Server 2003 SP1/XP x64 and on earlier
versions of Windows?
Approach
Decorate the Model section to match the
processor architecture of the 64-bit driver that
you are installing
This will install the driver correctly on Windows 2003
SP1 (any platform), Windows XP Professional x64
Edition, and Longhorn
Also provide an undecorated Model section
This will install the x86 driver
It will install a driver correctly on earlier versions of
Windows
Use decorated SourceDisksFiles to point the
installer to the correct location of your binaries
Getting Started – 32-bit Driver
The INF Model section below installs an x86
driver on any version of Windows
[MANUFACTURER]
%Acme Corp.% = Acme
[Acme]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme100PS]
CopyFiles = Driver.DLL
…
Getting Started – x64 Driver
The INF Model section below loads an x64 driver on:
Windows Server 2003 SP1 (any processor architecture)
Windows XP Professional x64 Edition
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme100PS]
CopyFiles = Driver.DLL
…
Supporting More Versions of Windows
This also installs the x64 driver on versions of
Windows prior to Windows 2003 SP1 and XP x64
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
But: also
matches x86
drivers!
[Acme]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
…
Solution with Three Example Usages
The following slides show a complete example
Separate install scenarios are presented,
all using the same INF
Complete Example
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
[Acme]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme100PS]
CopyFiles = MyDriverFile.dll, ...
[SourceDisksNames.x86]
1= %Location%,,,
[SourceDisksFiles.x86]
MyDriverFile.dll = 1,\i386
[SourceDisksNames.amd64]
1= %Location%,,,
[SourceDisksFiles.amd64]
MyDriverFile.dll = 1,\amd64
Install an x64 Driver on Server 2003 SP1/XP x64
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
[Acme]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme100PS]
CopyFiles = MyDriverFile.dll, ...
[SourceDisksNames.x86]
1= %Location%,,,
[SourceDisksFiles.x86]
MyDriverFile.dll = 1,\i386
[SourceDisksNames.amd64]
1= %Location%,,,
[SourceDisksFiles.amd64]
MyDriverFile.dll = 1,\amd64
Installs an x64 driver
on XP x64, and
Windows Server 2003
SP1 (any platform, so
may be additional
driver)
Install an x86 Driver on Server 2003 SP1/XP x64
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
[Acme]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme100PS]
CopyFiles = MyDriverFile.dll, ...
[SourceDisksNames.x86]
1= %Location%,,,
[SourceDisksFiles.x86]
MyDriverFile.dll = 1,\i386
[SourceDisksNames.amd64]
1= %Location%,,,
[SourceDisksFiles.amd64]
MyDriverFile.dll = 1,\amd64
This section is used
when the user installs
an x86 driver on XP
x64, or Server 2003
SP1 (any platform)
Install an x64 Driver on XP SP2
[MANUFACTURER]
%Acme Corp.% = Acme, NTamd64
[Acme]
%Acme Model% = Acme100PS, <hardware IDs>
[Acme.NTamd64]
%Acme Model% = Acme100PS, <hardware IDs>
This section is also
used to install the x64
driver on XP SP2 as
an additional driver
[Acme100PS]
CopyFiles = MyDriverFile.dll, ...
[SourceDisksNames.x86]
1= %Location%,,,
[SourceDisksFiles.x86]
MyDriverFile.dll = 1,\i386
[SourceDisksNames.amd64]
1= %Location%,,,
[SourceDisksFiles.amd64]
MyDriverFile.dll = 1,\amd64
SourceDisksFiles
locates the correct
driver files
User Experience Changes
To make the Driver installation experience more
predictable and consistent, we made some
changes for Server 2003 SP1 and XP x64 Edition
We changed the path through the Add Printer
Driver Wizard so that the user can select the
platform before the printer model
We improved the way in which Unidrv-based
printer drivers are installed
Add Printer Driver Wizard
Install an x86 driver on
an x64 Server
Use Have Disk to
locate non-native
drivers
Unidrv
Problem: when installing an x64 Unidrv-based
driver on an x86 print server as an additional
driver, how do we locate the x64 version of
Unidrv?
Old solution: use remote admin from machine
with matching architecture. But:
This requires that you have x64 installed locally
No version predictability
New solution: Windows prompts for correct
Windows media
Gives the user control
If it’s on a network share this is transparent to the user
Summary of Printer Driver Installation Section
INF Model section decorations are now required
for x64 drivers
They are supported on Itanium and will be required so
decorate Itanium drivers too
Undecorated model sections are used to install
x86 drivers, and also for x64 drivers on earlier
versions of Windows
So use decorations on the SourceDisksFiles section to
distinguish between different driver platforms
There are some tweaks in Windows Server 2003
SP1 and XP x64 to improve the overall user
experience
Call to Action
Use Model section decorations in your INF to describe the
target platform for your driver
Assess market needs for x64 drivers for your devices
Now - CAD / DCC / CAM
Future
Photo / enthusiast
Print servers / enterprise deployment
Examine driver and application code for use of
GDI:DrvDocumentEvent
Plan for workarounds if required
Use the Designed for Windows Logo Program to certify
64-bit drivers
Additional Resources
Community Sites
http://www.microsoft.com/communities/default.mspx
MSDN Developer Community Chats:
Printer Drivers -- Ask the Experts Online
http://msdn.microsoft.com/chats/windows/windows_102402.asp
Windows Drivers: Printer Drivers
http://msdn.microsoft.com/chats/windows/windows_101602.asp
Windows Drivers Printing and Networking
http://msdn.microsoft.com/chats/windows/windows_022002.asp
Web resources
WS-Devices Profile:
http://msdn.microsoft.com/webservices/understanding/specs/default.aspx
?pull=/library/en-us/dnglobspec/html/devprof.asp
Printer Working Group
http://www.pwg.org
WHDC Printing home page:
http://www.microsoft.com/whdc/device/print/default.mspx
WHDC Still Imaging / WIA home page:
http://www.microsoft.com/whdc/device/stillimage/default.mspx
Additional Resources
E-mail
For developer print questions: prninfo @ microsoft.com
For developer scan questions: wiainfo @ microsoft.com
For developer color questions: mscolor @ microsoft.com
DDK
Especially important: read the section entitled “How to Use
Decorations in INF Files for Printer Drivers” which was recently
updated. This is currently on MSDN.
White papers:
On www.microsoft.com/whdc: Printer Driver Setup: 64-bit Drivers and
Platforms
For print administrators
Information on planning for mixed 32-bit/64-bit environments will be
published on www.microsoft.com/printserver
© 2005 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.