我刚开始开发驱动程序,并试图在启动时通过操作系统初始化设备驱动程序。该驱动程序适用于 Windows Embedded CE 6.0。
我一直试图让我的设备在初始化时通过串行端口向我的 PC 发送消息。
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
DLLEntry 函数被调用:
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 键位于内置路径中:[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 行是系统引导期间的加载尝试。最后四行是在运行加载驱动程序的应用程序时输出的。“Testing Driver”和“Driver Tested”分别放在应用程序的开头和结尾。
编辑 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