Driver Naming Conventions
For an application to use a stream driver through the file system, the stream driver must be presented as a file resource so that the application can specify the device file in a CreateFile call to get a handle to the device. Having obtained the handle, the application can then use ReadFile or WriteFile to perform I/O operations, which Device Manager translates into corresponding calls to stream interface functions to perform the desired read and write actions. For Windows Embedded CE 6.0 to recognize stream device resources and redirect file I/O operations to the appropriate stream drive, stream drivers must follow a special naming convention that distinguishes these resources from ordinary files.
Windows Embedded CE 6.0 supports the following naming conventions for stream drivers:
¦ Legacy names The classical naming convention for stream drivers consists of three upper case letters, a digit, and a colon. The format is XXX[0-9]:, where XXX stands for the three-letter driver name and [0-9] is the index of the driver as specified in the driver's registry settings (see Lesson 3, 'Configuring and Loading a Driver'). Because the driver index has only one digit, legacy names only support up to ten instances of a stream driver. The first instance corresponds to index 1, the ninth instance uses index 9, and the tenth instance refers to index 0. For example, CreateFile(L'COM1:'...) accesses the stream driver for the first serial port by using the legacy name COM1:.
The legacy naming convention does not support more than ten instances per stream driver.
¦ Device names To access a stream driver with an index of ten or higher, you can use the device name instead of the legacy name. The device name conforms to the format $deviceXXX [index], where $device is a namespace that indicates that this is a device name,
Although legacy names and device names differ in format and supported range of driver instances, CreateFile returns the same handle with access to the same stream driver in both cases.
¦ Bus name Stream drivers for devices on a bus, such as Personal Computer Memory Card International Association (PCMCIA) or Universal Serial Bus (USB), correspond to bus names that the relevant bus driver passes to Device Manager when enumerating the drivers available on the bus. Bus names relate to the underlying bus structure. The general format is $busBUSNAME_[bus number]_[device number]_ [function number], where $bus is a namespace that indicates that this is a bus name,
Bus names are primarily used to obtain handles for unloading and reloading bus drivers and for power management, but not for data read and write operations.
Stream Interface API
For Device Manager to load and manage a stream driver successfully, the stream driver must export a common interface, generally referred to as the stream interface. The stream interface consists of 12 functions to initialize and open the device, read and write data, power up or down the device, and close and de-initialize the device, as summarized in Table 6-1.
Table 6-1 Stream interface functions
Function Name | Description |
---|---|
XXX_Init | Device Manager calls this function to load a driver during the boot process or in answer to calls to ActivateDeviceEx in order to initialize the hardware and any memory structures used by the device. |
XXX_PreDeinit | Device Manager calls this function before calling XXX_Deinit to give the driver a chance to wake sleeping threads and invalidate open handles in order to accelerate the de-initialization process. Applications do not call this function. |
XXX_Deinit | Device Manager calls this function to de-initialize and deallocate memory structures and other resources in response to a DeActivateDevice call after deactivating and unloading a driver. |
XXX_Open | Device Manager calls this function when an application requests access to the device by calling CreateFile for reading, writing, or both. |
XXX_PreClose | Device Manager calls this function to give the driver a chance to invalidate handles and wake sleeping threads in order to accelerate the unloading process. Applications do not call this function. |
XXX_Close | Device Manager calls this function when an application closes an open instance of the driver, such as by calling the CloseHandle function. The stream driver must de-allocate all memory and |