what is the difference between strcpy and lstrcpy?
-
char *strcpy( char *string1, const char *string2 ); LPTSTR lstrcpy( LPTSTR lpString1, // address of buffer LPCTSTR lpString2 // address of string to copy );
- strcpy works with standard text. (1 byte per character) - lstrcpy is portable. lstrcpy will copy standard text if you use standard character settings in your project, and will copy Unicode text if you use Unicode character settings. (2 bytes per character) The "magic" behind this lies with the LPTSTR/LPCTSTR typedefs. When compiled under standard settings LPTSTR = char*, and therefore: lstrcpy = char*(char* lpString1, const char* lpString2), which is the same as strcpy. Using Unicode settings, LPTSTR = wchar_t*, and therefore: lstrcpy = wchar_t*(wchar_t* lpString1, const wchar_t* lpString2), which is the same as wcscpy. So if you're using lstrcpy in your project, and decide you want to use the Unicode settings, you don't have to change a thing. If you're using strcpy and decide to go Unicode, you would need to replace all your strcpy calls with wcscpy. I think there's an article on the site about this, you should check it out.:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
-
char *strcpy( char *string1, const char *string2 ); LPTSTR lstrcpy( LPTSTR lpString1, // address of buffer LPCTSTR lpString2 // address of string to copy );
- strcpy works with standard text. (1 byte per character) - lstrcpy is portable. lstrcpy will copy standard text if you use standard character settings in your project, and will copy Unicode text if you use Unicode character settings. (2 bytes per character) The "magic" behind this lies with the LPTSTR/LPCTSTR typedefs. When compiled under standard settings LPTSTR = char*, and therefore: lstrcpy = char*(char* lpString1, const char* lpString2), which is the same as strcpy. Using Unicode settings, LPTSTR = wchar_t*, and therefore: lstrcpy = wchar_t*(wchar_t* lpString1, const wchar_t* lpString2), which is the same as wcscpy. So if you're using lstrcpy in your project, and decide you want to use the Unicode settings, you don't have to change a thing. If you're using strcpy and decide to go Unicode, you would need to replace all your strcpy calls with wcscpy. I think there's an article on the site about this, you should check it out.:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
-
char *strcpy( char *string1, const char *string2 ); LPTSTR lstrcpy( LPTSTR lpString1, // address of buffer LPCTSTR lpString2 // address of string to copy );
- strcpy works with standard text. (1 byte per character) - lstrcpy is portable. lstrcpy will copy standard text if you use standard character settings in your project, and will copy Unicode text if you use Unicode character settings. (2 bytes per character) The "magic" behind this lies with the LPTSTR/LPCTSTR typedefs. When compiled under standard settings LPTSTR = char*, and therefore: lstrcpy = char*(char* lpString1, const char* lpString2), which is the same as strcpy. Using Unicode settings, LPTSTR = wchar_t*, and therefore: lstrcpy = wchar_t*(wchar_t* lpString1, const wchar_t* lpString2), which is the same as wcscpy. So if you're using lstrcpy in your project, and decide you want to use the Unicode settings, you don't have to change a thing. If you're using strcpy and decide to go Unicode, you would need to replace all your strcpy calls with wcscpy. I think there's an article on the site about this, you should check it out.:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Aren't you getting _tcscpy() and lstrcpy() mixed up here? It has been a long time since I've used lstrcpy() so you may well be right. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
-
Aren't you getting _tcscpy() and lstrcpy() mixed up here? It has been a long time since I've used lstrcpy() so you may well be right. Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
_tcscpy should do the same thing as lstrcpy. (text mapping wise) If I remember right, lstrcpy is the Win32 API version, whereas _tcscpy is the C runtime version.
:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
-
_tcscpy should do the same thing as lstrcpy. (text mapping wise) If I remember right, lstrcpy is the Win32 API version, whereas _tcscpy is the C runtime version.
:cool: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Jack Rabbit wrote: _tcscpy should do the same thing as lstrcpy. While the net result may be the same,
_tcscpy()
resolves to eitherstrcpy()
,_mbscpy()
, orwcscpy()
, which are all part of the RTL. Usinglstrcpy()
, which is part of the Win32 API, produces smaller code.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow