I must solve two problems:
- use an MFC property sheet from a C# app
- manage ODBC and ADO.NET connections in a single exe
- An Overview of Managed/Unmanaged Code Interoperability
- MFC under the hood
- Native and .NET interoperability
- Using C++ Interop (Implicit PInvoke)
- Introduction to managed C++
- Intro to Managed C++, Part 2: Mixing Managed and Unmanaged Code
- C++/CLI Migration Primer
- Mixed (Native and Managed) Assemblies
- How to: Compile MFC and ATL Code with /clr
- Moving to .NET and WinFX: A Roadmap for C/C++ Applications
- Books:
- Extending MFC Applications with the .NET Framework (Tom Archer)
- Subclass System.Windows.Forms.Control
This technique works ok with a CWnd-derived class. Unfortunately our legacy MFC code is based on property sheets so this is not going to be enough, but it’s a start.
- One single C++/CLI App containing MFC legacy source and dialog templates.
However for some reason only the Release version of the executable worked. The Debug version kept displaying the following assertion,
Anyway this is still not quite what I want to do: my Windows Forms MDI framework is written in C#, not in C++. The legacy code must reside a DLL compiled in mixed mode.
- A C# Windows Forms project calls a dialog residing inside a mixed-mode exe
- Changed to DLL
- Switched on /clr
- Disabled pre-compiled headers.
- Same as above but using Alexey Shalnov’s MFCAppAdapter class
- Created an MFC MDI App with Visual Studio 2005.
- Added MFCAppAdapter.cpp (copied from Alexey Shalnov’s article).
- Changed MFCAppAdapter.cpp compile options to /clr (at the file level, not the project level).
- Set Code Generation option: set to default.
- Set Enable Minimal Rebuild option to No.
- Set Enable C++ Exceptions to Yes with SEH
- Set Debug Information Format to Zi
- Add references to System and System.Windows.Forms