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. Conversion of CString to LPCWSTR

Conversion of CString to LPCWSTR

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
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
    Sudhakar Pasupunuri
    wrote on last edited by
    #1

    Hi .. I want to convert my "CString" to "LPCWSTR" type.. How can I do this??? Plz help me out .. Thanks Sudhakar

    A A 2 Replies Last reply
    0
    • S Sudhakar Pasupunuri

      Hi .. I want to convert my "CString" to "LPCWSTR" type.. How can I do this??? Plz help me out .. Thanks Sudhakar

      A Offline
      A Offline
      Arsalan Malik
      wrote on last edited by
      #2

      Use the function mbstowcs. It takes a char pointer, so use GetBuffer function of CString to get char pointer. Alternatively you can use AllocSysString method to BSTR, which can be easily passed as LPCWSTR. Arsalan Malik

      1 Reply Last reply
      0
      • S Sudhakar Pasupunuri

        Hi .. I want to convert my "CString" to "LPCWSTR" type.. How can I do this??? Plz help me out .. Thanks Sudhakar

        A Offline
        A Offline
        Archer282
        wrote on last edited by
        #3

        use the member function GetBuffer() Link to microsoft documentation of CString::GetBuffer example:

        CString MyString("This is my string"); LPCWSTR MyLPCWSTR = (LPCWSTR) MyString.GetBuffer(MyString.GetLength());

        note: the return type of GetBuffer() is LPTSTR

        S 1 Reply Last reply
        0
        • A Archer282

          use the member function GetBuffer() Link to microsoft documentation of CString::GetBuffer example:

          CString MyString("This is my string"); LPCWSTR MyLPCWSTR = (LPCWSTR) MyString.GetBuffer(MyString.GetLength());

          note: the return type of GetBuffer() is LPTSTR

          S Offline
          S Offline
          Sudhakar Pasupunuri
          wrote on last edited by
          #4

          Thanks for the info.. It was working perfectly.. Thanks Sudhakar

          D 1 Reply Last reply
          0
          • S Sudhakar Pasupunuri

            Thanks for the info.. It was working perfectly.. Thanks Sudhakar

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

            Remember that for every call to GetBuffer(), there must also be a call to ReleaseBuffer(). If you are not going to be editing the internal CString buffer, why ask for a writeable copy? Try this instead:

            CString MyString("This is my string");
            LPCWSTR MyLPCWSTR = (LPCWSTR) ((LPCTSTR) MyString);


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            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