Click here to Skip to main content
15,894,294 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: Muthithreading Pin
Mark Salsbery16-Dec-06 12:47
Mark Salsbery16-Dec-06 12:47 
GeneralRe: Muthithreading Pin
bsaksida16-Dec-06 23:22
bsaksida16-Dec-06 23:22 
AnswerRe: Muthithreading Pin
Michael Dunn16-Dec-06 12:51
sitebuilderMichael Dunn16-Dec-06 12:51 
QuestionQuestion about the built in memory leak detection in vs05 Pin
FocusedWolf15-Dec-06 14:45
FocusedWolf15-Dec-06 14:45 
AnswerRe: Question about the built in memory leak detection in vs05 Pin
George L. Jackson15-Dec-06 20:12
George L. Jackson15-Dec-06 20:12 
AnswerRe: Question about the built in memory leak detection in vs05 Pin
Mark Salsbery16-Dec-06 10:53
Mark Salsbery16-Dec-06 10:53 
GeneralRe: Question about the built in memory leak detection in vs05 Pin
FocusedWolf16-Dec-06 15:09
FocusedWolf16-Dec-06 15:09 
QuestionHosting a Windows Forms Control in a MFC ActiveX control Pin
sps-itsec4615-Dec-06 6:59
sps-itsec4615-Dec-06 6:59 
Hi guys,

I think I need some serious painkillers on this!

Short version:

Can anybody explain in details how to expose a C# WinForms Control as ActiveX control. Either via hosting it in a MFC ActiveX control or by implementing it completely in C# (implementing all interfaces, registration/unregistration stuff, events).

Perhaps somebody has a template project for this problem where I just can drop in my Windows Forms Control and is willing to share it with me and the others (sounds like XMas, I know).


Bloody details:

We have a large client application with lots of legacy code that implements an ActiveX container. So you can add e.g. GUI components by providing new ActiveX controls. Since we have almost year 2007 we want to develop new GUI components with Windows Forms instead of the existing MFC/OWL stuff (yes! OWL! WTF | :WTF: ). We recently migrated to Visual Studio 2005 (.NET 2.0).

As far as I can see there are 2 main approaches:
(Approach 1) Use of a MFC ActiveX control for hosting the Windows Forms control and use the new MFC 8.0 template classes CWinFormsDialog[^] or CWinFormsView[^] for adding the WinForms control to a CDialog/CView.

(Approach 2) Implement all necessary COM interfaces completely in C# and make them visible to COM and do the extra COM registration/unregistration stuff as explained here[^]. So the resulting component would be completely written in C# with no other languages involved. Furthermore we have about half a dozen COM interfaces for communication between the client and the ActiveX component. These interfaces must be implemented too. Sounds like very much more work than approach one.

So we decided to follow approach one - hosting a WinForms control within a MFC ActiveX control. What a pain until now!

This is what we did (following the MSDN examples[^]):

(1) Created an "empty" MFC ActiveX control, with all of our COM interfaces, showing an empty CDialog. Works flawlessly when added to the client application or to the ActiveX Control Test Container.

(2) Enabled Common Language Runtime Support (/clr) for the project. After fixing some compiler warnings the project compiles fine to MSIL.

(Mad | :mad: #1) Here is already the first major problem: When the project is started after '/clr' is activated, Visual Studio 2005 locks up completely while loading the CLR DLLs (e.g. 'mscoree.dll', 'mscorwks.dll'). There is no error message or crash, but VS2005 hangs infinitely and the only thing to do is killing the 'devenv.exe' process. Why is this? Confused | :confused: But it's possible to start the application regularly! Only when started via VS2005 it hangs. The ActiveX still shows up correctly when the application is not launched via VS2005.

(3) Since I found no solution for this problem I sighed and added a CWinFormsControl member to the "empty" CDialog as described in the MSDN example here[^] (which works by the way perfectly when used in a stand alone dialog application). I tried two variants:
CWinFormsControl<WinFormsCtrl::UserControl1> m_WinFormsCtrl;  // strong named, GACed
CWinFormsControl<System::Windows::Forms::LinkLabel> m_WinFormsCtrl;
The result was the same in both cases:

(Mad | :mad: #2) When the ActiveX is about to be displayed it crashes in 'CWinFormsControl<TManagedControl>::InternalCreateManagedControl' (<VS2005-install-path>\vc\atlmfc\include\afxwinforms.inl). Output window says: A first chance exception of type 'System.AccessViolationException' occurred in <MyActiveX>.OCX

I got this information by attaching to the application process with VS2005 when the application is already running.


I read several threads where members of the Visual Studio Team and MVP's are saying that MFC 7.1/8.0 are officially supported unmanaged hosts for Windows Forms controls, just like Internet Explorer. But it seems not to apply for MFC ActiveX controls!? WTF | :WTF:


cheers,
mykel

If they give you lined paper, write the other way!

AnswerRe: Hosting a Windows Forms Control in a MFC ActiveX control Pin
sps-itsec463-Jan-07 0:56
sps-itsec463-Jan-07 0:56 
QuestionOverride property Pin
bsaksida15-Dec-06 4:47
bsaksida15-Dec-06 4:47 
AnswerRe: Override property Pin
George L. Jackson15-Dec-06 20:28
George L. Jackson15-Dec-06 20:28 
GeneralRe: Override property Pin
bsaksida16-Dec-06 11:18
bsaksida16-Dec-06 11:18 
QuestionMulti Instance. Pin
bsaksida15-Dec-06 1:21
bsaksida15-Dec-06 1:21 
AnswerRe: Multi Instance. Pin
prasad_som15-Dec-06 2:38
prasad_som15-Dec-06 2:38 
GeneralRe: Multi Instance. Pin
bsaksida15-Dec-06 4:48
bsaksida15-Dec-06 4:48 
QuestionHide Form Pin
mactick14-Dec-06 19:26
mactick14-Dec-06 19:26 
AnswerRe: Hide Form Pin
bsaksida14-Dec-06 19:56
bsaksida14-Dec-06 19:56 
GeneralRe: Hide Form Pin
mactick14-Dec-06 20:20
mactick14-Dec-06 20:20 
GeneralRe: Hide Form Pin
bsaksida14-Dec-06 20:26
bsaksida14-Dec-06 20:26 
GeneralRe: Hide Form Pin
mactick14-Dec-06 20:56
mactick14-Dec-06 20:56 
QuestionHow to access another forms members ?? Pin
Programm3r14-Dec-06 18:27
Programm3r14-Dec-06 18:27 
AnswerRe: How to access another forms members ?? Pin
User 58385214-Dec-06 19:03
User 58385214-Dec-06 19:03 
QuestionRe: How to access another forms members ?? Pin
Programm3r14-Dec-06 20:57
Programm3r14-Dec-06 20:57 
GeneralRe: How to access another forms members ?? Pin
bsaksida14-Dec-06 21:00
bsaksida14-Dec-06 21:00 
QuestionRe: How to access another forms members ?? Pin
Programm3r14-Dec-06 23:36
Programm3r14-Dec-06 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.