Creating delegate from a function pointer





5.00/5 (4 votes)
This tip shows you how to create a delegate from a C++ function pointer
//Assume you have managed to somehow pass a function pointer from C++ as Cplussplusfunctionptr to C#. In my case I was lucky, becoz I had managed C++ as a mid layer to convert void* to IntPtr;
IntPtr func = Cplussplusfunctionptr;
GuiFactoryOnNotify delegateOnNotify = (GuiFactoryOnNotify)Marshal.GetDelegateForFunctionPointer
(func, typeof(GuiFactoryOnNotify));
Thanks to cory nelson in stack overflow for the original tip.