65.9K
CodeProject is changing. Read more.
Home

Creating delegate from a function pointer

starIconstarIconstarIconstarIconstarIcon

5.00/5 (4 votes)

Jun 27, 2011

CPOL
viewsIcon

24017

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.