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