2 Replies - 6923 Views - Last Post: 15 January 2008 - 01:32 AM Rate Topic: -----

#1 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

strcpy() and wcscpy() Alternatives?

Posted 15 January 2008 - 12:11 AM

I'm using VS 2005 to write a Win32 DLL in Visual C++.

I have to copy strings (ASCII and Unicode) from a buffer returned by DeviceIOControl(), so I've been using strcpy(), strncpy(), wcscpy() and wcsncpy() for the copy operations. The code works, no problem but VC++ gives me a warning, "warning C4996: 'strncpy' was declared deprecated"

What alternatives can I use?
I've tried using the cstdlib header file but that doesn't get rid of the Warning either.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: strcpy() and wcscpy() Alternatives?

#2 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: strcpy() and wcscpy() Alternatives?

Posted 15 January 2008 - 12:52 AM

MSDN has strncpy_s listed as the non-deprecated version.

I believe that the deprecated ones had some security issues because they don't check for sufficient size in the destination character array, and it allows you to write more characters than the destination array has room for.
Was This Post Helpful? 0
  • +
  • -

#3 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: strcpy() and wcscpy() Alternatives?

Posted 15 January 2008 - 01:32 AM

That did the trick.
Thanks jj.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1