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. convert TCHAR to CString

convert TCHAR to CString

Scheduled Pinned Locked Moved C / C++ / MFC
12 Posts 6 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.
  • C Cedric Moonen

    No need to convert anything, you can simply assign your buffer in your CString object:

    CString csPath = buffer;

    If you need to concatenate your buffer at the end of the CString content, you can also do it like this:

    CString csPath = "Something";
    csPath += buffer;

    BTW, what is SIZEOFTCHAR ? What is its value ? If it is the size of one character, then your string will only be able to contain 1 single character, so I guess this is not really what you want.

    Cédric Moonen Software developer
    Charting control [v2.0] OpenGL game tutorial in C++

    P Offline
    P Offline
    p_1960
    wrote on last edited by
    #3

    Thanks for ur Reply..... but the issueis... TCHAR buffer[8000]; ::GetSystemDirectory(buffer,8000); i need add the below string to the path which is obtained from above function.. CString csPath; csPath=_T("\\")+"files.ini"; Please help me..

    CPalliniC C R 3 Replies Last reply
    0
    • P p_1960

      Thanks for ur Reply..... but the issueis... TCHAR buffer[8000]; ::GetSystemDirectory(buffer,8000); i need add the below string to the path which is obtained from above function.. CString csPath; csPath=_T("\\")+"files.ini"; Please help me..

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

      TCHAR buffer[8000];
      if (! ::GetSystemDirectory(buffer,8000))
      {
      // handle error
      }
      CString csPath(buffer);
      csPath += _T("\\files.ini");

      :)

      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.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • P p_1960

        Thanks for ur Reply..... but the issueis... TCHAR buffer[8000]; ::GetSystemDirectory(buffer,8000); i need add the below string to the path which is obtained from above function.. CString csPath; csPath=_T("\\")+"files.ini"; Please help me..

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #5

        p_1960 wrote:

        i need add the below string to the path which is obtained from above function.. CString csPath; csPath=_T("\\")+"files.ini";

        CString csPath = buffer;
        csPath += _T("\\files.ini");

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

        1 Reply Last reply
        0
        • P p_1960

          Thanks for ur Reply..... but the issueis... TCHAR buffer[8000]; ::GetSystemDirectory(buffer,8000); i need add the below string to the path which is obtained from above function.. CString csPath; csPath=_T("\\")+"files.ini"; Please help me..

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #6

          p_1960 wrote:

          TCHAR buffer[8000];

          What's your fetish with the number 8000? :rolleyes:

          It is a crappy thing, but it's life -^ Carlo Pallini

          CPalliniC 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            p_1960 wrote:

            TCHAR buffer[8000];

            What's your fetish with the number 8000? :rolleyes:

            It is a crappy thing, but it's life -^ Carlo Pallini

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #7

            I make a guess: This sample [^] uses 32767, that is **0x**8000-1 (Well..., actually the two things are probably unrelated...) :-D

            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.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            In testa che avete, signor di Ceprano?

            T 1 Reply Last reply
            0
            • CPalliniC CPallini

              I make a guess: This sample [^] uses 32767, that is **0x**8000-1 (Well..., actually the two things are probably unrelated...) :-D

              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.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #8

              CPallini wrote:

              This sample [^] uses 32767, that is 0x8000-1 (Well..., actually the two things are probably unrelated...)

              thats probably best answer i ever got!

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

              CPalliniC 1 Reply Last reply
              0
              • T ThatsAlok

                CPallini wrote:

                This sample [^] uses 32767, that is 0x8000-1 (Well..., actually the two things are probably unrelated...)

                thats probably best answer i ever got!

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                Never mind - my own stupidity is the source of every "problem" - Mixture

                cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #9

                Thank you, anyway I guess you got too few answers in you life... :-D

                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.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                In testa che avete, signor di Ceprano?

                T 1 Reply Last reply
                0
                • CPalliniC CPallini

                  Thank you, anyway I guess you got too few answers in you life... :-D

                  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.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #10

                  CPallini wrote:

                  Thank you, anyway I guess you got too few answers in you life

                  i thought you are taliking about question

                  CPalliniC 1 Reply Last reply
                  0
                  • T ThatsAlok

                    CPallini wrote:

                    Thank you, anyway I guess you got too few answers in you life

                    i thought you are taliking about question

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #11

                    Just kidding, pal (I know, I often forgot the joke icon... :rolleyes: ) :)

                    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.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    In testa che avete, signor di Ceprano?

                    1 Reply Last reply
                    0
                    • C Cedric Moonen

                      No need to convert anything, you can simply assign your buffer in your CString object:

                      CString csPath = buffer;

                      If you need to concatenate your buffer at the end of the CString content, you can also do it like this:

                      CString csPath = "Something";
                      csPath += buffer;

                      BTW, what is SIZEOFTCHAR ? What is its value ? If it is the size of one character, then your string will only be able to contain 1 single character, so I guess this is not really what you want.

                      Cédric Moonen Software developer
                      Charting control [v2.0] OpenGL game tutorial in C++

                      A Offline
                      A Offline
                      aravind sn
                      wrote on last edited by
                      #12

                      CString is 16 bit under unicode but 8bit under non unicode version i guess. but so underunicode version direct conversion can be done as TCHAR is unsigned short. where in non unicode version, WideCharToMultiByte() can be used

                      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