Browse Source

Fixed marshaling of null UTF-32 wide strings.

Closes issue #606. Thanks to magnet31 for reporting the issue.
pull/609/head
Joao Matos 10 years ago
parent
commit
da56988266
  1. 3
      src/Runtime/Helpers.cs
  2. 1
      tests/Common/Common.Tests.cs
  3. 2
      tests/Common/Common.h

3
src/Runtime/Helpers.cs

@ -9,6 +9,9 @@ namespace CppSharp.Runtime @@ -9,6 +9,9 @@ namespace CppSharp.Runtime
{
public static string MarshalEncodedString(IntPtr ptr, Encoding encoding)
{
if (ptr == IntPtr.Zero)
return null;
var size = 0;
while (Marshal.ReadInt32(ptr, size) != 0)
size += sizeof(int);

1
tests/Common/Common.Tests.cs

@ -406,6 +406,7 @@ public class CommonTests : GeneratorTestFixture @@ -406,6 +406,7 @@ public class CommonTests : GeneratorTestFixture
var ws = new TestWideStrings();
var s = ws.WidePointer;
Assert.That(ws.WidePointer, Is.EqualTo("Hello"));
Assert.That(ws.WideNullPointer, Is.EqualTo(null));
}
[Test]

2
tests/Common/Common.h

@ -597,9 +597,11 @@ typedef const wchar_t * LPCWSTR; @@ -597,9 +597,11 @@ typedef const wchar_t * LPCWSTR;
struct DLL_API TestWideStrings
{
LPCWSTR GetWidePointer();
LPCWSTR GetWideNullPointer();
};
LPCWSTR TestWideStrings::GetWidePointer() { return L"Hello"; }
LPCWSTR TestWideStrings::GetWideNullPointer() { return 0; }
enum struct MyEnum { A, B, C };

Loading…
Cancel
Save