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. ATL / WTL / STL
  4. CListBox with wchar or WCHAR, Resolved

CListBox with wchar or WCHAR, Resolved

Scheduled Pinned Locked Moved ATL / WTL / STL
c++questioncsharpvisual-studio
7 Posts 3 Posters 1 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.
  • B Offline
    B Offline
    bkelly13
    wrote on last edited by
    #1

    Visual Studio 2008, MFC, C++, Windows 7 and Windows XP My project uses WCHAR and a dialog needs a CListBox. But CListBox does not like wchar_t or WCHAR. In particular, method AddString(). My searches have not discovered a CListBoxW or anything that looks like wchar_t methods. What is the proper control to use that performs the CListBox operations? I see that CString will work, but then the WCHAR must be converted to CString. Must that path be taken? Resolution: I was certain Unicode was selected. I was wrong, MBCS was selected. Changing that to Unicode resolved the apparent inconsistencies.

    Thank you for your time

    E L 2 Replies Last reply
    0
    • B bkelly13

      Visual Studio 2008, MFC, C++, Windows 7 and Windows XP My project uses WCHAR and a dialog needs a CListBox. But CListBox does not like wchar_t or WCHAR. In particular, method AddString(). My searches have not discovered a CListBoxW or anything that looks like wchar_t methods. What is the proper control to use that performs the CListBox operations? I see that CString will work, but then the WCHAR must be converted to CString. Must that path be taken? Resolution: I was certain Unicode was selected. I was wrong, MBCS was selected. Changing that to Unicode resolved the apparent inconsistencies.

      Thank you for your time

      E Offline
      E Offline
      emadns
      wrote on last edited by
      #2

      Change the Project Settings to build Unicode build. This will make CString and CListBox become Unicode

      1 Reply Last reply
      0
      • B bkelly13

        Visual Studio 2008, MFC, C++, Windows 7 and Windows XP My project uses WCHAR and a dialog needs a CListBox. But CListBox does not like wchar_t or WCHAR. In particular, method AddString(). My searches have not discovered a CListBoxW or anything that looks like wchar_t methods. What is the proper control to use that performs the CListBox operations? I see that CString will work, but then the WCHAR must be converted to CString. Must that path be taken? Resolution: I was certain Unicode was selected. I was wrong, MBCS was selected. Changing that to Unicode resolved the apparent inconsistencies.

        Thank you for your time

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        According to the CListBox documentation[^], the AddString method takes a LPCTSTR parameter; that is, a pointer to a TCHAR[]. If your project is built for Unicode that will be equated to LPCWSTR which is a pointer to a WCHAR[].

        B 1 Reply Last reply
        0
        • L Lost User

          According to the CListBox documentation[^], the AddString method takes a LPCTSTR parameter; that is, a pointer to a TCHAR[]. If your project is built for Unicode that will be equated to LPCWSTR which is a pointer to a WCHAR[].

          B Offline
          B Offline
          bkelly13
          wrote on last edited by
          #4

          Hello, My project is MFC and does and did have Unicode set. Right now, things are rather funky and I don't understand. For example CString a; CString b; b = "test"; a.Format( "%s", b ); // does not compile. a.Format( L"%s", b ); // does compile. A search found a tutorial that shows use without the L prefix. So I went back to the WCHAR concept and now it works. I really wish I was not the only one here working with C++. Thank you for taking the time to reply.

          Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

          L 1 Reply Last reply
          0
          • B bkelly13

            Hello, My project is MFC and does and did have Unicode set. Right now, things are rather funky and I don't understand. For example CString a; CString b; b = "test"; a.Format( "%s", b ); // does not compile. a.Format( L"%s", b ); // does compile. A search found a tutorial that shows use without the L prefix. So I went back to the WCHAR concept and now it works. I really wish I was not the only one here working with C++. Thank you for taking the time to reply.

            Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            If you are working in Unicode the the Format statement requires that the format string be declared as Unicode, with either the L prefix or TEXT() macro, thus:

            a.Format( L"%s", b ); // %s will be compiled as Unicode always
            a.Format( TEXT("%s"), b ); // %s will be compiled as Unicode or ASCII depending on the project settings

            Also, you should use upper case S to indicate that the contents of b is actually an ASCII, rather than Unicode, string.

            bkelly13 wrote:

            I really wish I was not the only one here working with C++.

            You are not, if you look in the C/C++ forum you will see fairly regular questions.

            B 1 Reply Last reply
            0
            • L Lost User

              If you are working in Unicode the the Format statement requires that the format string be declared as Unicode, with either the L prefix or TEXT() macro, thus:

              a.Format( L"%s", b ); // %s will be compiled as Unicode always
              a.Format( TEXT("%s"), b ); // %s will be compiled as Unicode or ASCII depending on the project settings

              Also, you should use upper case S to indicate that the contents of b is actually an ASCII, rather than Unicode, string.

              bkelly13 wrote:

              I really wish I was not the only one here working with C++.

              You are not, if you look in the C/C++ forum you will see fairly regular questions.

              B Offline
              B Offline
              bkelly13
              wrote on last edited by
              #6

              Hello Richard, This morning I determined that some code using CString compiled in Debug mode but not in Release mode. That was really puzzling. After messing around I discovered that I had multibyte character set enabled rather than Unicode. It explained some other problems I had since I was sure Unicode was selected. Now I am back on a path of progress. I was not clear in my last statement of my previous post. I really wish I was not the only one at this work site working with C++. There is an Oracle data base guy and five people working on a specialized script for processing telemetry data. Most of them know C# and they disdain C++. I'll stick with Unicode. I am thinking of dropping WCHAR and going to wchar_t. Is that a good or bad idea? Or maybe indifferent?

              Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

              L 1 Reply Last reply
              0
              • B bkelly13

                Hello Richard, This morning I determined that some code using CString compiled in Debug mode but not in Release mode. That was really puzzling. After messing around I discovered that I had multibyte character set enabled rather than Unicode. It explained some other problems I had since I was sure Unicode was selected. Now I am back on a path of progress. I was not clear in my last statement of my previous post. I really wish I was not the only one at this work site working with C++. There is an Oracle data base guy and five people working on a specialized script for processing telemetry data. Most of them know C# and they disdain C++. I'll stick with Unicode. I am thinking of dropping WCHAR and going to wchar_t. Is that a good or bad idea? Or maybe indifferent?

                Thank you for your time If you work with telemetry, please check this bulletin board: www.irigbb.com

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                bkelly13 wrote:

                and they disdain C++.

                Thanks for clarifying Bryan; seems you really are the one with the tough part of the job.

                bkelly13 wrote:

                dropping WCHAR and going to wchar_t

                Indifferent really, as WCHAR is just a typedef for wchar_t, probably a hangover from the days before C++. I know that going from ASCII to Unicode is initially a bit of a pain, but it is probably the right decision for the long term.

                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