|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Text; |
|
|
|
using CppSharp.AST; |
|
|
|
using CppSharp.AST; |
|
|
|
using CppSharp.Types; |
|
|
|
using CppSharp.Types; |
|
|
|
using Type = CppSharp.AST.Type; |
|
|
|
using Type = CppSharp.AST.Type; |
|
|
|
@ -133,8 +134,7 @@ namespace CppSharp.Generators.CSharp |
|
|
|
|
|
|
|
|
|
|
|
if (CSharpTypePrinter.IsConstCharString(pointer)) |
|
|
|
if (CSharpTypePrinter.IsConstCharString(pointer)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Context.Return.Write("Marshal.PtrToStringUni({0})", |
|
|
|
Context.Return.Write(MarshalStringToManaged(Context.ReturnVarName)); |
|
|
|
Context.ReturnVarName); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -151,6 +151,21 @@ namespace CppSharp.Generators.CSharp |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string MarshalStringToManaged(string varName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (Equals(Context.Driver.Options.Encoding, Encoding.ASCII)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return string.Format("Marshal.PtrToStringAnsi({0})", varName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (Equals(Context.Driver.Options.Encoding, Encoding.Unicode) || |
|
|
|
|
|
|
|
Equals(Context.Driver.Options.Encoding, Encoding.BigEndianUnicode)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return string.Format("Marshal.PtrToStringUni({0})", varName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new NotSupportedException(string.Format("{0} is not supported yet.", |
|
|
|
|
|
|
|
Context.Driver.Options.Encoding.EncodingName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals) |
|
|
|
public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (primitive) |
|
|
|
switch (primitive) |
|
|
|
@ -359,8 +374,8 @@ namespace CppSharp.Generators.CSharp |
|
|
|
type.IsPrimitiveType(PrimitiveType.WideChar)) && |
|
|
|
type.IsPrimitiveType(PrimitiveType.WideChar)) && |
|
|
|
pointer.QualifiedPointee.Qualifiers.IsConst) |
|
|
|
pointer.QualifiedPointee.Qualifiers.IsConst) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Context.Return.Write("Marshal.StringToHGlobalUni({0})", |
|
|
|
Context.Return.Write(this.MarshalStringToUnmanaged( |
|
|
|
Helpers.SafeIdentifier(Context.Parameter.Name)); |
|
|
|
Helpers.SafeIdentifier(Context.Parameter.Name))); |
|
|
|
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", |
|
|
|
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", |
|
|
|
Helpers.SafeIdentifier(Context.ArgName)); |
|
|
|
Helpers.SafeIdentifier(Context.ArgName)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
@ -402,6 +417,21 @@ namespace CppSharp.Generators.CSharp |
|
|
|
return pointee.Visit(this, quals); |
|
|
|
return pointee.Visit(this, quals); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string MarshalStringToUnmanaged(string varName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (Equals(Context.Driver.Options.Encoding, Encoding.ASCII)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return string.Format("Marshal.StringToHGlobalAnsi({0})", varName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (Equals(Context.Driver.Options.Encoding, Encoding.Unicode) || |
|
|
|
|
|
|
|
Equals(Context.Driver.Options.Encoding, Encoding.BigEndianUnicode)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return string.Format("Marshal.StringToHGlobalUni({0})", varName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new NotSupportedException(string.Format("{0} is not supported yet.", |
|
|
|
|
|
|
|
Context.Driver.Options.Encoding.EncodingName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals) |
|
|
|
public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers quals) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (primitive) |
|
|
|
switch (primitive) |
|
|
|
|