Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what is the difference between strcpy and lstrcpy?

what is the difference between strcpy and lstrcpy?

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    freehawk
    wrote on last edited by
    #1

    Hello everyone what is the difference between strcpy and lstrcpy? Thanks. -Freehawk

    J 1 Reply Last reply
    0
    • F freehawk

      Hello everyone what is the difference between strcpy and lstrcpy? Thanks. -Freehawk

      J Offline
      J Offline
      Jack Puppy
      wrote on last edited by
      #2

      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!

      F N 2 Replies Last reply
      0
      • J Jack Puppy

        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!

        F Offline
        F Offline
        freehawk
        wrote on last edited by
        #3

        Thank you very much. It gave me a clear imagine. -Freehawk

        1 Reply Last reply
        0
        • J Jack Puppy

          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!

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          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"

          J 1 Reply Last reply
          0
          • N Neville Franks

            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"

            J Offline
            J Offline
            Jack Puppy
            wrote on last edited by
            #5

            _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!

            D 1 Reply Last reply
            0
            • J Jack Puppy

              _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!

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Jack Rabbit wrote: _tcscpy should do the same thing as lstrcpy. While the net result may be the same, _tcscpy() resolves to either strcpy(), _mbscpy(), or wcscpy(), which are all part of the RTL. Using lstrcpy(), 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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups