DI Management Home > C Programming > Getting rid of that MSVC++ warning C4996: 'may be unsafe/disable deprecation'

Getting rid of that MSVC++ warning C4996: 'may be unsafe/disable deprecation'


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.

You are well aware of the dangers of using strcpy() and its ilk, but know how to deal with them and want to write code that will compile on multiple platforms.

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

This page explains how we fix it so our new Win32 Console project has the default settings we want. We describe changes for both VS2008 and [New2015-12-23] VS2013. No doubt the changes are similar for those versions in between and VS2015.

In particular, the changes we make are to default to:

Even better (from a real C programmers point of view), if you just want an empty project each time, instead of all that precompiled header stdafx rubbish, then see default to an empty project below.

The revised wizard file

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

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\Generic\Application\scripts\1033
C:\Program Files (x86)\Microsoft Visual Studio 12.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 (look under var config = proj.Object.Configurations("Debug") and var config = proj.Object.Configurations("Release"), respectively).

MSVC 2008
  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 MSVC 2008 version of the default.js file. The changes are at lines 127, 137, 177, 197, 206 and 246.

MSVC 2013

The changes are almost the same except step 2 becomes

  • Add the line CLTool.CompileAs = compileAsC; after the two lines that contain var CLTool = config.Tools("VCCLCompilerTool")

Here are the changes made to our MSVC 2013 default.js file.

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

Default to an empty project

If you just want an empty project instead of all that precompiled header stdafx rubbish, then edit the default.htm file, which on our system is in

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

The changes are identical for MSVC 2008 and MSVC 2013. Use a text editor to change lines 19 and 21 as shown below:

19 <SYMBOL NAME="EMPTY_PROJECT" TYPE=checkbox VALUE=false></SYMBOL>
20 <SYMBOL NAME="EXPORT_SYMBOLS" TYPE=checkbox VALUE=false></SYMBOL>
21 <SYMBOL NAME="PRE_COMPILED_HEADER" TYPE=checkbox VALUE=true></SYMBOL>
22 <SYMBOL NAME="SUPPORT_ATL" TYPE=checkbox VALUE=false></SYMBOL>
23 <SYMBOL NAME="SUPPORT_MFC" TYPE=checkbox VALUE=false></SYMBOL>
<SYMBOL NAME="EMPTY_PROJECT" TYPE=checkbox VALUE=true></SYMBOL>
<SYMBOL NAME="EXPORT_SYMBOLS" TYPE=checkbox VALUE=false></SYMBOL>
<SYMBOL NAME="PRE_COMPILED_HEADER" TYPE=checkbox VALUE=false></SYMBOL>
<SYMBOL NAME="SUPPORT_ATL" TYPE=checkbox VALUE=false></SYMBOL>
<SYMBOL NAME="SUPPORT_MFC" TYPE=checkbox VALUE=false></SYMBOL>

Now you should always default to an empty project.

Win32 Application Wizard (MSVC2008 Win32 Application Wizard (MSVC2013)

In MSVC 2013, you can turn off the Security Development Lifecycle (SDL) checks by changing line 22:

<SYMBOL NAME="SDL_CHECK" TYPE=checkbox VALUE=false></SYMBOL>

Platform Toolset

If anyone knows how to change default.js so the project defaults to Platform Toolset = Visual Studio 2013 - Windows XP (v120_xp) instead of v120, please let us know.

(We really, really hate these "fixes" in MSVC deliberately to make their executables not work on older platforms).

Contact

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

This page last updated 28 March 2019