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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to convert a CString to WCHAR?

How to convert a CString to WCHAR?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 5 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.
  • T Offline
    T Offline
    TooShy2Talk
    wrote on last edited by
    #1

    Hello guyz, I want to convert a CString to WCHAR but I don't know how to. Can anybody help me with this? Any comment will be much appreciated. Thank you.

    N R D C 4 Replies Last reply
    0
    • T TooShy2Talk

      Hello guyz, I want to convert a CString to WCHAR but I don't know how to. Can anybody help me with this? Any comment will be much appreciated. Thank you.

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      TooShy2Talk wrote:

      I want to convert a CString to WCHAR but I don't know how to.

      It depends on whether you have defined _UNICODE in your application or not. i.e if _UNICODE is define, the CString internally keeps a wchar* itself. so you can simply copy from cstring to wchar_t[] usinf wcscpy() fucntion. If _UNICODE is not define, CString will be internally keeping a char* pointer and you have to covert this char* to wchar_t[] using MultiByteToWideChar() API.

      nave [OpenedFileFinder]

      1 Reply Last reply
      0
      • T TooShy2Talk

        Hello guyz, I want to convert a CString to WCHAR but I don't know how to. Can anybody help me with this? Any comment will be much appreciated. Thank you.

        R Offline
        R Offline
        Russell
        wrote on last edited by
        #3

        CString -> CStringW ?


        Russell

        1 Reply Last reply
        0
        • T TooShy2Talk

          Hello guyz, I want to convert a CString to WCHAR but I don't know how to. Can anybody help me with this? Any comment will be much appreciated. Thank you.

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

          If Unicode is not defined, check out the A2W() macro. If Unicode is defined, you can simply use _tcscpy().


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          • T TooShy2Talk

            Hello guyz, I want to convert a CString to WCHAR but I don't know how to. Can anybody help me with this? Any comment will be much appreciated. Thank you.

            C Offline
            C Offline
            codeII
            wrote on last edited by
            #5

            Sindse ATL 7.0 and MFC 7.0 You can use CStringW (or CStringA ) This code is valid for both Unicode and Multibyte:

            CString cMyCString("Test");
            CStringW cMyCStringW( cMyCString );
            (LPCWSTR) cMyCStringW;

            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