CListBox with wchar or WCHAR, Resolved
-
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
-
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
-
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
-
According to the CListBox documentation[^], the
AddString
method takes aLPCTSTR
parameter; that is, a pointer to aTCHAR[]
. If your project is built for Unicode that will be equated toLPCWSTR
which is a pointer to aWCHAR[]
.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
-
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
If you are working in Unicode the the Format statement requires that the format string be declared as Unicode, with either the
L
prefix orTEXT()
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 settingsAlso, 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.
-
If you are working in Unicode the the Format statement requires that the format string be declared as Unicode, with either the
L
prefix orTEXT()
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 settingsAlso, 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.
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
-
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
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 forwchar_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.