Delegates Sample: Demonstrates Custom Delegates in a Managed Application

Delegates Sample: Demonstrates Custom Delegates in a Managed Application

Visual Studio .NET 2003

The Delegates sample illustrates the DelegateConsole class. It implements two uses of a delegate (single-cast and multicast) using the __delegate keyword. For more information on delegates, see Delegates in Managed Extensions for C++.

The sample also demonstrates interoperability between a Managed Extensions for C++ application and a C# DLL (csdel). The C# DLL implements a basic C# class (CDel) with a custom method.

Building and Running the Sample

To build and run Delegates using Visual Studio

  1. In the Visual Studio IDE, load the solution file Delegates.sln.
  2. In Solution Explorer, right-click the Delegates solution.
  3. On the shortcut menu, click Build Solution.
  4. On the Debug menu, click Start.

When the sample is built and run, single-cast and multicast delegates are created and invoked:

  • pSCDelegate

    A single-cast delegate is created and then the bound method is invoked. The confirmation is a printed string with the value passed by the single-cast delegate.

  • pMCDelegate

    Before creating the multicast delegate, the C# class (CDel) is first instantiated. The delegate is then bound to both the C# and managed class methods and invoked. The confirmation is a printed string with the value passed by the multicast delegate.

See Also

Managed Extensions for C++ Samples | printf | __delegate | static_cast

Show:
© 2016 Microsoft