Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam converting some ansi hebrew string to unicode string by using
following method:


nSize = MultiByteToWideChar(nlanguageCodePage, 0, chAnsiBuff, -1, NULL, 0);

MultiByteToWideChar(nlanguageCodePage, 0, chAnsiBuff, -1, chUniocodeBuff, 512);


iam having hebrew - ( windows code page 1255) so i will get 1255 ....if any junk characters are there in ansi it will dispalay correclty in unicode ?

what exactly this will do ( i.e first parameter will do if i willspecify hebrew still its converting proeprly)

please let me know the why its not working

What I have tried:

C#
//CONVERTING TO UNICODE
nSize = MultiByteToWideChar(nlanguageCodePage, 0, chAnsiBuff, -1, NULL, 0);
MultiByteToWideChar(nlanguageCodePage, 0, chAnsiBuff, -1, chUniocodeBuff, 512);

// bom at starting
if (nBOM == 0) { arcOut.Write(&bom, 2); }
arcOut.WriteString(chUniocodeBuff);
Posted
Updated 24-Nov-16 5:21am
v2
Comments
Richard MacCutchan 16-Nov-16 11:47am    
What does "not working" mean?
And why are you using the fixed size of 512 in the second call, rather than the value returned in nSize?
And why are you not checking the return value in the second call?
Member 12677926 16-Nov-16 22:43pm    
thats fine ..i tried with that ....my problem is not getting the desired output ...correct string in unicode hebrew file

1 solution

The function is for converting Multibyte string into wide char strings. Reading the documentation of the MultiByteToWideChar function is always a good idea.

But when your input is ANSI you better read the How to: Convert Between Various String Types to understand the different string types. A short: a ANSI-char is a single byte char, but the Multibyte and wide char can be up to four bytes. So be aware of the difference when using the sizeof-operator and some string length functions. Always check sizes before converting!!! Always ;-)
 
Share this answer
 

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