In Visual Studio 2005 / 2008 you can enable Code Analysis of your Unmanaged C++ project. The Code Analysis gives useful information of what part of your code does not meet the quality criteria. However, the Code Analysis also performs analysis of all system header files, which are used in the project. As it’s least likely that system header files will be modified by developers, this behavior is undesirable. For instance, Code Analysis will display a lot of messages compiling WTL header files.

You can disable Code Analysis of header files by adding the following code:

#pragma warning(push)
#include 
#pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS)
 
// ... your system includes ...
 
#pragma warning(pop)

Actually, in the CodeAnalysis/Warnings.h header file, the macro ALL_CODE_ANALYSIS_WARNINGS lists all Code Analysis warnings, which are disabled in the code using #pragma waring(disable) directive.

While including WTL headers I’ve faced with a problem when Code Analysis warnings (6xxx) were gone but certain waring messages appeared again (4505, etc). The problem is that in the atlbase.h file, some warings are also suppressed and the directive #pragma warning(disable) overrides them. You should use the following code in order to compile WTL header files without warnings and exclude WTL headers from Code Analysis.

// WTL
#include 
 
// Exclude WTL headers from Code Analysis
#pragma warning(push)
#include 
#pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS)
 
#include 
#include 
 
#pragma warning(pop)