280 likes | 500 Views
Developing WIA Drivers Byron Changuion Developer Windows Imaging Group Microsoft Corporation. Preamble. What is this presentation about? Selected topics regarding development of WIA mini-drivers (“full” WIA drivers) This talk is not necessary for you, if your device is:
E N D
Developing WIA DriversByron ChanguionDeveloperWindows Imaging GroupMicrosoft Corporation
Preamble • What is this presentation about? • Selected topics regarding development of WIA mini-drivers (“full” WIA drivers) • This talk is not necessary for you, if your device is: • PTP camera or Mass Storage device • Class driver exists • Simple flatbed scanner • Can write “micro-driver” instead
Agenda • Overview of WIA Components • WIA Item Trees • Run-time behavior of WIA Drivers • Troubleshooting and Debugging • Hints and Tips • What can you do next?
WIA Component Architecture Process boundary TWAIN Application WIA Application Key COM Proxy Microsoft Component TWAIN Data Source Default UI Optional vendor UI IHV Component ISV Component STI Interface WIA / STI service USD USD User Mode Kernel Mode USB Driver 1394 Driver SCSI Driver Serial Driver
WIA Item TreesGeneral • Device (and any data) represented by “Items” • Two kinds of items • Driver items and Application items • Driver creates tree of Driver items • WIA Service will build copy of tree for applications (using Application items)
Root IWiaItem Application 1 First Child IWiaItem Second Child IWiaItem Root IWiaItem Application 2 First Child IWiaItem Second Child IWiaItem WIA Item TreesGeneral WIA Driver Root IWiaDrvItem First Child IWiaDrvItem Second Child IWiaDrvItem
WIA Item TreesGeneral • Each Application item has its own property stream • Service will call driver to set initial property values • Driver notified when Application reads/writes properties
WIA Item TreesItem Types • Informs applications how to treat an item • For example, WiaItemTypeAudio • Item types are not exclusive • For example, (WiaItemTypeFile | WiaItemTypeImage) • Driver specifies item type when it creates the item
WIA Item TreesAnnotations • Some data may be associated with other data • Example: Audio recording for a picture • WIA represents annotations with child-items • Items with annotations have special item type flags
Picture 1 Picture 1 (WiaItemTypeFile | WiaItemTypeImage) (WiaItemTypeFile | WiaItemTypeImage | WiaItemTypeHasAttachments) Audio Annotation for Picture 1 Audio Annotation for Picture 1 (WiaItemTypeFile | WiaItemTypeAudio) (WiaItemTypeFile | WiaItemTypeAudio) Picture 2 Picture 2 (WiaItemTypeFile | WiaItemTypeImage) (WiaItemTypeFile | WiaItemTypeImage) WIA Item TreesAnnotations: Example Data on Device WIA Item tree Representation
WIA Item TreesInteractions with Driver • Image data exposed through items • Characteristics exposed through properties, for example • Cameras • Picture width / height, Time picture was taken, and so on • Scanners • Set resolution, Set data type, and so on
Read Property X Current value for X drvReadItemProperties If needed, return new value for X Key Microsoft Component IHV Component ISV Component WIA Item TreesInteractions with Driver Application WIA updates property storage WIA Driver Reading Property Example
WIA Item TreesInteractions with Driver: Example • Walk through sample code
Return appropriateerror code Write Property X 1. drvValidateItemProperties 5. Driver returns error 4. Helper returns error 3. Driver calls generic property validation helper Key Microsoft Component IHV Component ISV Component WIA Item TreesInteractions with Driver Application WIA performs rollback by restoring property stream WIA 2. Driver updates dependant properties Driver Writing Invalid Property Example
Run-Time BehaviorUpdating the Driver Tree • Drivers may add and/or remove WIA items, for example • Take picture • Delete picture • Need to let applications know • Use WIA events, for example • WIA_EVENT_ITEM_CREATED • WIA_EVENT_ITEM_DELETED • WIA_EVENT_TREE_UPDATED
Run-Time Behavior Updating the Driver Tree: Example • Walk through sample code
Run-Time Behavior drvInitializeWia / drvUnitializeWia • Used to bracket application sessions • Similar to AddRef / Release • Can use to maintain session Reference Count • Multiple drvInitializeWia calls can be made before the equivalent drvUninitializeWia calls (i.e., can more than one active session)
Run-Time Behavior drvInitializeWia / drvUnitializeWia: Example • Walk through sample code
Run-Time Behavior drvNotifyPnPEvent • Called Asynchronously • Plug and Play • WIA_EVENT_DEVICE_CONNECTED • WIA_EVENT_DEVICE_DISCONNECTED • Power Management • WIA_EVENT_POWER_SUSPEND • WIA_EVENT_POWER_RESUME • I/O Cancellation • WIA_EVENT_CANCEL_IO
Run-Time Behavior drvNotifyPnPEvent: Example • Walk through sample code
Troubleshooting • WIA Service Log file • %windir%\wiadebug.log • Turn on Warnings and Errors: • [HKLM\System\CurrentControlSet\Control\ StillImage\Debug\wiaservc.dll] • “DebugFlags = 0x3” • Example snippet: wiasValidateItemProperties, invalid RANGE value for : (propID) Horizontal Start Position, value = 3000 Valid RANGE is: MIN = 0, MAX = 1274, STEP = 1
DebuggingOverview • Why use a debugger? • Driver faults (without debugger - service will catch and simply return “failed”) • Service faults (without debugger – service process is terminated) • When do you start the debugger? • Automatically on startup • Attach at run-time
Process boundary TWAIN Application WIA Application Key COM Proxy Microsoft Component Default UI Optional vendor UI TWAIN Data Source IHV Component ISV Component STI Interface WIA / STI service USD USD User Mode Kernel Mode USB Driver 1394 Driver SCSI Driver Serial Driver Hints And Tips • USD does not show U.I.! • Multiple instances of driver when using STI
Hints And Tips • IWiaMiniDrv portion of driver only initialized and/or used when application talks WIA • drvInitializeWia / drvUnitializeWia not used to indicate driver loading or unloading • Use WIA’s pre-defined Event GUIDs for Scan, Fax, and so on
What Can You Do Next • Reference the platform SDK/DDK • For more technical details about WIA driver development • http://www.microsoft.com/hwdev/wia • For information about WHQL testing • http://www.microsoft.com/hwtest • Send e-mail to • winimage@microsoft.com