Description of the supportability of Winforms controls in unmanaged applications

Article translations Article translations
Article ID: 897863 - View products that this article applies to.
Expand all | Collapse all

On This Page

INTRODUCTION

This article contains information about the supportability of using Microsoft .NET Windows Forms (Winforms) controls in an unmanaged application. These unmanaged applications may include Microsoft Visual Basic 6.0 applications, Microsoft Foundation Classes (MFC) applications, or Microsoft Internet Explorer.

MORE INFORMATION

Scenario 1: Host Winforms components as ActiveX controls

In the Microsoft .NET Framework 1.0, Winforms only supports using Winforms controls in the following:
  • Windows Forms
  • Internet Explorer 5.01 and later versions
Winforms controls that are registered as ActiveX controls are not supported. Winforms controls that are created by using the CoCreateInstance function are also not supported.

In the Microsoft .NET Framework 1.1, support has been extended to include MFC 7.x and later versions and any container that is fully compatible with the MFC 7.x ActiveX control container. However, Winforms controls that are registered as ActiveX controls are still not supported. Winforms controls that are created by using the CoCreateInstance function are also not supported. Winforms only supports the managed activation of Winforms controls. When the Winforms controls are created, the controls can be hosted in MFC like other ActiveX controls.

To use Winforms controls in your application, you have to either host the common language runtime by using the unmanaged CLR hosting APIs or use the Managed Extensions for C++ to implement your application. We recommend that you use Managed Extensions for C++.

Scenario 2: Display a Winforms form from an unmanaged application

In the .NET Framework, you can display a Winforms form from an unmanaged application, such as a Visual Basic 6.0 application or an MFC 6.0 application. This scenario is supported. You can create a class library in Winforms that includes a method to display the form, and then build the class library for COM Interop. After you create and build the class library, you can use the Interop .dll file from Visual Basic 6.0 or from MFC, and then call the method to display the form. The key is to create a Winforms message pump in the Winforms form. The Winforms form can then run on the message pump.

You can start a Winforms message pump using one of the following methods:
  • Use the Form.ShowDialog() method to start a Winforms message pump for the form.
  • Put the form on a separate thread, and then call the Application.Run (newForm1) method to start the Winforms message pump on that thread. If you use this method to start the message pump, you must marshal any calls to the form from the unmanaged application. To do this, use the Control.Invoke method or an equivalent method.
For Win32 Interop, there are only two supported scenarios:
  • Create a new thread, and then use the Form.ShowDialog() method or the Application.Run() method. The Winforms message pump is used to dispatch for the thread.
  • Winforms code is hosted in MFC 7.x or Internet Explorer as an ActiveX control. In this scenario, you have to wrap up the managed code in an ActiveX control, and then use the ActiveX control as the hosting interface.

Note Subclassing or setting a form's parent to be a Win32 parent is not supported in any circumstance.

Properties

Article ID: 897863 - Last Review: August 26, 2005 - Revision: 1.1
APPLIES TO
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
Keywords: 
kbhowto kbinfo KB897863

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com