Solved

Truncated unicode

Posted on 2008-06-18
14
268 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now