Conditional Compilation and the Build Environment

When you use Windows Driver Kit (WDK) 8 you can conditionally compile the debugging code in your driver by selecting the release (free) or debug (checked) configuration. The configuration you choose sets the DBG preprocessor constant.

The value of DBG depends on the build configuration you choose to build your driver:

  • If you create your driver using a debug (checked) configuration, DBG will equal 1.

  • If you create your driver by using a release (free) build configuration, DBG will equal 0 (or will be undefined if neither wdm.h nor ntddk.h is included).

The debugging routines ASSERT, ASSERTMSG, KdBreakPoint, KdBreakPointWithStatus, KdPrint, and KdPrintEx are actually macros that are conditionally defined depending on the value of DBG. If it is 0, these macros are no-ops. Therefore, these macros are active only in the debug (checked) build of a driver.

Note   All debugging routines beginning with the letters "Kd" have no effect in a free build of a driver, except for KdRefreshDebuggerNotPresent.

For more information about using Visual Studio and MSBuild to create to release and debug versions of a driver, see Building a Driver and the WDK and Visual Studio build environment.