Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unicode characters act weirdly

Posted on 2003-11-06
12
Medium Priority
?
285 Views
Last Modified: 2013-11-25
I have a task to update some MFC COM-components to support Unicode characters (Chinese text). So far I have successfully fixed two components, so I kind of know what I'm doing. With the third component, I faced a problem where Chinese text displayd correctly on the component when it was written, but as soon as the user pressed enter or the text field otherwise lost focus, the characters changed to something completely wrong. This happened because I had both _MBCS and _UNICODE defined in the project and got fixed when I removed _MBCS. Now, with the fourth component I have the same problem but this time only _UNICODE is defined and I have no clue what causes this. In addition, the Chinese text displays correctly when it's first written to wordpad for example and then copy/pasted to component. Although this doesn't help since I have to use the component to send the Unicode text to another device and when we tested, the text is not sent correctly.
0
Comment
Question by:milzer
[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
  • 3
  • 3
  • 2
  • +2
12 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 9700260
That a component would spontaneously change what it is displaying seems very unlikely.  I suspect you have an event of some sort being triggered when the component looses focus that is changing the contents of what is displayed.  I think you need to look deeper into your code and see what's going on when the component looses focus.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9702695
Do you have any DDV_ rountines defined within your Dialog's DoDataExchange function.

Sounds like a custom DDV_ routine may be the culprit.
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 9702746

 are you using TCHARS or OLECHARS  or wchar_t's or BSTRS's ?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:milzer
ID: 9713694
Actually, could these conversions be the source of this problem? This is done in killfocus, but it's called also when text is copy/pasted so I doubt that this causes the problem.

-----
CString str;
WCHAR temp_str[20];
BSTR bstrTempStr = NULL;

m_Edit.GetWindowText(bstrTempStr);
swprintf (temp_str, L"%s", bstrTempStr);
str.Format(_T("%ls"),temp_str);
-----

For jhance and _ys_: I didn't find any events or handlers that could cause this.
And for williamcampbell: There's TCHAR's, wchar's and BSTR's used in code, the component is done by some other guy about a year ago and I'm just a poor guy fixing it :)
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9716727
>> m_Edit.GetWindowText(bstrTempStr);
CWnd::GetWindowText doesn't even have a function that takes a BSTR as an argument.

If the ultimate goal is to store the text into a CString then:

CString str;
m_Edit.GetWindowText(str);

will simply do the desired job.
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 9716759

  my suggestion find all occurances of BSTR and replace them with _bstr_t BSTR's are usually used for COM stuff.

 otherwise as _ys_ suggests do all your string handling with CString


 
0
 

Author Comment

by:milzer
ID: 9721058
This is a COM component (as I said in my question already) so I have to use BSTR's. And the GetWindowText here doesn't accept CString parameter.

GroupListControl.cpp(1860) : error C2664: 'int __thiscall ATL::CWindow::GetWindowTextW(unsigned short ** )' : cannot convert parameter 1 from 'class WTL::CString' to 'unsigned short ** '

..I'm losing my hope with this :/
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9721184
> And the GetWindowText here doesn't accept CString parameter.
Apologies. I has assumed the use of MFC, as opposed to their ATL variants.

CString str;
TCHAR temp_str[20];

m_Edit.GetWindowText(&temp_str, 20);
str.Format(_T("%ls"),temp_str);

I've eliminated the intermediate BSTR as it was causing problems. This may not even be the cause of your problems, but at least the code is cleaner.
0
 

Author Comment

by:milzer
ID: 9730565
I still didn't found any reason for this, but when we finally got actual Chinese Windows and tested with it, the component worked just fine. With English Windows and Chinese localisations it didn't work.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 11975900
Submitted to PAQ with points refunded (125)

DarthMod
Community Support Moderator
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

719 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