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. C / C++ / MFC
  4. Don't understand what's required in order to use unmgd c++ class in c# app - help?

Don't understand what's required in order to use unmgd c++ class in c# app - help?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++helptutorialquestion
6 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.
  • S Offline
    S Offline
    sherifffruitfly
    wrote on last edited by
    #1

    Hi all, I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application. What's the simplest way to do this? I've looked up resources, but they all appear to me more complicated than my basic level of understanding of MS C++ will allow to be helpful to me. Can someone point me to a very simple recipe (and hopefully simple explanation too) on how to turn this unmanaged class into one which c# can use? Also, will there be issues about "return data type matching" between c++ and c#? Thanks, cdj

    M C 2 Replies Last reply
    0
    • S sherifffruitfly

      Hi all, I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application. What's the simplest way to do this? I've looked up resources, but they all appear to me more complicated than my basic level of understanding of MS C++ will allow to be helpful to me. Can someone point me to a very simple recipe (and hopefully simple explanation too) on how to turn this unmanaged class into one which c# can use? Also, will there be issues about "return data type matching" between c++ and c#? Thanks, cdj

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You may want to post your question(s) on the C# board[^] as well! Mark

      Mark Salsbery Microsoft MVP - Visual C++

      S 1 Reply Last reply
      0
      • S sherifffruitfly

        Hi all, I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application. What's the simplest way to do this? I've looked up resources, but they all appear to me more complicated than my basic level of understanding of MS C++ will allow to be helpful to me. Can someone point me to a very simple recipe (and hopefully simple explanation too) on how to turn this unmanaged class into one which c# can use? Also, will there be issues about "return data type matching" between c++ and c#? Thanks, cdj

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

        sherifffruitfly wrote:

        I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application.

        Then you need to compile it into a DLL, either COM or just standard. You can in both cases easily import your DLL into C# ( the plain dll via a p/invoke signature for each method you want to call ), but the COM way allows you to create class instances, p/invoke does not.

        sherifffruitfly wrote:

        Also, will there be issues about "return data type matching" between c++ and c#?

        If you use COM, then the IDE will fix that for you, if you use a dll, then you need to work it out for each method, for both return values, and values going in. By far the most intelligent thing to do is to make your code managed, so you can create class instances and fully interact with them in C#.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        S 1 Reply Last reply
        0
        • C Christian Graus

          sherifffruitfly wrote:

          I've got the source code and compiled binary for a c++ class library, and I'd like to be able to instantiate & use the class in a c# application.

          Then you need to compile it into a DLL, either COM or just standard. You can in both cases easily import your DLL into C# ( the plain dll via a p/invoke signature for each method you want to call ), but the COM way allows you to create class instances, p/invoke does not.

          sherifffruitfly wrote:

          Also, will there be issues about "return data type matching" between c++ and c#?

          If you use COM, then the IDE will fix that for you, if you use a dll, then you need to work it out for each method, for both return values, and values going in. By far the most intelligent thing to do is to make your code managed, so you can create class instances and fully interact with them in C#.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          S Offline
          S Offline
          sherifffruitfly
          wrote on last edited by
          #4

          I want instances, so I guess the COM compilation is what would be helpful. I'll look up how to do that. The way I did it, I believe it's "just standard": #ifndef DllExport #define DllExport __declspec( dllexport ) #endif ... class DllExport {...} Thanks for the suggestions!

          1 Reply Last reply
          0
          • M Mark Salsbery

            You may want to post your question(s) on the C# board[^] as well! Mark

            Mark Salsbery Microsoft MVP - Visual C++

            S Offline
            S Offline
            sherifffruitfly
            wrote on last edited by
            #5

            We'll see how it goes here; if necessary, I will. Thanks!

            M 1 Reply Last reply
            0
            • S sherifffruitfly

              We'll see how it goes here; if necessary, I will. Thanks!

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Well the person I know would have an answer replied here so...cool! Good luck! Mark

              Mark Salsbery Microsoft MVP - Visual 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