wcstombs is not working
-
Hm, just looking at your code line and reading this in the documentation "If cchWideChar is set to 0, the function fails." I´d say use -1 as your cchWideChar (fourth parameter). Souldrift
-
hi all, i am using wcstombs function to convert my const wchar* value to char*.... but its showing ?? marks instead of unicode characters.. i tried using widechartomultibyte like this... [(WideCharToMultiByte(CP_ACP, 0, Text, 0, Chartext, nSize, NULL, NULL); where int nSize =0;] but its also not converting the value.... can anyone help me where am i going wrong... Thanks, Rakesh.
If the wide char character cannot be represented in the choosen codepage (in you case
CP_ACP
, i.e. The system default WindowsANSI
codepage), then it is replaced by a default one, seeWideCharToMultiByte
documentation [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, This is my piece of code.. const WCHAR* pText = "hello"; char * pCharText; WideCharToMultiByte(CP_ACP, 0, pText, -1,(LPSTR) pCharText, nSize, NULL, NULL); Thanks, Rakesh.
That cannot be all your code. What´s nSize? And pCharText wasn´t initialized -> this should be a runtime error. Anyway, try this
int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0); // first we ask for the memory needed
char* result = new char[erg];
erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, result, erg, 0, 0); // then we convertSouldrift
-
That cannot be all your code. What´s nSize? And pCharText wasn´t initialized -> this should be a runtime error. Anyway, try this
int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0); // first we ask for the memory needed
char* result = new char[erg];
erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, result, erg, 0, 0); // then we convertSouldrift
Hi SoulDrift, I tried your code..its still showing the same "??" marks rather japanese texts.. please tell me where am going wrong.. am giving the code once again for your perusal.. const WCHAR* = L"sss"; int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0); // first we ask for the memory needed char* charText = new char[erg]; erg = WideCharToMultiByte(CP_ACP, 0, pText, -1, charText, erg, 0, 0); // then we convert Thanks, Rakesh
-
Hi SoulDrift, I tried your code..its still showing the same "??" marks rather japanese texts.. please tell me where am going wrong.. am giving the code once again for your perusal.. const WCHAR* = L"sss"; int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0); // first we ask for the memory needed char* charText = new char[erg]; erg = WideCharToMultiByte(CP_ACP, 0, pText, -1, charText, erg, 0, 0); // then we convert Thanks, Rakesh
Your const WCHAR* doesn`t have a label. Does your compiler not have a problem with that? I tried your code
const WCHAR* pText = L"sss";
int erg=WideCharToMultiByte(CP_ACP, 0, pText, -1, NULL, 0, 0, 0); // first we ask for the memory needed
char* charText = new char[erg];
erg = WideCharToMultiByte(CP_ACP, 0, pText, -1, charText, erg, 0, 0); // then we convertI works very nicely. Souldrift
-
hi all, i am using wcstombs function to convert my const wchar* value to char*.... but its showing ?? marks instead of unicode characters.. i tried using widechartomultibyte like this... [(WideCharToMultiByte(CP_ACP, 0, Text, 0, Chartext, nSize, NULL, NULL); where int nSize =0;] but its also not converting the value.... can anyone help me where am i going wrong... Thanks, Rakesh.
Rakesh5 wrote:
...but its showing ?? marks instead of unicode characters..
What is?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
If the wide char character cannot be represented in the choosen codepage (in you case
CP_ACP
, i.e. The system default WindowsANSI
codepage), then it is replaced by a default one, seeWideCharToMultiByte
documentation [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I have to agree, if your developing on an American/english installed OS then CP_ACP will be Windows 1252, you want to change that to the Japanese/country specific page. ? is I remember right is 0x20, could be wrong. I wrote a little app to convert UNICODE to Multibyte supporting the codepages we need, and if the wrong code page was chosen the character would be displayed as ?? basically I replaced CP_ACP with either 1250 or 1251 or 1252 etc.. Seemed to do the trick.
-
hi all, i am using wcstombs function to convert my const wchar* value to char*.... but its showing ?? marks instead of unicode characters.. i tried using widechartomultibyte like this... [(WideCharToMultiByte(CP_ACP, 0, Text, 0, Chartext, nSize, NULL, NULL); where int nSize =0;] but its also not converting the value.... can anyone help me where am i going wrong... Thanks, Rakesh.
First of all, using CP_ACP means you don't really have a control of the target code page - it depends on the users's settings. Sometimes it is exactly what you want, sometimes it is not. Anyway, if we assume that your system locale is Windows CP 1252 and you have some Greek characters in
Text
, your code will try to convert Greek characters to CP1252 and because there is no mapping between the two scripts, you are going to get replacement characters (?) instead. To convert Greek text from const wchar* value to char value tochar*
, you'll need to use CP1253 (not sure if I spelled the constant correctly) instead of CP_AP. I hope it make sense.