- UID
- 872238
|
我想很多WinCE的开发人员,尤其是刚入门并且做驱动开发的工程师,都曾碰到这样一个问题,要编写一个外围设备的驱动,拿最简单的GPIO驱动来说,编写驱动本身可能只花了一会儿功夫,可要把编译生成的DLL打包到先前做好的操作系统映像当中,最简单也得MakeImg一下,还要修改BIB文件、注册表文件,以让系统启动的时候就加载该驱动,所有工作都做完了,还得花几分钟下载整个操作系统到内存去运行,这也得要个好几分钟。能力强的人一次成功,不走回头路也就算了。 如果驱动编写得有问题,那又得改代码,重新编译,把刚刚所做的事情再做一遍。说出来不怕大家笑话,我刚开始做驱动时就这样,反反复复,半天下来,才调试好一个简单的驱动。而事实上很大一部分时间都浪费在重复操作上。这种调试驱动的方法实在效率太低了。想到Linux下面的驱动调试,多方便!直接INSMOD一下,应用程序就可以调用,出现问题就RMMOD,根本无须来回倒腾操作系统的映像文件。那么,WinCE下难道就没有这么简便的方法嘛?答案是肯定的。
闲话少说,进入正题。查找EVC的帮助,发现函数ActivateDevice()可用来加载驱动程序。而这个函数的使用是相当简单的。我就不多说了,贴上一段帮助最能说明问题。当然,你也可以用ActivateDeviceEx()。
HANDLE ActivateDevice (
LPCWSTR lpszDevKey,
DWORD dwClientInfo
);
Parameters
lpszDevKey
[in] Pointer to the registry path string of the device's driver key under HKEY_LOCAL_MACHINE. A driver key contains the DLL name, the device prefix, friendly name, and other device information.
dwClientInfo
[in] Data that will be stored in the device's Active key in the ClientInfo value. The registry path to the driver's Active key is passed in as the context parameter to the device's XXX_Init function. The value in dwClientInfo is stored in the registry before XXX_Init is called.
Return Values
On success, ActivateDevice returns a handle to the device that can be used in subsequent calls to DeactivateDevice.
Remarks
This function is superseded by ActivateDeviceEx.
ActivateDevice loads a device driver. ActivateDevice reads the registry key specified in lpszDevKey to get the DLL name, device prefix, index, and other values. Next it adds the device to the active device list in the registry branch HKEY_LOCAL_MACHINE\Drivers\Active, and stores the relevant values there. If no device index was specified in the key named in lpszDevKey, then it assigns a free index. Then it loads the device driver DLL in the process space of the Device Manager. Then it broadcasts a WM_DEVICECHANGE message for the new device and triggers a NOTIFICATION_EVENT_DEVICE_CHANGE event in the application notification system to notify applications of the presence of the new device.
”, |
|