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. Managed C++/CLI
  4. Preserving polymorphism across the managed/unmanaged boundary

Preserving polymorphism across the managed/unmanaged boundary

Scheduled Pinned Locked Moved Managed C++/CLI
c++oopquestion
3 Posts 3 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.
  • M Offline
    M Offline
    Member 10167731
    wrote on last edited by
    #1

    I have a legacy C++ native code application that implements a class hierachy with some inheritance. I have to re-implement the application within a managed framework. TI would like to reuse the unmanged class hierarchy from the managed application and still benefit from the polymorphism built in to my unmanaged class hierarchy. Do I have to write a C++/CLI wrapper for each unmanaged class in the hierarchy and duplicate the inheritance structure within the wrappers?

    D J 2 Replies Last reply
    0
    • M Member 10167731

      I have a legacy C++ native code application that implements a class hierachy with some inheritance. I have to re-implement the application within a managed framework. TI would like to reuse the unmanged class hierarchy from the managed application and still benefit from the polymorphism built in to my unmanaged class hierarchy. Do I have to write a C++/CLI wrapper for each unmanaged class in the hierarchy and duplicate the inheritance structure within the wrappers?

      D Offline
      D Offline
      David Knechtges
      wrote on last edited by
      #2

      You might do it that way, but it might actually be better to put the native parts into managed DLLs using the wrappers and then using the DLLs from your managed application. It all depends on what you are trying to do. I wouldn't get too wrapped up in trying to preserve the old hierarchy in the managed world though.

      1 Reply Last reply
      0
      • M Member 10167731

        I have a legacy C++ native code application that implements a class hierachy with some inheritance. I have to re-implement the application within a managed framework. TI would like to reuse the unmanged class hierarchy from the managed application and still benefit from the polymorphism built in to my unmanaged class hierarchy. Do I have to write a C++/CLI wrapper for each unmanaged class in the hierarchy and duplicate the inheritance structure within the wrappers?

        J Offline
        J Offline
        John Schroedl
        wrote on last edited by
        #3

        Assuming that you really do need to expose the full class hierarchy as managed types to managed code then yes, I think you're left duplicating the hierarchy with wrapper ref classes. If the client managed application is also guaranteed to be C++/CLI (and not C#) it could #include the native class hierarchy intact and use it directly. If you want to allow C# then I'd use wrapper classes with the PIMPL idiom. Also, hopefully your native classes don't use multiple inheritance since a managed class can only have one non-interface base class. John

        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