Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to use wcstombs() for chinese string.It is not working with chinese language.Please help me

Thanks in advance

Here is my code:
C++
BSTR key = _T("インフォメーション");
char *szDataIn;
CString str = key ;
int nSize = str.GetLength();
szDataIn = new char[nSize+1];
memset(szDataIn,0,nSize+1);
wcstombs(szDataIn, str, nSize+1);

Here szDataIn consists of empty value
Posted
Updated 13-Jul-11 0:13am
v2
Comments
Eugen Podsypalnikov 13-Jul-11 5:00am    
Please provide your test code and the returned value :)
kutz 2 13-Jul-11 6:02am    
Here is my code:

BSTR key = _T("インフォメーション");

char *szDataIn;

CString str = key ;

int nSize = str.GetLength();

szDataIn = new char[nSize+1];

memset(szDataIn,0,nSize+1);

wcstombs(szDataIn, str, nSize+1);


Here szDataIn consists of empty value
Eugen Podsypalnikov 13-Jul-11 6:41am    
0. Thanks !
1. Try nSize *= 2 before its passing.
2. Please provide the returned value of wcstombs()
ThatsAlok 13-Jul-11 6:32am    
I am not sure, why you want to include chinese character in one byte char !
kutz 2 13-Jul-11 7:00am    
It returns -1

1 solution

Are you doing everything correctly according to the description of the function[^]? Please show your code and any results that you get.
 
Share this answer
 
Comments
kutz 2 13-Jul-11 6:03am    
Here is my code: BSTR key = _T("インフォメーション"); char *szDataIn; CString str = key ; int nSize = str.GetLength(); szDataIn = new char[nSize+1]; memset(szDataIn,0,nSize+1); wcstombs(szDataIn, str, nSize+1); Here szDataIn consists of empty value
Richard MacCutchan 13-Jul-11 6:16am    
Looking at your code I would suggest that your output buffer (szDataIn) is not long enough for the converted string. Take a look at the MSDN link I gave you and use the function to find the required size of your resulting MBCS buffer.
kutz 2 13-Jul-11 6:33am    
Here I used variable nSize which is the length of the string and it is 9.So i gave the third parameter as nSize+1
Richard MacCutchan 13-Jul-11 6:41am    
Please read again the link I gave you, particularly the section on how to find the required length of your output buffer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900