More marshalling

This commit is contained in:
Garry Newman 2016-10-26 10:43:08 +01:00
parent 43705fed86
commit 28a781d511
8 changed files with 4153 additions and 4147 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -154,52 +154,58 @@ namespace Generator
internal string InteropParameter( bool LargePack, bool includeMarshalling = false ) internal string InteropParameter( bool LargePack, bool includeMarshalling = false )
{ {
var ps = LargePack ? "" : ".PackSmall"; var ps = LargePack ? "" : ".PackSmall";
var marshalling = "";
if ( !NativeType.Contains( "_t" ) ) if ( !NativeType.Contains( "_t" ) )
ps = string.Empty; ps = string.Empty;
if ( TypeDef != null ) if ( TypeDef != null )
ps = string.Empty; ps = string.Empty;
if ( includeMarshalling ) if ( includeMarshalling )
{ {
if ( NativeType == "bool" ) marshalling = "[MarshalAs(UnmanagedType.U1)]";
if ( NativeType == "bool *" ) marshalling = "[MarshalAs(UnmanagedType.U1)]";
if ( TypeDef != null && TypeDef.NativeType.Contains( "_t" ) )
{
// if ( !TypeDef.NativeType.Contains( "*" ) )
// return $"{TypeDef.ManagedType} {Name}";
}
} }
if ( ShouldBeIntPtr ) if ( ShouldBeIntPtr )
return $"IntPtr /*{NativeType}*/ {Name}"; return $"IntPtr /*{NativeType}*/ {Name}".Trim();
if ( IsStructShouldBePassedAsRef ) if ( IsStructShouldBePassedAsRef )
return $"ref {ManagedType.Trim( '*', ' ' )}{ps} /*{NativeType}*/ {Name}"; return $"{marshalling} ref {ManagedType.Trim( '*', ' ' )}{ps} /*{NativeType}*/ {Name}".Trim();
if ( ShouldBePassedAsOut ) if ( ShouldBePassedAsOut )
return $"out {ManagedType.Trim( '*', ' ' )} /*{NativeType}*/ {Name}"; return $"{marshalling} out {ManagedType.Trim( '*', ' ' )} /*{NativeType}*/ {Name}".Trim();
if ( NativeType == "char *" || NativeType == "char **" ) if ( NativeType == "char *" || NativeType == "char **" )
{ {
return $"System.Text.StringBuilder /*{NativeType}*/ {Name}"; return $"System.Text.StringBuilder /*{NativeType}*/ {Name}".Trim();
} }
if ( TypeDef != null ) if ( TypeDef != null )
{ {
if ( NativeType.EndsWith( "*" ) ) if ( NativeType.EndsWith( "*" ) )
{ {
return $"IntPtr /*{NativeType}*/ {Name}"; return $"IntPtr /*{NativeType}*/ {Name}".Trim();
} }
else else
{ {
return $"{TypeDef.Name} /*{NativeType}*/ {Name}"; return $"{marshalling} {TypeDef.Name} /*{NativeType}*/ {Name}".Trim();
} }
} }
if ( NativeType.EndsWith( "*" ) && ManagedType.Contains( "_t" ) ) if ( NativeType.EndsWith( "*" ) && ManagedType.Contains( "_t" ) )
{ {
return $"IntPtr /*{NativeType}*/ {Name} "; return $"IntPtr /*{NativeType}*/ {Name} ".Trim();
} }
return $"{ManagedType} /*{NativeType}*/ {Name} "; return $"{marshalling} {ManagedType} /*{NativeType}*/ {Name} ".Trim();
} }
internal string Return() internal string Return()

View File

@ -173,7 +173,7 @@ namespace Generator
WriteLine( $"[DllImportAttribute( \"{library}\", EntryPoint = \"{flatName}\" )]" ); WriteLine( $"[DllImportAttribute( \"{library}\", EntryPoint = \"{flatName}\" )]" );
if ( ret.Return() == "bool" )WriteLine( "[return: MarshalAs(UnmanagedType.Bool)]" ); if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
WriteLine( $"internal static extern {ret.Return()} {methodName}({argstring});" ); WriteLine( $"internal static extern {ret.Return()} {methodName}({argstring});" );
LastMethodName = methodDef.Name; LastMethodName = methodDef.Name;