Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Truncated unicode

Posted on 2008-06-18
14
Medium Priority
?
318 Views
Last Modified: 2013-11-20
I am having trouble with porting  a WinCE Visual C++ project over to Visual Studio. In both projects, all text needs to be in unicode. All is well in the WinCE project but in trying to bring it over to Visual Studio all of my calls to CString::LoadString(nID) return a string that is truncated after the first character. I have double and triple verified that UNICODE is defined for the project.

Any thoughts would be appreciated.
0
Comment
Question by:dbthompson
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21823209
try to define the _UNICODE macro also
0
 

Author Comment

by:dbthompson
ID: 21823255
Thank you for the input but I have already done that. I probably should have mentioned that also.

0
 
LVL 86

Expert Comment

by:jkr
ID: 21823533
What do you get when you use

CString s;
wchar_t* p = (LPCTSTR) s;

?

Just to be absolutely sure about the UNICODE issue...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dbthompson
ID: 21823850
With the above suggestion I get the following compile error:

error C2440: 'initializing' : cannot convert from 'const unsigned short *' to 'unsigned short *'
0
 
LVL 86

Expert Comment

by:jkr
ID: 21823891
Yup. So neither UNICODE nor _UNICODE are set for the module in question, since CString is compiled as the ANSI version, othrewise you wouldn't get an error.
0
 

Author Comment

by:dbthompson
ID: 21824004
Thank you for your help. However, in my project settings under the C/C++ tab, my settings for "Preprocessor Definitions" are:

UNICODE,_UNICODE,_DEBUG,_TPC_1560_,WIN32,_WINDOWS,_USRDLL,_LOGICOM_DLL,_WINDLL,_AFXDLL

Am I overlooking something? Is there some way that these definitions can get blown out? Is there some backdoor (ie command line) way to force unicode behavior?

Once again, thanks for the help.
0
 
LVL 86

Expert Comment

by:jkr
ID: 21824041
Hm, I'd try to set

#define UNICODE
#define _UNICODE

in StdAfx.h manually. Chances are that the settings are in effect only for a different build configuration.
0
 

Author Comment

by:dbthompson
ID: 21824129
Defining UNICODE and _UNICODE in StdAfx.h resulted in warnings about macro redefinition and the code snippet that you suggested a few entries ago still generated the same error.
0
 
LVL 86

Expert Comment

by:jkr
ID: 21824412
Now, that's really odd...
0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 1000 total points
ID: 21827695
If you check the size of TCHAR, i.e.:

sizeof(TCHAR);

does it return 1 or 2? If you get 2 your project is UNICODE.

Can you post a section of the code you have and a sample string? The simple test in code snippet below for reading a string from the a string table resource worked fine, perhaps if you post additional code it might yield additional suggestions.
CString test;
test.LoadString(IDS_TEST);
AfxMessageBox(test);

Open in new window

LoadString.png
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1000 total points
ID: 21827807
how do you determined it just read the first character? have you tested the CString length?
or maybe it is just a presentation problem.
0
 

Author Comment

by:dbthompson
ID: 21830177
They way I determined that it was only showing the first character is from the debugger. This has turned out to be a flawed way of determining that. The attached picture tells the story. The MessageBox shows the real text and the string variable "sMessage" is shown in the debugger. I have never known the debugger to work this way so I did not know I couldn't trust it. I know better now.

My apologies for the trouble and many thanks for the help.
Unicode.JPG
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21830189
yeah, that happened to me some time ago. That's why I asked.
0
 

Author Closing Comment

by:dbthompson
ID: 31468635
The only reason I said the solution was partially complete was that there was no coding problem, it was a debugger problem, so strictly speaking there was no actual coding solution. But the input was nonetheless helpful and greatly appreciated!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question