diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index b9568359..c3c9e76c 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -1101,7 +1101,12 @@ namespace CppSharp.Generators.CLI var type = paramType.Visit(typePrinter); if (param.IsInOut) + { + if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore)) + Write(marshal.Context.SupportBefore); + WriteLine("{0} {1} = {2};", type, argName, marshal.Context.Return); + } else WriteLine("{0} {1};", type, argName); } diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 34198090..0366c35d 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -435,6 +435,11 @@ namespace CppSharp.Generators.CSharp Context.Return.Write("IntPtr.Zero"); CSharpContext.ArgumentPrefix.Write("&"); } + else if (Context.Parameter.IsInOut) + { + Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name)); + CSharpContext.ArgumentPrefix.Write("&"); + } else { Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name)); diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index 7893748e..cb9eac03 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -67,6 +67,9 @@ public class BasicTests : GeneratorTestFixture Assert.That(str, Is.EqualTo("HelloStringOut")); hello.StringOutRef(out str); Assert.That(str, Is.EqualTo("HelloStringOutRef")); + str = "Hello"; + hello.StringInOut(ref str); + Assert.That(str, Is.EqualTo("StringInOut")); } [Test] diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index c992e5ee..e405f60d 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -1,4 +1,5 @@ #include "Basic.h" +#include Foo::Foo() { @@ -213,6 +214,14 @@ void Hello::StringOutRef(CS_OUT const char*& str) str = "HelloStringOutRef"; } +void Hello::StringInOut(CS_IN_OUT const char** str) +{ + if (strcmp(*str, "Hello") == 0) + *str = "StringInOut"; + else + *str = "Failed"; +} + int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int)) { return ret.A; diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 7dcd7d65..9f7318eb 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -135,6 +135,8 @@ public: void StringOut(CS_OUT const char** str); void StringOutRef(CS_OUT const char*& str); + void StringInOut(CS_IN_OUT const char** str); + //void StringInOutRef(CS_OUT const char*& str); }; class DLL_API AbstractFoo