Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Creating delegate from a function pointer

5.00/5 (4 votes)
26 Jun 2011CPOL 23.9K  
This tip shows you how to create a delegate from a C++ function pointer
C#
//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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)