Saturday, September 19, 2020

Error: C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

when I compiled old MTPRINTX demo from Revo MFC book, I got the following error messages:

Error C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. MTPRINTX c:\demo_revo\mtprintx\mtprintx\hexvivw.cpp 38

I searched internet, stackoverflow.com has some good posts:

  1. How to get rid of “unsafe” warnings / errors in Visual Studio (strcpy, sprintf, strdup)
  2. a good solution:

    If you are on visual studio version >= 2005 and want to fix these warnings in a proper way... easiest method is to #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 and #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 1 in your project.

  3. Secure Template Overloads
  4. Many CRT functions have been deprecated in favor of newer, security-enhanced versions (for example, strcpy_s is the more secure replacement for strcpy). The CRT provides template overloads to help ease the transition to the more secure variants.

  5. strcpy() error in Visual studio 2012
  6. I tested: but it would be a good idea to add _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) as to inherit predefined definitions IMHO & for the most part this is a good approach.

  7. How to fix compile error “This function or variable may be unsafe” (strcpy)

No comments:

Post a Comment