convert c++ function pointer to c# delegate
-
hi everybody, i am wrapping some services written in c++ for .Net customers. because of performance reasons, i chose to do it was to write for each routine in c++ a analogous routine in c#, and do the same for all my own types. here is the problem: i have routine in c++ which one of its parameters is function pointer, and i would to give the C# user the ability to send a delegate that will take place exactly as the C++ user uses is own function. i was looking for solution all over the net with good enough answer for me. i also understand that normally there is no function pointer in c#. the question again in few words: how can i wrap c++ function pointer parameter by equivalent C# parameter? thanks in advance. adi
-
hi everybody, i am wrapping some services written in c++ for .Net customers. because of performance reasons, i chose to do it was to write for each routine in c++ a analogous routine in c#, and do the same for all my own types. here is the problem: i have routine in c++ which one of its parameters is function pointer, and i would to give the C# user the ability to send a delegate that will take place exactly as the C++ user uses is own function. i was looking for solution all over the net with good enough answer for me. i also understand that normally there is no function pointer in c#. the question again in few words: how can i wrap c++ function pointer parameter by equivalent C# parameter? thanks in advance. adi
Adi Arbel wrote: i also understand that normally there is no function pointer in c#. A delegate is a function pointer, in essence. I'm not sure how you would pass a function pointer, it's a pointer to an address in the C++ exe, or at least an address that C++ can use. pinvoke.net could be a good place to look. Christian Graus - Microsoft MVP - C++
-
hi everybody, i am wrapping some services written in c++ for .Net customers. because of performance reasons, i chose to do it was to write for each routine in c++ a analogous routine in c#, and do the same for all my own types. here is the problem: i have routine in c++ which one of its parameters is function pointer, and i would to give the C# user the ability to send a delegate that will take place exactly as the C++ user uses is own function. i was looking for solution all over the net with good enough answer for me. i also understand that normally there is no function pointer in c#. the question again in few words: how can i wrap c++ function pointer parameter by equivalent C# parameter? thanks in advance. adi
Hi Adi, Deligates may not be the correct solution for you. As deligates are typically used for even handling. What you would require is a c# wrapper for your c++ code and some of the members of this c# wrapper would be callback functions. Now these call back functions you can pass as parameters to functions. Cheers, Prady
-
Hi Adi, Deligates may not be the correct solution for you. As deligates are typically used for even handling. What you would require is a c# wrapper for your c++ code and some of the members of this c# wrapper would be callback functions. Now these call back functions you can pass as parameters to functions. Cheers, Prady
-
Adi Arbel wrote: i also understand that normally there is no function pointer in c#. A delegate is a function pointer, in essence. I'm not sure how you would pass a function pointer, it's a pointer to an address in the C++ exe, or at least an address that C++ can use. pinvoke.net could be a good place to look. Christian Graus - Microsoft MVP - C++
Hi Christian, Thanks for your answer, but it seems to be that i have to make clear few things: I want that my unmanaged code (product written in c++) will be able to get a pointer to managed function (supplied by the .net customer) and activate it. Do u think it is possible? any ideas? Thanks again! Adi
-
Hi Christian, Thanks for your answer, but it seems to be that i have to make clear few things: I want that my unmanaged code (product written in c++) will be able to get a pointer to managed function (supplied by the .net customer) and activate it. Do u think it is possible? any ideas? Thanks again! Adi
No, not unless it's managed C++, then they can work together. Otherwise, I doubt it. Christian Graus - Microsoft MVP - C++
-
No, not unless it's managed C++, then they can work together. Otherwise, I doubt it. Christian Graus - Microsoft MVP - C++
-
My wrapper (between the .Net customers and the unmanaged C++ product) is in Managed C++. is it making it any better?
Yeah, it may well do. Your MC++ code should be able to use the delegates directly, I would have thought. Christian Graus - Microsoft MVP - C++