Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. convert c++ function pointer to c# delegate

convert c++ function pointer to c# delegate

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpc++performancehelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adi Arbel
    wrote on last edited by
    #1

    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

    C P 2 Replies Last reply
    0
    • A Adi Arbel

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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++

      A 1 Reply Last reply
      0
      • A Adi Arbel

        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

        P Offline
        P Offline
        Pradyumna Gogte
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • P Pradyumna Gogte

          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

          A Offline
          A Offline
          Adi Arbel
          wrote on last edited by
          #4

          thanks Prady, but... unfortunately, i can not iclude the callback functions as members of the c# wrapper, because those are external functions writen by users of the product. any other ideas?

          1 Reply Last reply
          0
          • C Christian Graus

            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++

            A Offline
            A Offline
            Adi Arbel
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • A Adi Arbel

              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

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              No, not unless it's managed C++, then they can work together. Otherwise, I doubt it. Christian Graus - Microsoft MVP - C++

              A 1 Reply Last reply
              0
              • C Christian Graus

                No, not unless it's managed C++, then they can work together. Otherwise, I doubt it. Christian Graus - Microsoft MVP - C++

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                My wrapper (between the .Net customers and the unmanaged C++ product) is in Managed C++. is it making it any better?

                C 1 Reply Last reply
                0
                • A Anonymous

                  My wrapper (between the .Net customers and the unmanaged C++ product) is in Managed C++. is it making it any better?

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  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++

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups