Browse Source

Added UnmanagedFunctionPointerAttribute to generated delegates to avoid run-time crashes.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/48/head
Dimitar Dobrev 12 years ago
parent
commit
fbe5851237
  1. 5
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

5
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1849,15 +1849,16 @@ namespace CppSharp.Generators.CSharp
TagType tag; TagType tag;
if (typedef.Type.IsPointerToPrimitiveType(PrimitiveType.Void) if (typedef.Type.IsPointerToPrimitiveType(PrimitiveType.Void)
|| typedef.Type.IsPointerTo<TagType>(out tag)) || typedef.Type.IsPointerTo(out tag))
{ {
PushBlock(CSharpBlockKind.Typedef); PushBlock(CSharpBlockKind.Typedef);
WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }"); WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }");
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
else if (typedef.Type.IsPointerTo<FunctionType>(out function)) else if (typedef.Type.IsPointerTo(out function))
{ {
PushBlock(CSharpBlockKind.Typedef); PushBlock(CSharpBlockKind.Typedef);
WriteLine("[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]");
WriteLine("public {0};", WriteLine("public {0};",
string.Format(TypePrinter.VisitDelegate(function).Type, string.Format(TypePrinter.VisitDelegate(function).Type,
SafeIdentifier(typedef.Name))); SafeIdentifier(typedef.Name)));

Loading…
Cancel
Save