Solved

Unicode characters act weirdly

Posted on 2003-11-06
12
280 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

635 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