Click here to Skip to main content
15,888,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert c++ code into c#, but with the following function MultiByteToWideChar, the first parameter codepage:
the first parameter has been ast as CP_ACP in c++, but when I use it in c#, then it is said that CP_ACP does not exist in current context. what have I missed here?

MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
Posted
Updated 8-Jul-12 6:26am
v4
Comments
[no name] 8-Jul-12 12:15pm    
Strings in .NET are all unicode
Sergey Alexandrovich Kryukov 8-Jul-12 14:37pm    
Right, and, by that reason, I don't think this call can be useful in a .NET application.
--SA
Seraph_summer 9-Jul-12 15:08pm    
you are right!! thanks a lot!
perilbrain 8-Jul-12 13:14pm    
If you are using CP_ACP directly, then it is senseless.....
See in the definition header the unsigned integer value for CP_ACP.
Seraph_summer 9-Jul-12 15:08pm    
you are right!! thanks a lot!

If this string is already UNICODE, then it is already wide char. Just be sure that your str in C# is multibyte (probably char array or ASCII) and not unicode. Such unicode string you may only convert back to multibyte with vice versa WideCharToMultiByte.
 
Share this answer
 
Comments
Seraph_summer 9-Jul-12 15:07pm    
thanks a lot, you are right!!
I do not think that function exists in the standard .NET framework, so you should use the System.Text.Encoding[^] class.
 
Share this answer
 
Comments
Seraph_summer 9-Jul-12 15:05pm    
thanks a lot!
you proposal is a good solution!
Richard MacCutchan 9-Jul-12 15:12pm    
Thanks, happy to help.
try using

C++
MultiByteToWideChar(0, 0, str, -1, NULL, 0);


and let us know if it still doesn't recognizes.
 
Share this answer
 
Comments
Seraph_summer 9-Jul-12 15:06pm    
thanks a lot, actually, I found later that I do not need this function in .net.
You might use GetACP[^] function instead of CP_ACP constant.
 
Share this answer
 
Comments
Seraph_summer 9-Jul-12 15:07pm    
thanks a lot, actually, I found later that I do not need this function in .net.

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