FoundationEx .NET
FoundationEx .NET functionality is an extension to the existing FoundationEx classes. This functionality is located in a new project that separates the dependencies of the .NET framework from FoundationEx. The solution and project files are in <InstallDir>\Src\FoundationEx* .NET.sln, where * is a numerical value for the compiler version.
Using the features of FoundationEx .NET requires the addition of various elements to your existing or new FoundationEx-based application, as discussed in this section.
Framework and References
FoundationEx .NET requires the Microsoft .NET framework. This framework is installed with your compiler. When creating a FoundationEx .NET project, the Visual Studio project settings need to reference .NET assemblies. These .NET assemblies include: PresentationCore, PresentationFramework, System, System.Xaml, WindowsBase.
Set these in the project settings under Common Properties >Framework and References. Select Add New Reference to locate the .NET assembly references mentioned above and add them to the project.
Header Files and Namespaces
To access the new FoundationEx.NET functionality, add header files to your new or existing FoundationEx project. These include FoundationExNet.h, vcclr.h, and msclr\event.h.
// Typically added to stdafx.h
#include <FoundationEx .NET\FoundationExNet.h>
// View Classes will typically need the following:
// C++/CLI Headers and Namespaces
#include <vcclr.h>
#include <msclr\event.h>
using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Media;
using namespace System::Windows::Shapes;
using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Media::Animation;
using namespace System::Windows::Interop;
using namespace sflexnet;
As shown in the code snippet above, it is also necessary to include a reference to the sflexnet namespace.
CLR Support
The common language runtime (CLR) must be added as an option in the project settings. In Visual Studio, set the project setting Configuration Properties > General > Common Language Runtime Support to Common Language Runtime Support (/clr).
In addition, add the CLR to any files in a mixed programming application that uses managed code. To add this support in Visual Studio, right-click on the .cpp file and select properties. Then choose Configuration Properties > C/C++ > General > Common Language Run Time Support and select Common Language Runtime Support (/clr).
In mixed mode programming using C++/CLI, the exception option /EHs is incompatible with the /clr switch. In the Visual Studio project settings, change Code Generation to exceptions to /EHa by setting Configuration Properties > C/C++ > Code Generation > Enable C++ Exceptions to Yes with SEH Exceptions (/EHa).
In mixed mode programming using C++/CLI, the optimization options must be disabled. In the Visual Studio project settings, disable optimization by setting Configuration Properties > C/C++ > Optimization > Optimization to Disabled (/Od).
FoundationEx .NET Sample
A sample is provided that demonstrates the usage of the FoundationEx .NET features involving MFC and WPF interoperability. The sample is located in the <InstallDir>\Samples\FoundationEx .NET\WPFMDIEx\ directory and is used in discussion of all code samples related to MFC and WPF Interoperability throughout this document.