Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,999 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,401 people online right now. Registration is fast and FREE... Join Now!




strcpy() and wcscpy() Alternatives?

 
Reply to this topicStart new topic

strcpy() and wcscpy() Alternatives?

born2c0de
14 Jan, 2008 - 11:11 PM
Post #1

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Strcpy() And Wcscpy() Alternatives?
14 Jan, 2008 - 11:52 PM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Strcpy() And Wcscpy() Alternatives?
15 Jan, 2008 - 12:32 AM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
That did the trick.
Thanks jj.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 12:09PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month