为了完成CE作业又来看CE下的驱动程序设计了,后悔上那堂课时没认真听......
还是先把知识复习一下:
Audio Drivers l
Battery Drivers l
Block Drivers l
Bluetooth HCI Transport Driver l
Direct3D Device Driver Interface l
DirectDraw Display Drivers l
Display Drivers l
DVD-Video Renderer l
IEEE 1394 Drivers l
Keyboard Drivers l
Notification LED Drivers l
Parallel Port Drivers l
PC Card Drivers l
Printer Drivers l
Serial Port Drivers l
Smart Card Drivers l
Stream Interface Drivers l
Touch Screen Drivers l
USB Drivers
驱动的装载过程:
1 大部分的驱动都是由系统启动时的设备管理进程(Device.exe)来完成装载的。
2 而一些Buit-in驱动由GWES.exe来装载。这些驱动包括显示驱动(DDI.dll),键盘驱动和触摸屏(鼠标)驱动
3 Device.exe会查看注册表里的[HKEY_LOCAL_MACHINE]\Drivers中一个被称为RootKey的字符串,通常是Builtin。这个RootKey里的驱动列表就是设备管理器必须初始化的。
[帖图1]
4 装载驱动的DLL, 为它创建一个ActiveKey(在[HKEY_LOCAL_MACHINE\Drivers\Active 下),并将这个DLL作为设备驱动注册到系统中。
3.[帖图2]
5 也可以由应用程序来手工装载驱动,如ActiveDeviceEx函数;另一个老的装载驱动的方法是用:RegisterDevice和 DeregisterDevice。
Stream Interface
一个流式接口驱动是指一个驱动把流式接口函数暴露出来,而不考虑驱动所控制的设备类型。典型的流式接口驱动:文件系统驱动(iostream,fstream),COM,LPT。。。。。
直接使用win32文件系统API:
hSer = CreateFile(TEXT(“COM1:”), GENERIC_READ, 0, NULL, OPEN_EXSITING, 0, NULL);
rc = ReadFile(hSer, &ch, 1, &cBytes, NULL);
TransmitCommChar(hSer, ‘a’);
CloseHandle(hSer);
创建一个流式驱动的过程:
1 写一个DLL,把流式接口的函数都expose出来
2 创建设备驱动
3 配置注册表
XXX_Close
Closes the device context identified by hOpenContext.
XXX_Deinit Called by the Device Manager to de-initialize a device.
XXX_Init Called by the Device Manager to initialize a device.
XXX_IOControl Sends a command to a device.
XXX_Open Opens a device for reading, writing, or both. An application indirectly invokes this function when it calls
CreateFile to open special device file names.
XXX_PowerDown Ends power to the device. It is useful only with devices that can be shut off under software control.
XXX_PowerUp Restores power to a device.
XXX_Read Reads data from the device identified by the open context.
XXX_Seek Moves the data pointer in the device.
XXX_Write
Writes data to the device.
注册表配置:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Sample]
"Dll" = "mydriver.Dll"
"Prefix" = "DEM"
"Index" = dword:1
"Order" = dword:0
"FriendlyName" = "Demo Driver"
"Ioctl" = dword:0
CE下的服务
在CE4.0之前是没有服务可用的,4.0之后服务管理被加入进来了。
一个CE服务也是一个DLL,结构和一个流式驱动程序的差不多:有3字符前缀,有10个进入口函数
本文地址:http://com.8s8s.com/it/it33079.htm