Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Fri, 6 Jun 2008 09:51:01 -0700,    group: microsoft.public.win32.programmer.international        back       


How to find only one invalid char in src buffer with MultiByteToWi   
Hi all,

     I am filling char buffer with 0-127 range characters along with é 
character, then MultiByteToWideChar API failed. If I include two times é 
character, it is getting success. Please find the below code snippet. Please 
correct If I am wrong. My system settings are United States, English. VC++ 
6.0, Windows XP.

CHAR szData[100] = {0};
strcpy(szData, "1é2345");
INT nWideCharBufferLen = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, 
szData, -1, 0, 0 );

// Here issue is there.

I think, MultiByteToWideChar api should return 0. But it is returning 5 
always. How?
Here this api will not be able to convert "é" character why because it is 
alreaded encoded. 

One more thing is, it é char is there twice (for ex: "1éééé2345");, then it 
returns ZERO. then I can find, some invalid characters are there in source 
string. 

If one time (é character) is there in string, then also i need to identify. 
How?

Thanks in advance.

-- 
Thanks & Regards,
Bill.
date: Fri, 6 Jun 2008 09:51:01 -0700   author:   Bill

Re: How to find only one invalid char in src buffer with MultiByteToWi   
Why on earth do you expect consistent and correct results from an API that 
you feed with incorrect data? Why do you tell the API that you give it an 
UTF-8 string even though it's not UTF-8? Adding more éééé's just modifies 
the UTF-8 stream. Maybe sometimes, it's correct, maybe sometimes it isn't.

Let me copy/paste my answer to your previous post:

*** Your literal ANSI string is encoded using the default codepage, not 
UTF8. ***

HTH,

Serge.
http://www.apptranslator.com - Localization tool for your C++ applications


"Bill"  wrote in message 
news:B3A53086-2B04-451E-BABB-E5A5D03A700C@microsoft.com...
> Hi all,
>
>     I am filling char buffer with 0-127 range characters along with é
> character, then MultiByteToWideChar API failed. If I include two times é
> character, it is getting success. Please find the below code snippet. 
> Please
> correct If I am wrong. My system settings are United States, English. VC++
> 6.0, Windows XP.
>
> CHAR szData[100] = {0};
> strcpy(szData, "1é2345");
> INT nWideCharBufferLen = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED,
> szData, -1, 0, 0 );
>
> // Here issue is there.
>
> I think, MultiByteToWideChar api should return 0. But it is returning 5
> always. How?
> Here this api will not be able to convert "é" character why because it is
> alreaded encoded.
>
> One more thing is, it é char is there twice (for ex: "1éééé2345");, then 
> it
> returns ZERO. then I can find, some invalid characters are there in source
> string.
>
> If one time (é character) is there in string, then also i need to 
> identify.
> How?
>
> Thanks in advance.
>
> -- 
> Thanks & Regards,
> Bill.
date: Mon, 9 Jun 2008 13:13:45 +0200   author:   Serge Wautier

Re: How to find only one invalid char in src buffer with MultiByteToWi   
> I think, MultiByteToWideChar api should return 0. But it is returning 5 
> always. How?
Tried it both on Vista and XP, with 1, 2, ... 5 times the character.
I always get 0.
Can you try and dump your resulting buffer when you get 5?


-- 
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
date: Mon, 09 Jun 2008 19:55:35 -0700   author:   Mihai N.

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us