Microsoft Knowledge Base Email Alertz

KBAlertz.com: Description of the supportability of Winforms controls in unmanaged applications

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 897863 - Last Review: August 26, 2005 - Revision: 1.1

Description of the supportability of Winforms controls in unmanaged applications


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.

APPLIES TO
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
Keywords: 
kbhowto kbinfo KB897863
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please