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 CString to WCHAR

convert CString to WCHAR

Scheduled Pinned Locked Moved C / C++ / MFC
help
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.
  • N Offline
    N Offline
    neha agarwal27
    wrote on last edited by
    #1

    Hi all, I want to convert CString to WCHAR; i have done this:-

    WCHAR wsz[MAX_PATH];
    CString szLinkName = _T("Test Mail");
    MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(LPCTSTR)szLinkName, -1,
    wsz, MAX_PATH);

    but i only get "T" in wsz i.e first element.... I am working in VC2005 Can anybody help me in this... Thanks in advance

    R R M D 4 Replies Last reply
    0
    • N neha agarwal27

      Hi all, I want to convert CString to WCHAR; i have done this:-

      WCHAR wsz[MAX_PATH];
      CString szLinkName = _T("Test Mail");
      MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(LPCTSTR)szLinkName, -1,
      wsz, MAX_PATH);

      but i only get "T" in wsz i.e first element.... I am working in VC2005 Can anybody help me in this... Thanks in advance

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

      This is the Gabababazillionth time this question is asked. Please learn to use Google[^].

      Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP

      1 Reply Last reply
      0
      • N neha agarwal27

        Hi all, I want to convert CString to WCHAR; i have done this:-

        WCHAR wsz[MAX_PATH];
        CString szLinkName = _T("Test Mail");
        MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(LPCTSTR)szLinkName, -1,
        wsz, MAX_PATH);

        but i only get "T" in wsz i.e first element.... I am working in VC2005 Can anybody help me in this... Thanks in advance

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

        neha.agarwal27 wrote:

        MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(LPCTSTR)szLinkName, -1, wsz, MAX_PATH);

        how and why do you decided to use MultiByteToWideChar here?

        1 Reply Last reply
        0
        • N neha agarwal27

          Hi all, I want to convert CString to WCHAR; i have done this:-

          WCHAR wsz[MAX_PATH];
          CString szLinkName = _T("Test Mail");
          MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(LPCTSTR)szLinkName, -1,
          wsz, MAX_PATH);

          but i only get "T" in wsz i.e first element.... I am working in VC2005 Can anybody help me in this... Thanks in advance

          M Offline
          M Offline
          Mathias S
          wrote on last edited by
          #4

          Why do it the hard way when there are macros in ATL to do it for you. #include void MyFunc(WCHAR* s) { USES_CONVERSION; CString str = W2T(s); } Just make sure you don't use W2T() in a loop since it allocate memory from the stack. then use W2T_EX instead and USES_CONVERSION_EX;

          1 Reply Last reply
          0
          • N neha agarwal27

            Hi all, I want to convert CString to WCHAR; i have done this:-

            WCHAR wsz[MAX_PATH];
            CString szLinkName = _T("Test Mail");
            MultiByteToWideChar(CP_ACP, 0, (LPCSTR)(LPCTSTR)szLinkName, -1,
            wsz, MAX_PATH);

            but i only get "T" in wsz i.e first element.... I am working in VC2005 Can anybody help me in this... Thanks in advance

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

            neha.agarwal27 wrote:

            but i only get "T" in wsz i.e first element....

            How are you verifying this?

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

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

            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