Export (0) Print
Expand All

Best Practices for Maintainable Device Drivers (Windows CE 5.0)

Windows CE 5.0
Send Feedback

While developing a device driver, if feasible, write consistent, self-validating code, in a non-confusing manner.

The following list shows best practices for maintainability:

  • Define the power states of your device.
  • Remove the DOSYSGEN logic from sources files.
  • Use all source and header files.
  • Verify that no source or header files contain unused code.
  • Initialize any global variables within DLL_PROCESS_ATTACH, which is within the DLLENTRY function.

    Be aware of any implicit initialization to zero or NULL.

  • Call the DisableThreadLibraryCalls function within DLL_PROCESS_ATTACH in each DLL.

    DLL_PROCESS_ATTACH is in the DLLENTRY function. Installable ISR DLLs cannot call DisableThreadLibraryCalls.

  • Move duplicated code into functions.
  • Move code that multiple drivers share into a shared library.
  • Use only necessary critical sections.
  • Do not use the HalXXX bus parent access functions: HalGetBusData, HalTranslateBusAddress, and so on.

    Instead, use the CEDDK bus access functions: BusTransBusAddrToVirtual, GetBusNamePrefix, and so on.

  • Use the DEBUGCHK or ASSERT macros to ensure all assumptions are explicit.
  • Use validation functions to validate important structures, global data, device states, and so on.
  • Use debug zones of appropriately size.
  • Run the Application Verifier on the driver.
  • Declare destructors as virtual, if you expect a C++ class to have subclasses.

See Also

Power States | Sources File | Application Verifier Tool | Bus Drivers | CEDDK Dynamic-Link Library Bus Access Reference | Debugging Macros | Windows CE Drivers


Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft