Browse Source

Added support for Unicode when marshalling strings.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/60/head
Dimitar Dobrev 13 years ago
parent
commit
de4879f108
  1. 4
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 11
      tests/Basic/Basic.Tests.cs
  3. 2
      tests/Basic/Basic.h

4
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -133,7 +133,7 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -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));

11
tests/Basic/Basic.Tests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using NUnit.Framework;
using Basic;
@ -103,5 +103,14 @@ public class BasicTests @@ -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));
}
}

2
tests/Basic/Basic.h

@ -11,6 +11,8 @@ public: @@ -11,6 +11,8 @@ public:
Foo();
int A;
float B;
const char* Unicode;
};
class DLL_API Foo2 : public Foo

Loading…
Cancel
Save