设备驱动程序未调用Xxx_Init [英] Device Driver not calling Xxx_Init

查看:56
本文介绍了设备驱动程序未调用Xxx_Init的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始进行驱动程序开发,并试图在启动时通过操作系统初始化设备驱动程序.该驱动程序适用于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"))));返回dwResult;}//结束MYD_Init 

将调用DLLEntry函数:

  BOOL DllEntry(保留hANDLE hDllHandle,DWORD dwReason,LPVOID){开关(dwReason){情况DLL_PROCESS_ATTACH:RETAILMSG(TRUE,(TEXT("MyDriver-Process Attached \ n")));DEBUGMSG(TRUE,(TEXT("MyDriver-Process Attached \ n")));休息;情况DLL_PROCESS_DETACH:RETAILMSG(TRUE,(TEXT("MyDriver-Process Detached \ n")));DEBUGMSG(TRUE,(TEXT("MyDriver-Process Detached \ n")));休息;.......默认:休息;}//结束开关返回TRUE;}//结束DllEntry 

这是串行端口日志中的几行:

  FMD_Init:为引导加载程序/运行时映像保留的块:3124I2C驱动程序:开始初始化MyDriver-已附加进程MyDriver-已分离进程打开设备块的时钟(在OTG_CTRL中)2589 CUSBFN :: IsConfigurationSupportable2593 CUSBFN :: IsEndpointSupportable2595 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]下列出的驱动程序调用这些驱动程序,还是必须手动调用它们?

再次感谢您可以提供的任何见解!

以下是易于理解的注册表设置:

  [HKEY_LOCAL_MACHINE \ Drivers \ BuiltIn \ MyDriver]前缀" ="MYD""Dll" ="myDriver.dll"索引" = dword:1标志" = dword:0 

修改3:

这是尝试通过应用程序打开驱动程序后的输出:

  USBFN:dwDeviceStatus:0x11,m_f已附加:已附加USBFN:dwDeviceStatus:0x1,m_f附加:附加MyDriver-附加过程MyDriver-流程分离COM_打开COM_打开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)测试驱动程序MyDriver-附加过程MyDriver-流程分离经过驾驶员测试 

第3行和第4行是系统引导期间的加载尝试.运行加载驱动程序的应用程序时,将输出最后四行."Testing Driver"和"Driver Tested"分别放置在应用程序的开头和结尾.

转储输出

  myDriver.dll文件的转储档案类型:DLL本节包含myDriver.dll的以下导出00000000特征501012DA时间日期戳2012年7月25日星期三10:38:020.00版本1个序数基数9种功能9个名字顺序提示RVA名称1 0 000013D4 DllEntry = DllEntry2 1 00001348 MYD_Close = MYD_Close3 2 0000130C MYD_Deinit = MYD_Deinit4 3 000013B8 MYD_IOControl = MYD_IOControl5 4 000012B8 MYD_Init = MYD_Init6 5 00001328 MYD_开= MYD_开7 6 00001364 MYD_Read = MYD_Read8 7 0000139C MYD_Seek = MYD_Seek9 8 00001380 MYD_Write = MYD_Write概括1000个数据1000 .pdata1000 .reloc1000 .text 

加载驱动程序后,将调用

解决方案

Xxx_Init .可以通过手动调用ActivateDevice来加载它,也可以通过在 [HKLM \ Drivers \ BuiltIn] 中设置适当的注册表设置使它由DeviceManager自动加载(向我们显示您正在使用的键).确保在 DllEntry 之后调用

Xxx_Init ,因为在操作系统加载DLL时会调用 DllEntry ,该操作必须在设备管理器可以加载它.

在所有这些操作发生之后,

CreateFile 会在驱动程序中调用 Xxx_Open 方法.

所以事件的顺序是:

  1. 操作系统加载DLL,并调用 DllEntry
  2. 设备管理器通过调用 Xxx_Init
  3. 加载驱动程序(手动或自动).
  4. 应用程序通过调用 CreateFile 打开驱动程序,这使设备管理器调用 Xxx_Open

某些电源管理组件可能会降到2.5,但它们是可选的,可能与您遇到的问题无关.

通常,在首次测试驱动程序启动时,我将从测试应用程序显式调用 ActivateDevice / DeactivateDevice .它使您可以替换驱动程序DLL,而不必每次都重新引导系统.

所以给您的问题是:

  1. 如果您从应用程序手动调用ActivateDevice,会发生什么情况?
  2. 您目前正在使用哪些注册表项来尝试让设备管理器加载驱动程序?

I am just starting out with driver development, and am trying to initialize a device driver through the operating system on start up. The driver is for Windows Embedded CE 6.0.

I have been attempting to have my device send a message through a serial port to my PC whenever it gets initialized.

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

The DLLEntry function is gets called:

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

And here are a few lines from the serial port log:

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

Line three shows that the driver gets loaded (I think), but MYD_Init is not called afterward. I'm not sure what I am missing. Maybe a missing reference from another file. My .def file includes the MYD_Init under EXPORTS. The .reg key is within the BuiltIn path: [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\MyDriver]. Not sure if there are any others.

I guess my real question is what are possible things I am missing/forgetting to get the MYD_Init function to get called?

Thanks for any help you guys can provide to help me get this work!

Edit:

I have realized that the CreateFile function is never called and feel this is the reason for my problem. What are some steps that I could take to figure out where this function should be placed so that MYD_Init is not called before DllEntry?

Or maybe the ActivateDevice/ActiveDeviceEx functions? Does the OS automatically call these for the drivers listed under [HKEY_LOCAL_MACHINE\Drivers\BuiltIn], or do they have to be called manually?

Thanks again for any insight that can be provided!

Edit 2:

Here are the registry settings easily readable:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\MyDriver]
    "Prefix"="MYD"
    "Dll"="myDriver.dll"
    "Index"=dword:1
    "Flags"=dword:0

Edit 3:

This is the output after trying to open the driver through an application:

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

Line 3 and 4 is the Load attempt during system boot. The last four lines are output when the application to load the driver is run. "Testing Driver" and "Driver Tested" were placed at the beginning and end of the application.

Edit 4: Dumpbin Output

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

解决方案

Xxx_Init will be called when the driver is loaded. It might be loaded by calling ActivateDevice manually, or by having it automatically loaded by DeviceManager by setting the proper registry settings in [HKLM\Drivers\BuiltIn] (show us what keys you are using).

Xxx_Init is guaranteed to be called after DllEntry because DllEntry gets called when the DLL is loaded by the OS, which has to occur before Device Manager can load it.

CreateFile calls the Xxx_Open method in the driver, which is after all of these actions occur.

So the order of events is:

  1. OS loads the DLL, calling DllEntry
  2. Device Manager loads the driver (either manually or automatic), calling Xxx_Init
  3. App opens the driver by calling CreateFile, which makes Device Manager call Xxx_Open

There are possibly some power management pieces that can fall at 2.5 on the list, but they are optional and likely unrelated to the issue you're seeing.

Typpically I'll use an explicit call to ActivateDevice/DeactivateDevice from a test app when first testing out driver bring-up. It lets you replace the driver DLL without having to reboot the system every time.

So the questions to you are:

  1. If you manually call ActivateDevice from an app, what happens?
  2. What are the registry keys you're currently using to try to get device manager to load the driver?

这篇关于设备驱动程序未调用Xxx_Init的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆