_CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES not working

Hello,

i tried using _CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES after reading from the following post:
http://blogs.msdn.com/michael_howard/archive/2005/02/03/366625.aspx

i am still getting the depricated methods warning.
i am including the code here.

/******** stdafx.h - start *******/

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#define _CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES 1

#define WIN32_LEAN_AND_MEAN        // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
#include <string.h>

// TODO: reference additional headers your program requires here

/******** stdafx.h - end *******/

/******** stdafx.cpp - start *******/

// stdafx.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    TCHAR    buff[1024];

    _tcscpy (buff, _T ("Bharat Mata Ki Jai"));

    return 0;
}

/******** stdafx.cpp - end *******/

And here is the build log:

/******* build log - start *******/

------ Rebuild All started: Project: stdafx, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'stdafx', configuration 'Debug|Win32'
Compiling...
stdafx.cpp
d:\prac\stdafx\stdafx\stdafx.cpp(11) : warning C4996: 'wcscpy' was declared deprecated
        d:\program files\microsoft visual studio 8\vc\include\wchar.h(944) : see declaration of 'wcscpy'
Compiling manifest to resources...
Linking...
Embedding manifest...
Build log was saved at "file://d:\prac\stdafx\stdafx\Debug\BuildLog.htm"
stdafx - 0 error(s), 1 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

/******* build log - end *******/

please reply.

Chanakya.




Answer this question

_CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES not working

  • Christian Bogino

    i dont want to disable warnings but to move to the new secure versions so _CRT_SECURE_NO_DEPRICATE is of no help.

    solved the problem using this article http://msdn2.microsoft.com/en-us/library/ms175759

    but still there are problems as the new secure methods wont work for pointers. consider following code:

    #define _CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES 1

    char*  buff = (char*)malloc(32 * sizeof(char));

    strcpy_s (buff, "Bharat Mata Ki Jai");  // generates error.

    i can solve above problem with following code:

    char*  buff = (char*)malloc(32 * sizeof(char));

    strcpy_s (buff, (32 * sizeof(char)), "Bharat Mata Ki Jai");

    now consider following code:

    void foo1 (void)
    {
        char*  buff = (char*)malloc(32 * sizeof(char));

        foo2 (buff);
    }

    void foo2 (char* szBuff)
    {
        strcpy (szBuff, "Bharat Mata Ki Jai");
    }

    now i have to pass the buffer size. which will change prototype for foo2.
    i dont want to change the interface. how can above be solved

    please reply.

    Chanakya.



  • Chrutil

    heh sorry above example was wrong.

    please consider following code:

    #define _CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES 1

    void foo1 (void)
    {
        char*  buff = (char*)malloc(32 * sizeof(char));

        foo2 (&buff);
    }

    void foo2 (char** szBuff)
    {
        strcpy_s (*szBuff, "Bharat Mata Ki Jai");
    }

    please reply.

    Chanakya



  • hangkous

    You can't: you have to change the function prototype: either to include the length of the buffer or to a type that carries the length around with it: like std::string.

  • TSCH

    You need to define _CRT_SECURE_NO_DEPRECATE or use the secure version of the method in question.

    Also take a look atthe following past post is you are still getting deprecated warnings: http://forums.microsoft.com/msdn/ShowPost.aspx PostID=77532

    Thanks,
      Ayman Shoukry
      VC++ Team

  • mjl

    You did it already by doing
    strcpy_s (buff, (32 * sizeof(char)), "Bharat Mata Ki Jai");

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Brainwires

    Ayman,

    thanks for your replies.

    but still the problem persists.

    please consider the following code:

    void foo1 (void)
    {
        char*  buff = (char*) malloc(32 * sizeof(char));

        strcpy_s (buff, (32 * sizeof(char)), "Bharat Mata Ki Jai");
        // i know the size here as i have allocated just above the strcpy_s() call.
    }

    void foo2 (void)
    {
        char*  buff = (char*) malloc(32 * sizeof(char));

        foo3 (&buff);
    }

    void foo3 (char**  szBuff)
    {
        //strcpy_s (*szBuff, "Bharat Mata Ki Jai");
        // here i dont know the size.
        // i cannot use sizeof() as i will get sizeof pointer.
        // i cannot use strlen () as this is dependent on '\0'
        // and it can be anywhere 5th position or 1000th position
        // how to find out the size here
        // i dont want to change the function prototype
    }

    please reply.

    Chanakya.



  • gbarendt

    what is the way to calculate size in foo2

    its a pointer hence sizeof() cannot be used.

    functions like strlen() depends on '\0' so it is also of no use.

    please reply.

    Chanakya



  • David Guyer MS

    Why not calculate the size needed in foo2 and hence you won't need to change the prototype or number of parameters passed to foo2.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • _CRT_SECURE_COPP_OVERLOAD_STANDARD_NAMES not working