C# control in MFC Window/Frame

G

Guest

I have an existing MFC based application that I prefer not to change much.
For some new functionalities in this application, I'd like to write in C#.
Potentially there are substantial two-way data exchanges between the existing
MFC components and the new C# ones. In addition, I'd like the C# Forms based
controls and windows to behave reasonably consistent with the MFC app. So I
have the following questions and many thanks in advance:

1. Is this something doable or to avoid?
2. I'm optimistic so assuming doable, any recent and detailed (w/ examples)
articles (in addition to and hopefully newer than
http://msdn.microsoft.com/msdnmag/issues/05/04/C)?
3. Would I be able to control whether the C# control float out of the main
window or not? (this one is probably too specific)
4. .NET 2.0 improvements in related areas?

Thanks again,
 
L

Lloyd Dupont

I think......
You might create you Control in C#, make it COM visible (the default).
Instantiate in in C++ through COM (no idea on how to achieve that), ask for
its handle (Control.Handle). that would give you a HWND.
Which you could, then, insert into your hierarchy.
 
K

Kevin Yu [MSFT]

Hi Bill,

As far as I know, Microsoft .NET 1.0 Windows Forms controls are supported
in Windows Forms and Internet Explorer 5.01 and later versions. .NET 1.1
Windows Forms controls are supported in Windows Forms, Microsoft Foundation
Classes (MFC) 7.x, and Internet Explorer 5.01 and later versions. Other
applications and development tools that are capable of hosting ActiveX
controls, including the ActiveX Test Containers from versions of Visual
Studio that are earlier than Visual Studio .NET 2003, are not supported
hosts for .NET Windows Forms controls.

The supportability information in this article also applies to the use of
..NET controls through COM Interop. The use of a .NET control through a COM
Callable Wrapper (CCW) is supported only in Internet Explorer. For more
information on this please see article 317346 listed below.

However, using .NET controls in an MFC based application is NOT
recommended. Only MFC 7.1 and later versions support this. And also there
might be some unexpected behaviours in doing this. You can check the
following link for more information:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;311334

http://support.microsoft.com/kb/839076/

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Thanks, Kevin.

I should clarify. Othe MFC side, it's 7.1. I intend to use .NET 2.0. I'm
hoping this will make things better. On the other hand, I'm afraid someone is
going to tell me I'd have to either have 8.0/2.0 or 7.1/1.1 combinations.
 
K

Kevin Yu [MSFT]

Hi Bill,

As far as I know, we can use MFC 7.1 with .NET 2.0 controls. But we don't
recommend to use .net controls in MFC, since there might be some unexpected
issues during the interop.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

I'm not sure I follow. MS doesn't recommend .NET controls in MFC. So what's
the recommended way to develop C# components in an existing MFC application?
Just don't do it?
 
K

Kevin Yu [MSFT]

Hi Bill,

From our experience, there might be some unexpected issues when doing this.
So it's just not recommended to do so. It's better to use an ActiveX
control than hosting a .NET control.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top