CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jun 1999
    Posts
    505

    How to use #define _CRT_SECURE_NO_DEPRECATE?

    Hi,
    I am trying to use strcpy. I am getting 'deprecated function warning'. One of the posts on this forum suggests to use

    #define _CRT_SECURE_NO_DEPRECATE

    before stdafx.h

    I have done this but still I am getting lot of warnings:

    Code:
    1>------ Rebuild All started: Project: testCalendar1, Configuration: Debug Win32 ------
    1>Deleting intermediate and output files for project 'testCalendar1', configuration 'Debug|Win32'
    1>Compiling...
    1>stdafx.cpp
    1>Compiling...
    1>testCalendar1.cpp
    1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(38) : warning C4996: 'strcpy' was declared deprecated
    1>        d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
    1>        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
    1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(39) : warning C4996: 'strcpy' was declared deprecated
    1>        d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
    1>        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
    1>Compiling manifest to resources...
    1>Linking...
    1>LINK : D:\VCPROG\testCalendar1\Debug\testCalendar1.exe not found or not built by the last incremental link; performing full link
    1>Embedding manifest...
    1>Build log was saved at "file://d:\VCPROG\testCalendar1\testCalendar1\Debug\BuildLog.htm"
    1>testCalendar1 - 0 error(s), 2 warning(s)
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

    My code is as follows:

    Code:
    #define _CRT_SECURE_NO_DEPRECATE
    #include "stdafx.h"
    
    #include "string.h"
    
    int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    char *months[]=
    {
    	" ",
    	"January",
    	"February",
    	"March",
    	"April",
    	"May",
    	"June",
    	"July",
    	"August",
    	"September",
    	"October",
    	"November",
    	"December"
    };
    struct Calendar{
    	char monthName[11];
    	char DayName[31][3];//worst case
    	int  DayNo[31];
    };
    Calendar calArr[12]; //12 months
    char *DayName[7]={"Mon", "Tue", "Wed", "Thu","Fri", "Sat", "Sun"};
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int DayNameIndex;
    	int month,day;
    	//_CRT_SECURE_NO_DEPRECATE;
    	strcpy(calArr[0].DayName[0],"Sat");
    	strcpy(calArr[0].monthName,"January");
    	calArr[0].DayNo[0]=1;
    	DayNameIndex=5;
    
    
        for ( month = 1; month <= 12; month++ )
    	{
    		strcpy_s(calArr[month-1].monthName,months[1]);
    		//if (month==2) check leap year
    		for ( day = 1; day <= days_in_month[month]; day++ );
    	}

    Some body plz guide me.

    Zulfi.

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Try this one,

    #define _CRT_SECURE_NO_WARNINGS

  3. #3
    Join Date
    Apr 2008
    Posts
    725

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    with both these in the stdafx.h it does now work

    #define _CRT_SECURE_NO_DEPRECATE 1

    #define _CRT_NONSTDC_NO_DEPRECATE 1
    and several other methods

    http://social.msdn.microsoft.com/for...-f1de8f7ef291/

  4. #4
    Join Date
    Jun 1999
    Posts
    505

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Hi,

    Thanks for your attention. I tried both the recipes but still I am getting this warning message.

    Kindly guide me.


    Zulfi.

  5. #5
    Join Date
    Jan 2009
    Posts
    1,689

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Try adding -D_CRT_SECURE_NO_DEPRECATE to the arguments that you send the compiler.

  6. #6
    Join Date
    Jun 1999
    Posts
    505

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Hi,
    I have tried the following but still it gives me the same set of warnings:

    Code:
    #define D_CRT_SECURE_NO_DEPRECATE 
    #define _CRT_SECURE_NO_WARNINGS 
    #define _CRT_SECURE_NO_DEPRECATE 1
    
    #define _CRT_NONSTDC_NO_DEPRECATE 1
    #include "stdafx.h"
    #include "string.h"


    Warnings:

    Code:
    1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(45) : warning C4996: 'strcpy' was declared deprecated
    1>        d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
    1>        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
    1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(46) : warning C4996: 'strcpy' was declared deprecated
    1>        d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
    1>        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
    1>Linking...
    1>Embedding manifest...
    1>Build log was saved at "file://d:\VCPROG\testCalendar1\testCalendar1\Debug\BuildLog.htm"
    1>testCalendar1 - 0 error(s), 2 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    I still need help on this.


    Zulfi.
    Last edited by Zulfi Khan2; March 6th, 2011 at 11:51 AM. Reason: MISSED SOME COMMANDS

  7. #7
    Join Date
    May 2009
    Posts
    2,413

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Strange. Just

    #define _CRT_SECURE_NO_WARNINGS

    should be enough.

    I think you still get the messages because

    stdafx.cpp

    isn't recompiled so the defines don't take effect.

    Put

    #define _CRT_SECURE_NO_WARNINGS

    on top of stdafx.h instead.

    ---

    But before you do that you could try and add this line,

    #pragma warning(disable : 4996)

    on top of testcalendar1.cpp
    Last edited by nuzzle; March 6th, 2011 at 12:54 PM.

  8. #8
    Join Date
    Jun 1999
    Posts
    505

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Hi,

    I have tried the following:

    Code:
    // testCalendar1.cpp : Defines the entry point for the console application.
    //
    
    #pragma warning(disable : 4996)
    
    
    
    #define _CRT_SECURE_NO_WARNINGS 
    #include "stdafx.h"
    #include "string.h"
    #include "stdlib.h"
    But I am still getting the deprecate message.

    Kindly guide me.

    I am using VS2005.

    Zulfi.

  9. #9
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    You should add it to the project settings (C/C++ / Preprocessor / Preprocessor Definitions).

    Everything before #include "stdafx.h" is ignored if you have precompiled headers enabled.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  10. #10
    Join Date
    May 2009
    Posts
    2,413

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Quote Originally Posted by Zulfi Khan2 View Post
    But I am still getting the deprecate message.
    It wasn't that clear maybe but one of my suggestions was to put,

    #define _CRT_SECURE_NO_WARNINGS

    inside the actual stdafx.h file (at the top). That should do it.
    Last edited by nuzzle; March 6th, 2011 at 05:48 PM.

  11. #11
    Join Date
    Jan 2001
    Posts
    253

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Quote Originally Posted by nuzzle View Post
    It wasn't that clear maybe but one of my suggestions was to put,

    #define _CRT_SECURE_NO_WARNINGS

    inside the actual stdafx.h file (at the top). That should do it.
    Yes, this is one of the correct ways to handle this.

    When using precompiled headers with the Microsoft compiler, it ignores any code in the source file until it finds the include of the precompiled header file. So any of the #defines before the #include "stdafx.h" are just thrown away (ignored).

    The other common way to handle this is to add it to the preprocessor definitions in the project, making sure to set it for both debug and release configurations.

  12. #12
    Join Date
    Jun 1999
    Posts
    505

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Hi,

    I want to thank all my friends for helping me. I have put it on top in the stdafx.h file but still I am getting the same set of warnings.

    Code:
    #define _CRT_SECURE_NO_WARNINGS 
    #pragma once
    
    
    #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
    #include <stdio.h>
    #include <tchar.h>
    Kindly guide me. I want to avoid this . Though its not causing any error but for newcomers this can be very much questionable.

    Zulfi.

  13. #13
    Join Date
    Jun 1999
    Posts
    505

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Hi,
    I have done it in preprocessor definitions also. But still I am getting these warnings.

    Code:
    
    WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS

  14. #14
    Join Date
    May 2009
    Posts
    2,413

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    Strange.

    Well, I have no further suggestions. There's probably something you do that would be obvious if one could look at the full project.

    You'll have to figure it out using the Microsoft documentation,

    http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx

    To isolate the problem, create a new project and do nothing but introduce strcpy.
    Last edited by nuzzle; March 8th, 2011 at 02:27 AM.

  15. #15
    Join Date
    Jul 2012
    Posts
    1

    Re: How to use #define _CRT_SECURE_NO_DEPRECATE?

    I know I'm a few years late, but maybe this will help out other people.
    Instead of _CRT_SECURE_NO_WARNINGS in the preprocessor, try _CRT_SECURE_NO_DEPRECATE

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured