none
How often DllMain (Demo Stream Driver) gets called during Boot ? RRS feed

  • Question

  • I built a Demo Stream Driver with OutputDebugString in DllMain.

    I can see a lot of calls (DllMain : DLL_THREAD_ATTACH/DLL_THREAD_DETACH) during boot - why ?

    Thursday, October 28, 2010 3:22 PM

All replies

  • Device drivers run inside a host process - NK.exe in Windows Embedded CE 6.0, or Device.exe in Windows CE 5.0 and earlier versions.  As a result, your driver DLL's DllMain function may be notified with DLL_THREAD_ATTACH or DLL_THREAD_DETACH whenever any new thread is created or terminated within that process.  Device drivers that don't require any thread-specific data should call DisableThreadLibraryCalls while processing DLL_PROCESS_ATTACH in order to disable DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications.


    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    • Proposed as answer by Michael Koster Friday, October 29, 2010 6:04 AM
    Thursday, October 28, 2010 4:35 PM
  • Thank you !

    Friday, October 29, 2010 6:58 AM
  • Hello,

    I have a doubt...are you talking about kernel mode drivers (in WinCE 6.0) running in NK.exe ? If I create a user mode driver, it runs in a host process udevice.exe. in this case I have only one DLL_THREAD_ATTACH (at creation of main thread). I can have multiple DLL_THREAD_ATTACH if I use the same host process udevice.exe to hosting more then one user mode driver..is it right ?

    In Win CE 5 I agree with you because alla drivers are executed inside device.exe that runs in user space.

    Paolo.

    Friday, October 29, 2010 7:27 AM
  • Yes, regarding CE 6.0 drivers, I was referring specifically to kernel mode drivers loading into NK.exe, as this is the default behavior unless the DEVFLAGS_LOAD_AS_USERPROC bit of the driver Flags value is set in the registry, in which case the driver is loaded as a user mode driver.  User mode drivers, as you noted, are hosted in a user-mode process (udevice.exe) and by default, each user mode driver gets its own udevice.exe process instance to run in unless you group multiple drivers together in a host process group using the registry keys and values ProcGroup_xxxx and ProcGroup.  However, even in the case of a user mode driver within a private udevice.exe host, you might still receive more than one DLL_THREAD_ATTACH/DLL_THREAD_DETACH notification if your driver creates additional threads. 


    Tom Gensel PTG Systems, LLC
    http://www.ptgsystems.com
    Friday, October 29, 2010 2:00 PM
  • Oh yes...but only if my driver creates additional threads otherwise it receives only one DLL_THREAD_ATTACH/DLL_THREAD_DETACH (main driver thread).

     

    Friday, October 29, 2010 2:05 PM