Walkthrough: Using /clr:pure Features

This walkthrough demonstrates the use of reflection in pure MSIL application. The Windows Forms Scribble solution is extended to include some native classes that contain static data as well as exposing Windows Forms controls that must be usable from the Windows Forms designer. Building the sample with the /clr:pure option addresses potential issues with this scenario. See How to: Migrate to /clr:pure for more information.

Prerequisites

ScribbleDotNET Sample: Extending Scribble with CLR Features

To build/run this sample application

  1. Download the ScribbleDotNET sample.

  2. Open the solution file, Scribble.sln, in the Visual Studio development environment.

  3. Build the solution using either the "CLR-Pure Debug" or "CLR-Pure Release" configurations.

  4. Open the StringDialog.h component in Design mode

  5. The design window which appears will contain an instance of the "ScribbleCustomControl".

Technologies

  • New C++ Syntax for .NET

  • Reflection

  • marshal_as<T> for access to native types from managed classes.

This sample creates an unmanaged class and wraps it in a managed control class. When compiled into a pure MSIL application, the Visual Studio Windows Forms designer is able to reflect over the resulting EXE file and load the managed control for use in the Windows Forms designer. This behavior is possible only when the current configuration is to create a pure MSIL application, and not in an unmanaged or mixed mode.

Within the control, we instantiate an instance of a native class. The information that we need is a native string. We use marshal_as<T> to convert the data to a managed data type that we can use in a CLR-enabled application. For more information about the marshaling library, see Overview of Marshaling in C++.

See Also

Concepts

Language Features for Targeting the CLR

Other Resources

Walkthroughs in Visual C++ 2010