I am trying to pass a function pointer from C # to C ++ / CLI and get a Windows compiler error stating that the ManagedTakeCallback
function ManagedTakeCallback
not supported by this language (C #). I define a ManagedTakeCallback
in a C ++ / CLI interop. My code looks like
C # application:
namespace ManagedConsoleApplication { class Callback { public delegate double DelegateAdd(double value1, double value2); public static double CallbackAdd(double value1, double value2) { return value1 + value2; } public static DelegateAdd delegateCallback = new DelegateAdd(Callback.CallbackAdd);
and
C ++ / CLI interop dll h and cpp file:
//HEADER namespace Interop { typedef double (__stdcall *PCallback)(double value1, double value2); public ref class InteropDLL { public: double ManagedAdd(double value1, double value2); public: double ManagedTakeCallback(PCallback pCallback); }; } //CPP double Interop::InteropDLL::ManagedAdd(double value1, double value2) { return NativeAdd(value1, value2); } double Interop::InteropDLL::ManagedTakeCallback(PCallback pCallback) { return NativeTakeCallback(); }
Then the C ++ / CLI interaction layer calls the C DLL. I can call the interop function ManagedAdd
; however, if ManagedTakeCallback
added, a Windows compiler error occurs. I suspect that the C # application is not marching correctly in the function pointer through the ManagedTakeCallback
function ManagedTakeCallback
or that the signature does not match the C ++ / CLI side? I would really appreciate your understanding.
source share