我刚开始开发驱动程序,并试图在启动时通过操作系统初始化设备驱动程序。该驱动程序适用于Windows Embedded CE 6.0。
我一直试图让我的设备在初始化时通过串行端口向我的电脑发送消息。
DWORD MYD_Init(LPCTSTR pContext, LPCVOID lpvBusContext)
{
DWORD dwResult = 1;
RETAILMSG(TRUE, (TEXT("MyDriver: Initializing!\n")));
DEBUGMSG(TRUE, (TEXT("MyDriver: Initializing!\n")));
return dwResult;
} //end MYD_Init
DLLEEntry函数被调用:
BOOL DllEntry(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
RETAILMSG(TRUE, (TEXT("MyDriver - Process Attached\n")));
DEBUGMSG(TRUE, (TEXT("MyDriver - Process Attached\n")));
break;
case DLL_PROCESS_DETACH:
RETAILMSG(TRUE, (TEXT("MyDriver - Process Detached\n")));
DEBUGMSG(TRUE, (TEXT("MyDriver - Process Detached\n")));
break;
.......
default:
break;
} //end Switch
return TRUE;
} //end DllEntry
以下是串行端口日志中的几行:
FMD_Init: Blocks reserved for the bootloader/run-time image: 3124
I2C Driver: Intialization Started
MyDriver - Process AttachedMyDriver - Process DetachedTurn on clocks for Device block (in OTG_CTRL)
2589 CUSBFN::IsConfigurationSupportable
2593 CUSBFN::IsEndpointSupportable
2595 CUSBFN::IsEndpointSupportable
第三行显示驱动程序已加载(我认为),但之后不会调用MYD_Init。我不确定我错过了什么。可能是另一个文件中缺少引用。我的.def文件包括EXPORTS下的MYD_Init。.reg密钥位于BuiltIn路径中:[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\MyDriver]。不确定是否还有其他人。
我想我真正的问题是,我错过了/忘记了调用MYD_Init函数的可能内容是什么?
谢谢你们能提供的任何帮助来帮助我完成这项工作!
编辑:
我已经意识到CreateFile函数从未被调用,我觉得这就是我出现问题的原因。我可以采取哪些步骤来确定这个函数应该放在哪里,这样在DllEntry之前就不会调用MYD_Init了?
或者ActivateDevice/ActiveDeviceEx功能?操作系统会自动为[HKEY_LOCAL_MACHINE\drivers\BuiltIn]下列出的驱动程序调用这些吗?还是必须手动调用它们?
再次感谢您提供的任何见解!
编辑2:
以下是易于阅读的注册表设置:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\MyDriver]
"Prefix"="MYD"
"Dll"="myDriver.dll"
"Index"=dword:1
"Flags"=dword:0
编辑3:
这是尝试通过应用程序打开驱动程序后的输出:
USBFN: dwDeviceStatus: 0x11, m_fAttached: Attached
USBFN: dwDeviceStatus: 0x1, m_fAttached: Attached
MyDriver - Process Attached
MyDriver - Process Detached
COM_Open
COM_Open
IOCTL_SERIAL_SET_COMMTIMEOUTS (50,1,50,5,500)
IOCTL_SERIAL_SET_COMMTIMEOUTS (50,1,50,5,500)
IOCTL_SERIAL_SET_COMMTIMEOUTS (-1,0,0,2,500)
Testing Driver
MyDriver - Process Attached
MyDriver - Process Detached
Driver Tested
第3行和第4行是系统引导期间的加载尝试。最后四行是在加载驱动程序的应用程序运行时输出的。“测试驱动程序”和“经过测试的驱动程序”被放置在应用程序的开头和结尾。
编辑4:垃圾箱输出
Dump of file myDriver.dll
File Type: DLL
Section contains the following exports for myDriver.dll
00000000 characteristics
501012DA time date stamp Wed Jul 25 10:38:02 2012
0.00 version
1 ordinal base
9 number of functions
9 number of names
ordinal hint RVA name
1 0 000013D4 DllEntry = DllEntry
2 1 00001348 MYD_Close = MYD_Close
3 2 0000130C MYD_Deinit = MYD_Deinit
4 3 000013B8 MYD_IOControl = MYD_IOControl
5 4 000012B8 MYD_Init = MYD_Init
6 5 00001328 MYD_Open = MYD_Open
7 6 00001364 MYD_Read = MYD_Read
8 7 0000139C MYD_Seek = MYD_Seek
9 8 00001380 MYD_Write = MYD_Write
Summary
1000 .data
1000 .pdata
1000 .reloc
1000 .text