Hi,
I have the following callback registration function in my Native dll
And in my managed C++ code I write,Code:typedef void (*IpOptMsg)(LPARAM lParam, int ipoptMsg, LPARAM lParamStruct); void NLPRegisterCallback( IpOptMsg fnMsg);
I don't get any compilation error, my after running my code I get an exception saying the memory is corrupt.Code:public ref class LibWrap { public: delegate void EvaluateObjective(IntPtr lParam, int ipoptMsg, IntPtr lParamStruct); [DllImport("demo.dll", CallingConvention = CallingConvention::Cdecl)] static void IpOptNLPRegisterCallback(IntPtr lParam, EvaluateObjective^ fnMsg, IntPtr lParamStruct); }; int main(array<System::String ^> ^args) { LibWrap::EvaluateObjective^ evalObjective; LibWrap::IpOptNLPRegisterCallback(handle,evalObjective, IntPtr::Zero); }
In C# I do the same thing as - and it works fine!
Thanks in advance!Code:[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] public delegate void EvaluateObjective(IntPtr lParam, uint ipoptMsg, IntPtr lParamStruct); [DllImport("demo.dll", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern void IpOptNLPRegisterCallback(IntPtr lParam, EvaluateObjective fnMsg, IntPtr lParamStruct);


Reply With Quote
