From 595e42b880bf080c2604b54edfd6415b08ec9b93 Mon Sep 17 00:00:00 2001 From: triton Date: Fri, 22 Mar 2013 16:22:38 +0000 Subject: [PATCH] Added native to managed marshaling of function pointers. --- src/Generator/Generators/CLI/CLIMarshal.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index 7138377f..6b2f614f 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -134,7 +134,16 @@ namespace Cxxi.Generators.CLI return typeMap.IsValueType; } - // TODO: How should function pointers behave here? + FunctionType function; + if (decl.Type.IsPointerTo(out function)) + { + Return.Write("safe_cast<{0}>(", typedef); + Return.Write("System::Runtime::InteropServices::Marshal::"); + Return.Write("GetDelegateForFunctionPointer("); + Return.Write("IntPtr({0}), {1}::typeid))",Context.ReturnVarName, + typedef.ToString().TrimEnd('^')); + return true; + } return decl.Type.Visit(this); }