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. CString to LPCTSTR

CString to LPCTSTR

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
10 Posts 8 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.
  • J Offline
    J Offline
    johnnyXP
    wrote on last edited by
    #1

    How i can convert a CString to LPCTSTR? I can't found an easy solution for this. Please give a help. Thank's bros.

    D L 2 Replies Last reply
    0
    • J johnnyXP

      How i can convert a CString to LPCTSTR? I can't found an easy solution for this. Please give a help. Thank's bros.

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      Nothing easier than that: CString cstr; LPCTSTR lpString = (LPCTSTR)cstr; :-D Dominik


      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

      A 1 Reply Last reply
      0
      • J johnnyXP

        How i can convert a CString to LPCTSTR? I can't found an easy solution for this. Please give a help. Thank's bros.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You don't need to convert anything, CString has an implicit LPCTSTR cast. If a function takes a const char* as parameter, simply take your CString. regards

        B 1 Reply Last reply
        0
        • L Lost User

          You don't need to convert anything, CString has an implicit LPCTSTR cast. If a function takes a const char* as parameter, simply take your CString. regards

          B Offline
          B Offline
          Binayak
          wrote on last edited by
          #4

          For unicode you better use the following CString cstr; char * myString = (char *) (LPCTSTR) (cstr);

          M A G 3 Replies Last reply
          0
          • B Binayak

            For unicode you better use the following CString cstr; char * myString = (char *) (LPCTSTR) (cstr);

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Binayak wrote: char * myString = (char *) (LPCTSTR) (cstr) No, that is wrong. Casting blindly without understanding the underlying strings leads to problems. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

            B 1 Reply Last reply
            0
            • M Michael Dunn

              Binayak wrote: char * myString = (char *) (LPCTSTR) (cstr) No, that is wrong. Casting blindly without understanding the underlying strings leads to problems. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released

              B Offline
              B Offline
              Binayak
              wrote on last edited by
              #6

              sorry I forgot to put const. this works definitely (const char *) mystring = (const char *) LPCTSTR(temp) //where temp is the CString FYI look at: http://www-tcsn.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20702176.html

              T 1 Reply Last reply
              0
              • B Binayak

                For unicode you better use the following CString cstr; char * myString = (char *) (LPCTSTR) (cstr);

                A Offline
                A Offline
                Alvaro Mendez
                wrote on last edited by
                #7

                :eek: This is just wrong, whether UNICODE is used or not. If you need me to explain, let me know. Now it's quittin' time! Regards, Alvaro


                Hey! It compiles! Ship it.

                1 Reply Last reply
                0
                • D Dominik Reichl

                  Nothing easier than that: CString cstr; LPCTSTR lpString = (LPCTSTR)cstr; :-D Dominik


                  _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

                  A Offline
                  A Offline
                  Alvaro Mendez
                  wrote on last edited by
                  #8

                  No need to cast: LPCTSTR lpString = cstr; Regards, Alvaro


                  Hey! It compiles! Ship it.

                  1 Reply Last reply
                  0
                  • B Binayak

                    sorry I forgot to put const. this works definitely (const char *) mystring = (const char *) LPCTSTR(temp) //where temp is the CString FYI look at: http://www-tcsn.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20702176.html

                    T Offline
                    T Offline
                    Tim Smith
                    wrote on last edited by
                    #9

                    That is so wrong in so many ways. First off, if it is a UNICODE build, then you will end up with a pointer to data such as. 0x65 0x00 0x66 0x00 0x97 0x00 To convert from a T string to a const char string, use the following macro: T2CA (temp) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                    1 Reply Last reply
                    0
                    • B Binayak

                      For unicode you better use the following CString cstr; char * myString = (char *) (LPCTSTR) (cstr);

                      G Offline
                      G Offline
                      Gary R Wheeler
                      wrote on last edited by
                      #10

                      NO. Simply casting an LPCTSTR to a char * simply converts the pointer, not the characters. You must convert the characters, which requires using something like WideCharToMultiByte.


                      Software Zen: delete this;

                      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