I have a large amount of code for an MFC/ATL program that I would like to use in a windows form appllication. What is the easiest way to "convert" this code so that it compiles with /clr enabled and finds the basic classes, e.g. CObject, CString, CFile and the templates?
There's not much "conversion" that needs to be done, you can just enable /clr and compile. There will be build errors but not a huge number.
This is a decision that should not be taken lightly. Once you cross the /clr threshold you sacrifice a few things:
Build performance gets a lot worse, especially linking. You cannot incrementally link a C++ /clr project.
An additional loading layer is added to your .Exe or .Dll. You have to be careful about the order of initialization, especially with statics. This got a lot better staring with VS2005 but there are still hiccups. I have a /clr DLL project that does not unload correctly and I have not been able to figure out why. One symptom of such issues is that you don't get the memory-leak detection dumpon exit from debug.
When you add functionality to the project, you have the choice of managed or native implementation. If you choose to go managed for something that is done native elsewhere in the project, you have to choose, do I go revise the older implementation?
Crossing the managed-native threshold has performance and debugging implications.
Exception handling gets more complicated.
Rather than flipping the /clr switch on an entire project, I recommend a much more targeted approach. Keep your large library native. Create a mixed-mode /clr bootstrapper / wrapper. This "thin proxy" provides the benefit of access to your native library while maintaining the native library's stability and performance.
If you have dialogs (or worse, SDI/MDI views, see here) in your native library it can be tricky to wire up the display. But it will be worth it.
VC++.net, if I am not mistaken has a new version of MFC. Convert the project to a VC.net project and then slowly convert the classes over to managed code. This gives you a change to slowly redesign everything rather than a huge jump of rewritting everything. Btw, if you haven't already seperate the interface from the internal workings with the MVC design pattern.