Click here to Skip to main content
15,121,505 members
Articles / Programming Languages / C#
Tip/Trick
Posted 26 Jun 2011

Tagged as

Stats

21.5K views
5 bookmarked

Creating delegate from a function pointer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
26 Jun 2011CPOL
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)

Share

About the Author

Mukit, Ataul
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Comments and Discussions

 
QuestionCalling Service written in C, from C# Pin
Muneeb R. Baig4-Jul-11 12:54
MemberMuneeb R. Baig4-Jul-11 12:54 
AnswerRe: Calling Service written in C, from C# Pin
Mukit, Ataul4-Jul-11 20:44
MemberMukit, Ataul4-Jul-11 20:44 
QuestionRe: Calling Service written in C, from C# Pin
Muneeb R. Baig4-Jul-11 20:58
MemberMuneeb R. Baig4-Jul-11 20:58 
AnswerRe: Calling Service written in C, from C# Pin
Mukit, Ataul4-Jul-11 21:08
MemberMukit, Ataul4-Jul-11 21:08 
GeneralRe: Calling Service written in C, from C# Pin
Muneeb R. Baig4-Jul-11 21:13
MemberMuneeb R. Baig4-Jul-11 21:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.