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. Converting character array to LPCTSTR

Converting character array to LPCTSTR

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
5 Posts 3 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.
  • S Offline
    S Offline
    siddharthsan
    wrote on last edited by
    #1

    Hi, Please anybody tell me how to convert a character array(char a[11]) to LPCTSTR??? Thank you Siddharth

    P C 2 Replies Last reply
    0
    • S siddharthsan

      Hi, Please anybody tell me how to convert a character array(char a[11]) to LPCTSTR??? Thank you Siddharth

      P Offline
      P Offline
      Programm3r
      wrote on last edited by
      #2

      Hi, What about:LPCTSTR var1 = "Test"; char a[11]={0}; strcpy(a, var1); //or maybe this LPCTSTR var1; char a[11]="abcdefghijk"; strcpy(var1, a)
      Regards,


      The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

      C 1 Reply Last reply
      0
      • S siddharthsan

        Hi, Please anybody tell me how to convert a character array(char a[11]) to LPCTSTR??? Thank you Siddharth

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        if _UNICODE is NOT defined, then you can do a simple cast:

        LPCTSTR lp = (LPCTSTR) a;

        however, if _UNICODE is defined, the you have to perform a conversion, using, for instance, MultiByteToWideChar function [^]. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        1 Reply Last reply
        0
        • P Programm3r

          Hi, What about:LPCTSTR var1 = "Test"; char a[11]={0}; strcpy(a, var1); //or maybe this LPCTSTR var1; char a[11]="abcdefghijk"; strcpy(var1, a)
          Regards,


          The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          you can't do that if _UNICODE is defined. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          P 1 Reply Last reply
          0
          • C CPallini

            you can't do that if _UNICODE is defined. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            P Offline
            P Offline
            Programm3r
            wrote on last edited by
            #5

            CPallini wrote:

            you can't do that if _UNICODE is defined

            :doh::doh: Forgot about the _UNICODE ... My bad :)


            The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

            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