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. C++ to Managed CLI

C++ to Managed CLI

Scheduled Pinned Locked Moved Managed C++/CLI
c++csharpdotnethelpquestion
9 Posts 2 Posters 2 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
    sunshine work
    wrote on last edited by
    #1

    Hi, i am working on a project using C and C++. But now i have to use lil bit of C# code in it.So i made a sample application , converted all the c# code to managed C++/CLI.I changed the properties of sample app to Clr support.It worked fine. But in my current project, i have some pure c classes also. So when i was changing the property of my project to CLR , it gave me error of xyz.c file cannot convert into \clr. I dont know wat to do?i cannot convert xyz.c class into xyz.cpp Can anyone suggest what should i do... Is it possible that i mange to use mannaged c++ also and i still donot have to convert the whole project into CLR.

    L 1 Reply Last reply
    0
    • S sunshine work

      Hi, i am working on a project using C and C++. But now i have to use lil bit of C# code in it.So i made a sample application , converted all the c# code to managed C++/CLI.I changed the properties of sample app to Clr support.It worked fine. But in my current project, i have some pure c classes also. So when i was changing the property of my project to CLR , it gave me error of xyz.c file cannot convert into \clr. I dont know wat to do?i cannot convert xyz.c class into xyz.cpp Can anyone suggest what should i do... Is it possible that i mange to use mannaged c++ also and i still donot have to convert the whole project into CLR.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You could convert the C code into a DLL which you can then access via P/Invoke from the CLR portion. Unfortunately you cannot convert pure C code to CLR.

      S 2 Replies Last reply
      0
      • L Lost User

        You could convert the C code into a DLL which you can then access via P/Invoke from the CLR portion. Unfortunately you cannot convert pure C code to CLR.

        S Offline
        S Offline
        sunshine work
        wrote on last edited by
        #3

        Hi,Thanks for the reply. I managed to do it by adding a new CLR class and putting all my C Sharp code to it.Automaticaly VS ask me that wether i would like to convert by my code to CLR.Then it converts all my code to CLR without giving any compile error :). Regards Shubh

        1 Reply Last reply
        0
        • L Lost User

          You could convert the C code into a DLL which you can then access via P/Invoke from the CLR portion. Unfortunately you cannot convert pure C code to CLR.

          S Offline
          S Offline
          sunshine work
          wrote on last edited by
          #4

          Hi Richard .. I posted my problem i tried diffrent ways to solve it..like i told you that i found a temporary way to resolve my problem. But that is not proper solution. You know what that now i am thinking to use my CLI/C++ code as dll .To call the function in that dll, do i need a wrapper class in my unamanged c++ code .If yes then can you give me an idea or post to implment it.I havenot used wrapper classes before. Is there any other way to call dll functions.Need your guidance.Thanks in advance.

          L 1 Reply Last reply
          0
          • S sunshine work

            Hi Richard .. I posted my problem i tried diffrent ways to solve it..like i told you that i found a temporary way to resolve my problem. But that is not proper solution. You know what that now i am thinking to use my CLI/C++ code as dll .To call the function in that dll, do i need a wrapper class in my unamanged c++ code .If yes then can you give me an idea or post to implment it.I havenot used wrapper classes before. Is there any other way to call dll functions.Need your guidance.Thanks in advance.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            As I suggested before, you could just make all your unmanaged copde into a standard DLL. You can then access the functions directly via P/Invoke[^]. I am not exactly sure what you are trying to do with the C code, and whether it would not be better just to convert it all to C#.

            S 1 Reply Last reply
            0
            • L Lost User

              As I suggested before, you could just make all your unmanaged copde into a standard DLL. You can then access the functions directly via P/Invoke[^]. I am not exactly sure what you are trying to do with the C code, and whether it would not be better just to convert it all to C#.

              S Offline
              S Offline
              sunshine work
              wrote on last edited by
              #6

              Hey i dont think ,i made my point clear to you.Actually this thing is completely new to me.Thats why i am unable to explain it corectly. I have unmanaged c++ code. But now in that i need to use some of the managed i.e C++/CLI code. That is my main problem :confused: :( . I tried to search solutions on internet but these solutions made me more :~ confused. One of the solution said , i should make dll of the managed code .Then i should make one wrapper to call the functions of the dll.Should i do that. Can't i directly use the functions of dll in my c++ unmanged code like withe help of GetProcAddtress() without any wrapper class.I am new to all this. Please Help.I need it :sigh: .

              L 1 Reply Last reply
              0
              • S sunshine work

                Hey i dont think ,i made my point clear to you.Actually this thing is completely new to me.Thats why i am unable to explain it corectly. I have unmanaged c++ code. But now in that i need to use some of the managed i.e C++/CLI code. That is my main problem :confused: :( . I tried to search solutions on internet but these solutions made me more :~ confused. One of the solution said , i should make dll of the managed code .Then i should make one wrapper to call the functions of the dll.Should i do that. Can't i directly use the functions of dll in my c++ unmanged code like withe help of GetProcAddtress() without any wrapper class.I am new to all this. Please Help.I need it :sigh: .

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I'm afraid it is still not clear exactly what you are trying to do and why you need to mix managed and unmanaged code. I have already explained that you can use the functions of an unmanaged DLL in managed code by using the P/Invoke mechanism (link given in my previous answer). If that does not, or will not work, then you need to give an example of your code and explain what the problem is.

                S 1 Reply Last reply
                0
                • L Lost User

                  I'm afraid it is still not clear exactly what you are trying to do and why you need to mix managed and unmanaged code. I have already explained that you can use the functions of an unmanaged DLL in managed code by using the P/Invoke mechanism (link given in my previous answer). If that does not, or will not work, then you need to give an example of your code and explain what the problem is.

                  S Offline
                  S Offline
                  sunshine work
                  wrote on last edited by
                  #8

                  Okay , i will tell you.What is my problem. Actually i need to use powershell apis , in my c++ code.As i need to find out the no .of servers in my appfabric cluster. So the challenge was how to acess powershell in c++ code. I had one c# code in which i was able to acess powershell properly. It gives me every information i need to find out..Like wether the appfabric service is running or not.How many servers in cluster.All the info. Now as my code is in c++ , my biggest challenge is using the c# script in c++,because that scripts works wonder for me. So to use that i converted whole of C# code into C++/CLI so that i can use it in my current unmanged c++ code. Now the problem is adding that C++/CLI code into UNMANAGED CODE so that i can acess powershell in c++. How to do that mixed mode programming?

                  L 1 Reply Last reply
                  0
                  • S sunshine work

                    Okay , i will tell you.What is my problem. Actually i need to use powershell apis , in my c++ code.As i need to find out the no .of servers in my appfabric cluster. So the challenge was how to acess powershell in c++ code. I had one c# code in which i was able to acess powershell properly. It gives me every information i need to find out..Like wether the appfabric service is running or not.How many servers in cluster.All the info. Now as my code is in c++ , my biggest challenge is using the c# script in c++,because that scripts works wonder for me. So to use that i converted whole of C# code into C++/CLI so that i can use it in my current unmanged c++ code. Now the problem is adding that C++/CLI code into UNMANAGED CODE so that i can acess powershell in c++. How to do that mixed mode programming?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    I think Calling Managed Code from Unmanaged Code and vice-versa[^] may be what you are looking for.

                    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