The user control uses ICommandTarget::Initialize to store a reference to the command source object in m_CmdSrc, as shown in the following example. To use ICommandTarget you need to add a reference to mfcmifc80.dll.

CWinFormsView handles several of the common MFC view notifications by forwarding them to the managed user control. These notifications include the OnInitialUpdate, OnUpdate and OnActivateView methods of the IView Interface.

Go to Resource View (CTRL+SHIFT+E), expand the Menu folder, and then double click on IDR_MFC02TYPE. This displays the menu editor.

Add a menu option at the bottom of the View menu. Save the file.

In Solution Explorer, open the Resource.h file, copy the value for the menu option you just added, and paste that value as the first parameter to the m_CmdSrc.AddCommandHandler call in the C# project's Initialize method.

Build and run the project.

On the Build menu, click Build Solution.

On the Debug menu, click Start without debugging.

Select the menu option you added. Notice that the method in the .dll is called.