Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
3.20/5 (4 votes)
See more:
Dear Gurus,

Can anyone please explain the difference between strcpy_s and StringCchCopy?

I would also like to know the difference between the functions found in StrSafe.h and the other safe string functions like wcscpy_s etc.

Please advice which function is best to use.

Thanks in advance.
Posted
Updated 17-Mar-11 4:17am
v2

If you really want to use the "safe" ones (they are not really safe, and are slow), I'd go with strcpy_s. It is provided with CRT, whereas StringCchCopy depends on Windows version - it is supported only in XP SP2 and above.
 
Share this answer
 
Comments
Ryan Zahra 17-Mar-11 10:27am    
In my case, support is not a problem as I'm using this for Windows Server 2003 SP2 and over. In your opinion, which function should I use and why?
They both do the same thing. strcpy_s is standard C, and the other is MFC a native Windows API.

Google really does work. Try this link:

http://msdn.microsoft.com/en-us/library/ms646979(v=VS.85).aspx[^]
 
Share this answer
 
v2
Comments
Ryan Zahra 17-Mar-11 10:11am    
Agreed, but which should I use? Which one is the best?
#realJSOP 17-Mar-11 13:52pm    
Whatever blows up your skirt.
Emilio Garavaglia 17-Mar-11 13:53pm    
We don't have their respective sources, but I'll not be surprised if we found that one just calls the other!
#realJSOP 17-Mar-11 13:54pm    
Please don't edit my posts. If there's a mistake, let me know, and I'll edit it.
Emilio Garavaglia 17-Mar-11 16:46pm    
Now you know ...
Both Versions are "Sercure".
I personally prefer the "StringCchCopy" versions since they are cleaner and more consistent then the *_S versions.

Regards,

K,D
 
Share this answer
 
v2
strcpy_s is the secure version of strcpy :

the secure functions do not prevent or correct security errors; rather, they catch errors when they occur. They perform additional checks for error conditions, and in the case of an error, they invoke an error handler


while StringCchCopy is a replacement for the following functions :

* strcpy, wcscpy, _tcscpy
* lstrcpy
* StrCpy
 
Share this answer
 
Comments
Ryan Zahra 17-Mar-11 10:08am    
According to MSDN both functions are secure. See http://msdn.microsoft.com/en-us/library/ms647466(v=VS.85).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900