DI Management Home > C Programming > _CRT_SECURE_NO_DEPRECATE

MSVC++: Getting rid of that _CRT_SECURE_NO_DEPRECATE warning


Are you a real C programmer who gets thoroughly annoyed by that blasted warning message everytime you compile a new project in MSVC++?

warning C4996: '_strcpy': This function or variable may be unsafe. Consider using _strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

Furthermore, the default character set is set to Unicode, which leads to various warnings that you need to use some other wide-character library.

This page explains how to fix it so your default new Win32 project has the settings you want. In particular,

The revised wizard file

The file you need to fix is called default.js. On our 64-bit system with MSVC++ 2008, this file is hidden away in this directory

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\Generic\Application\scripts\1033

It should be somewhere similar on your set up.

Make a backup copy of the original default.js file, and then use a text editor to make the following changes. You will need to make two sets of changes inside the file, one for the Debug configuration and one for the Release configuration.

  1. Change config.CharacterSet = charSetUNICODE; to config.CharacterSet = charSetNotSet; in the two places it occurs.
  2. Add the line CLTool.CompileAs = compileAsC; after the two lines that contain CLTool.RuntimeLibrary.
  3. Add the line strDefines += ";_CRT_SECURE_NO_DEPRECATE"; before the two lines CLTool.PreprocessorDefinitions = strDefines;.

Here is a marked-up copy of our version of the default.js file. The changes are at lines 127, 137, 177, 197, 206 and 246.

Once you've made and saved these changes, the next time you add a new Win32 project to your C++ solution in MSVC++, you should get the default settings you want. Now your project should compile first time.

Contact

To comment on this page or to contact us, please send us a message.

This page last updated 12 December 2011