WIA Minidriver
Applications see Windows Image Acquisition (WIA) devices as a hierarchical tree of IWiaItem or IWiaItem2 objects with the root item representing the device itself. WIA devices may be used concurrently by more than one application. It is therefore necessary that each application's view of an IWiaItem or IWiaItem2 object be independent of another application's views. This is accomplished by having two different item objects. The driver creates the driver item tree of IWiaDrvItem Interface objects, also called driver items, using the WIA driver services methods. These are global objects that the driver uses to represent each driver's internal items. When an application creates an IWiaItem or IWiaItem2 object (also called an application item), this object is linked to the driver's corresponding IWiaDrvItem Interface in the driver item tree. A reference count is maintained on the IWiaDrvItem Interface object subject to the following rules:
- When a driver adds an IWiaDrvItem Interface object to the driver item tree, the IWiaDrvItem Interface object's reference count is incremented. This typically takes place during IWiaMiniDrv::drvInitializeWia or when a WIA_CMD_SYNCHRONIZE command is processed.
- When a driver removes an IWiaDrvItem Interface object from the driver item tree, the IWiaDrvItem Interface object's reference count is decremented and the IWiaDrvItem Interface object is marked so that it can't access the device again. This typically takes place when a device is disconnected or an item is deleted. Applications are still able to read properties from an IWiaItem or IWiaItem2 object even when the corresponding IWiaDrvItem Interface object has been removed from the driver item tree.
- When an IWiaItem or IWiaItem2 object is created it is linked to a corresponding IWiaDrvItem Interface object. The reference count of the IWiaDrvItem Interface object is incremented.
- When an IWiaItem or IWiaItem2 object is released, the link to its corresponding IWiaDrvItem Interface object is severed and the IWiaDrvItem Interface object's reference count is decremented.
- If an IWiaDrvItem Interface object's reference count goes to zero, the IWiaDrvItem Interface object is deleted. This applies to all IWiaDrvItem Interface objects including the root item. An IWiaDrvItem Interface object's reference count only goes to zero when no application items reference it and it is no longer linked to the driver item tree.
Using this reference counting scheme, many IWiaItem or IWiaItem2 objects may link to one IWiaDrvItem Interface without interference. Because each IWiaItem or IWiaItem2 contains its own property storage, an application can continue to read item properties even after an item has been deleted, but no operation that requires access to the device will succeed. Because item properties are stored in the IWiaItem or IWiaItem2 object, the driver must set the IWiaItem or IWiaItem2 object's properties to the device before a data transfer.