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 TCHAR

CString to TCHAR

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

    Hi everyone! I have a CString variable and it must be passed in a function as TCHAR. I don't know how could I convert it. Does anybody knows? Thank you in advance! :)

    D O 2 Replies Last reply
    0
    • S satcat

      Hi everyone! I have a CString variable and it must be passed in a function as TCHAR. I don't know how could I convert it. Does anybody knows? Thank you in advance! :)

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

      SomeFunction( TCHAR ch )
      {
      ...
      }

      CString str;
      SomeFunction(str[0]);

      will work.


      A rich person is not the one who has the most, but the one that needs the least.

      1 Reply Last reply
      0
      • S satcat

        Hi everyone! I have a CString variable and it must be passed in a function as TCHAR. I don't know how could I convert it. Does anybody knows? Thank you in advance! :)

        O Offline
        O Offline
        Orkun GEDiK
        wrote on last edited by
        #3

        TCHAR is simple "char" type. If you want to pass CString data into a function, you should use "TCHAR*" instead of "TCHAR". Example as below. void f(TCHAR* prm) { do something } void main(void) { CString szPrm; f(szPrm.GetBuffer(szPrm.GetLength())); return(0); } Otherwise, you can pass only one character into function. Ahmet Orkun GEDiK System & Software Support Specialist (SAP R/3) ASTRON

        S 1 Reply Last reply
        0
        • O Orkun GEDiK

          TCHAR is simple "char" type. If you want to pass CString data into a function, you should use "TCHAR*" instead of "TCHAR". Example as below. void f(TCHAR* prm) { do something } void main(void) { CString szPrm; f(szPrm.GetBuffer(szPrm.GetLength())); return(0); } Otherwise, you can pass only one character into function. Ahmet Orkun GEDiK System & Software Support Specialist (SAP R/3) ASTRON

          S Offline
          S Offline
          satcat
          wrote on last edited by
          #4

          Now it works perfectly, thank you :-D

          J 1 Reply Last reply
          0
          • S satcat

            Now it works perfectly, thank you :-D

            J Offline
            J Offline
            John M Drescher
            wrote on last edited by
            #5

            If you do this you should also call szPrm.ReleaseBuffer(). The MSDN doc says the following: If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions. If you are not going to change the string the following should work (LPTSTR)(LPCTSTR)szPrm John

            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