diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 6d414ef3..f523e0c4 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -133,7 +133,7 @@ namespace CppSharp.Generators.CSharp if (CSharpTypePrinter.IsConstCharString(pointer)) { - Context.Return.Write("Marshal.PtrToStringAnsi({0})", + Context.Return.Write("Marshal.PtrToStringUni({0})", Context.ReturnVarName); return true; } @@ -359,7 +359,7 @@ namespace CppSharp.Generators.CSharp type.IsPrimitiveType(PrimitiveType.WideChar)) && pointer.QualifiedPointee.Qualifiers.IsConst) { - Context.Return.Write("Marshal.StringToHGlobalAnsi({0})", + Context.Return.Write("Marshal.StringToHGlobalUni({0})", Helpers.SafeIdentifier(Context.Parameter.Name)); CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Helpers.SafeIdentifier(Context.ArgName)); diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index c08ec478..4c637d0f 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using NUnit.Framework; using Basic; @@ -103,5 +103,14 @@ public class BasicTests Assert.That(typeof(Foo2).GetProperty("P", BindingFlags.Instance | BindingFlags.NonPublic), Is.Not.Null); } + + [Test] + public void TestUnicode() + { + Foo foo = new Foo(); + const string georgia = "საქართველო"; + foo.Unicode = georgia; + Assert.That(foo.Unicode, Is.EqualTo(georgia)); + } } \ No newline at end of file diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 4426f829..ba9aa622 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -11,6 +11,8 @@ public: Foo(); int A; float B; + + const char* Unicode; }; class DLL_API Foo2 : public Foo