Enabling STRICT

When you define the STRICT symbol, you enable features that require more care in declaring and using types. This helps you write more portable code. This extra care will also reduce your debugging time. Enabling STRICT redefines certain data types so that the compiler does not permit assignment from one type to another without an explicit cast. This is especially helpful with Windows code. Errors in passing data types are reported at compile time instead of causing fatal errors at run time.

With Visual C++, STRICT type checking is defined by default.

To define STRICT on a file-by-file basis, insert a #define statement before including Windows.h:

#define STRICT
#include <windows.h>

When STRICT is defined, data type definitions change as follows:

  • Specific handle types are defined to be mutually exclusive; for example, you will not be able to pass an HWND where an HDC type argument is required. Without STRICT, all handles are defined as HANDLE, so the compiler does not prevent you from using one type of handle where another type is expected.
  • All callback function types (such as dialog procedures, window procedures, and hook procedures) are defined with full prototypes. This prevents you from declaring callback functions with incorrect parameter lists.
  • Parameter and return value types that should use a generic pointer are declared correctly as LPVOID instead of as LPSTR or another pointer type.
  • The COMSTAT structure is declared according to the ANSI standard.

Disabling STRICT

STRICT Compliance