Joesmith2002
驱动牛犊
驱动牛犊
  • 注册日期2002-06-14
  • 最后登录2002-06-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1123回复:0

Win 2000 Device Drivers Tutorial 4

楼主#
更多 发布于:2002-06-14 15:37
Device Objects and the Windows Namespace
In Windows NT and associates, Device Drivers are designed to help the Operating System present an interface between application and device. That interface makes the device look a file to the application. If the app wants to talk to the driver, it invokes CreateFile to open the communication, and then it uses ReadFile,  WriteFile, or DeviceIoControl to interchange data with the device. This communication is set up by associating a pathname in the Windows Object Namespace to each device being handled.

We will see in a moment that when the driver is initialized, its DriverEntry routine gets control. DriverEntry is the driver\'s initialization routine. One of the things that DriverEntry does is to create one Windows DeviceObject for each device under the control of that Device Driver. Each such DeviceObject represents its corresponding device.

Now, remember that Windows has a Namespace structure, where all names recognized by the system get an entry under a global hierarchy that starts at the \"\\\" root directory. The Windows File System itself is located under this Namespace hierarchy, but the Namespace includes many more entries besides the File System. DeviceObjects can be named, and when they are named, they get an entry in the Namespace. This makes the device name accessible to both applications and to the Operating System through the CreateFile API call.

You can look at the hierarchy with an \"Object View\" utility, there are many such available as Freeware on the Worldwide Web.  The Namespace will have many entries, organized as a tree rooted at \"\\\". One of the directories in that hierarchy is \\device, which contains every device visible by the system. When DriverEntry creates a DeviceObject named \"cdriver\", for example, an entry for that object will be created at \\device\\cdriver . However, this is not the name that is seen by the application: what the app really sees is a link to the \\device\\cdriver name. For example, the name \"C:\" is really a link into the \\device entry for drive C. This link is called the Dos Name of the object, as opposed to the native name under the \\device hierarchy which is known as the Nt Name. These links allow an application to access the devices using its Dos Name in a call to the CreateFile function.

So, the Driver must create two names for each DeviceObject: the NT Name under the \\device hierarchy, and the Dos Name that links to the NT Name. The Dos Name is created under the \\Dosdevices hierarchy, which is also known as the \\?? hierarchy. The Driver must also establish the link between the two. Once this is done, the application can issue a CreateFile call to connect to a device managed by the Driver.

Note also that Windows NT pervasively uses the 16-bit Unicode character set, not its older ASCII 8-bit counterpart. This is necessary to support languages and alphabets that have more than 256 characters or glyphs, for example, Far Eastern languages such as Chinese, Japanese or Korean. This means that DriverEntry must convert both the driver\'s NT Name and Dos Name to Unicode prior to creating the DeviceObject or establishing the Dos Name link to the NT Name. Check the listing further on in this document for details ! And don\'t forget to look up the DDK\'s on-line documentation for the API functions we call from DriverEntry

最新喜欢:

flyfoxflyfox
游客

返回顶部