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#
  4. using C# code in VC++(MFC) application

using C# code in VC++(MFC) application

Scheduled Pinned Locked Moved C#
csharpc++designquestion
7 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
    Shailesh Ha
    wrote on last edited by
    #1

    I am new to Dot Net.I have a VC++(MFC) application. I want to add better user interface to my application using c# or may be VB.Net. Which are the different ways i can do it??...can C++ code call C# code ?? should i implement as C# dll ??...or are there any other ways i can do it? looking forward for reply thankx in advance Shailesh

    J K 2 Replies Last reply
    0
    • S Shailesh Ha

      I am new to Dot Net.I have a VC++(MFC) application. I want to add better user interface to my application using c# or may be VB.Net. Which are the different ways i can do it??...can C++ code call C# code ?? should i implement as C# dll ??...or are there any other ways i can do it? looking forward for reply thankx in advance Shailesh

      J Offline
      J Offline
      Jun Du
      wrote on last edited by
      #2

      Shailesh Halankar wrote:

      ...can C++ code call C# code ??

      No, C++ cannot call C# directly. They cannot coexist in the same project.

      Shailesh Halankar wrote:

      should i implement as C# dll ??

      Yes. Two DLLs written in different .NET-compilant languages can coexist in the same solution and they can reference to each other.

      Shailesh Halankar wrote:

      ...or are there any other ways i can do it?

      Not any better ones I have known of. - It's easier to make than to correct a mistake.

      S 1 Reply Last reply
      0
      • S Shailesh Ha

        I am new to Dot Net.I have a VC++(MFC) application. I want to add better user interface to my application using c# or may be VB.Net. Which are the different ways i can do it??...can C++ code call C# code ?? should i implement as C# dll ??...or are there any other ways i can do it? looking forward for reply thankx in advance Shailesh

        K Offline
        K Offline
        Koushik Biswas
        wrote on last edited by
        #3

        It is easier said than done. Firstly, take a look at this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkcominteroppart2cservertutorial.asp[^]. It will tell you that in order for C++ to call C#, the C# assembly should be written in such a way that C++ can treat it as a COM object. In your case, you want the UI part to be in C#, and for business logic and processing part you want to continue the C++ MFC code. So the better way is to do the opposite - make the C# call your existing C++ code. Create a new C# project, create your UI, and when it is time to code the business logic, make calls to a C++ DLL. Convert your C++ code to a COM object. Then you can call it directly from your C# application. See here on how to do that:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkCOMInteropPart1CClientTutorial.asp?frame=true[^] Now if you are too lazy to do COM, and if your C++ MFC code is not really so gigantic, you can consider a re-write. Create a C# project, create your desired flashy cool UI, and type in the business logic part in C# as well. As you have said "I am new to Dot Net" - by doing so you will be 1 step farther from calling yourself "new"...:-D Koushik Biswas who else?

        S 1 Reply Last reply
        0
        • K Koushik Biswas

          It is easier said than done. Firstly, take a look at this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkcominteroppart2cservertutorial.asp[^]. It will tell you that in order for C++ to call C#, the C# assembly should be written in such a way that C++ can treat it as a COM object. In your case, you want the UI part to be in C#, and for business logic and processing part you want to continue the C++ MFC code. So the better way is to do the opposite - make the C# call your existing C++ code. Create a new C# project, create your UI, and when it is time to code the business logic, make calls to a C++ DLL. Convert your C++ code to a COM object. Then you can call it directly from your C# application. See here on how to do that:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkCOMInteropPart1CClientTutorial.asp?frame=true[^] Now if you are too lazy to do COM, and if your C++ MFC code is not really so gigantic, you can consider a re-write. Create a C# project, create your desired flashy cool UI, and type in the business logic part in C# as well. As you have said "I am new to Dot Net" - by doing so you will be 1 step farther from calling yourself "new"...:-D Koushik Biswas who else?

          S Offline
          S Offline
          Shailesh Ha
          wrote on last edited by
          #4

          Hello Thanks for your feedback I still wana clear certain things As u know my application is VC++ Doc-View application and, i want to create custom User controls like tree control in C# as a component DLL (may be) and want to add to my DOc View application frame. Is this possible? if not...which other way can i solve the problem My Problem is that i cannot rewrite the code as C# (as the VC APP is gigantic) thnks in Advance

          K 1 Reply Last reply
          0
          • S Shailesh Ha

            Hello Thanks for your feedback I still wana clear certain things As u know my application is VC++ Doc-View application and, i want to create custom User controls like tree control in C# as a component DLL (may be) and want to add to my DOc View application frame. Is this possible? if not...which other way can i solve the problem My Problem is that i cannot rewrite the code as C# (as the VC APP is gigantic) thnks in Advance

            K Offline
            K Offline
            Koushik Biswas
            wrote on last edited by
            #5

            Sorry you cannot. Reason is simple - a user control in the MFC document-view architechture interacts with the framework using a unique messaging system. It is just not an external assembly that you plug in. The design is from Microsoft days when .NET was not there. A C# assembly can give you a GUI, but you cannot display it from a VC++ MFC document-view project. At least I am not aware of any miracle that will let you do that. Now coming to what practical alternatives you have. Firstly, believe me the C# tree control is not that great a control. It has numerous limitations that will frustrate you immensely. The very concept of a cool control that lets you do plenty of bells and whistles might have resulted in your brain being "c-sharpized". With some searching and luck, you will find numerous complex user controls/ Activex objects developed in C++ that you can highly use in your project seamlessly. If it is not a binding to use C# (which you can't), you may look around for cool controls developed in VC++. Codeproject has many, and other forums have many too. If you are more specific about the exact kind of control that you want, I can do some parallel searching too, if you don't mind that is ;) Koushik Biswas who else?

            S 1 Reply Last reply
            0
            • K Koushik Biswas

              Sorry you cannot. Reason is simple - a user control in the MFC document-view architechture interacts with the framework using a unique messaging system. It is just not an external assembly that you plug in. The design is from Microsoft days when .NET was not there. A C# assembly can give you a GUI, but you cannot display it from a VC++ MFC document-view project. At least I am not aware of any miracle that will let you do that. Now coming to what practical alternatives you have. Firstly, believe me the C# tree control is not that great a control. It has numerous limitations that will frustrate you immensely. The very concept of a cool control that lets you do plenty of bells and whistles might have resulted in your brain being "c-sharpized". With some searching and luck, you will find numerous complex user controls/ Activex objects developed in C++ that you can highly use in your project seamlessly. If it is not a binding to use C# (which you can't), you may look around for cool controls developed in VC++. Codeproject has many, and other forums have many too. If you are more specific about the exact kind of control that you want, I can do some parallel searching too, if you don't mind that is ;) Koushik Biswas who else?

              S Offline
              S Offline
              Shailesh Ha
              wrote on last edited by
              #6

              Hello Was nice to get a reply from u. Ill think about the options u told me. Another issue that i wana discuss with u is that of connectivity to the net. How can i use ASP.net to connect my VC MFC application to the net. Also if i want to make my application as Web applcation wat provisions do i have in Dot Net. Thank you ;) regards Shailesh

              1 Reply Last reply
              0
              • J Jun Du

                Shailesh Halankar wrote:

                ...can C++ code call C# code ??

                No, C++ cannot call C# directly. They cannot coexist in the same project.

                Shailesh Halankar wrote:

                should i implement as C# dll ??

                Yes. Two DLLs written in different .NET-compilant languages can coexist in the same solution and they can reference to each other.

                Shailesh Halankar wrote:

                ...or are there any other ways i can do it?

                Not any better ones I have known of. - It's easier to make than to correct a mistake.

                S Offline
                S Offline
                Shailesh Ha
                wrote on last edited by
                #7

                HELLO Thanks for your reply.. I also want to discuss another thing or 2 with u First is can i implement my C# developed UI component as a COM and call it from my VC.Net MFC aplication (as u said that VC.Net (mfc) application cannot call a C# DLL).... Also If i want to give Net connectivity to my VC.Net MFC application i.e to be able to upload certain files over the network may be, then how can i do it in Dot net.Can i use Asp.net or ne other way?? thankx regards Shailesh

                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