Solved

Truncated unicode

Posted on 2008-06-18
14
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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 250 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 250 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
Change to event 1 135
ERP and the other system process verification 5 25
moto 4g phone enable finger print 4 72
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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