Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1312 Returning std::wstring values from C++ to C# does not work with Unicode strings

open
nobody
csharp (36)
5
2013-04-08
2013-04-08
Jarl
No

The generated marshaling code for returning std::wstring strings to .NET, replaces Unicode characters with "?". To reproduce this, put this code in the .i file:

%include "std_wstring.i"

%inline %{
std::wstring myTestFunc(const std::wstring & s)
{
return s;
}
%}

, and then run this C# code:

char unicodechar = '\u73a9';  // Chinese character for father, man
string unicodeString = unicodechar.ToString();
string s = trimPINVOKE.myTestFunc(unicodeString);
Assert.AreEqual(s, unicodeString);

s will be "?", rather than the Unicode string that was passed in.

Discussion