tags:

views:

50

answers:

4

I'm wondering how I would go about converting an existing c# winforms application to a class library and then call it from an mfc application. Are there any references on how to do this? I've tried googling, but, besides the fact that it will need the ComVisible attribute set to true I haven't found much information.

Thanks.

+1  A: 

Have a look at the regasm.exe tool shipped with .NET. It will generate the necessary registry entries (and optionally a .tlb file) that will allow COM components to access your assembly.

Steve Danner
+2  A: 

In visual studio project properties change the output type to class library. This will make your project compile into a dll. Also set the comvisible attribute to true. Thus will generate a com callable wrapper and a tlb file which you can use from your mfc project.

Also I think the following link is a very good and detailed explanation of how COM Interop works in .Net

http://www.codeproject.com/KB/COM/cominterop.aspx

Unmesh Kondolikar
A: 

Once you get this build properly, then you will need to get it to run properly. The main problem might be correctly parenting the windows forms from unmanaged windows, basically getting your managed forms to live inside what started as an unmanaged application. If you don't use WPF as the UI bridge between your unmanaged code and managed forms, then you will need to do this work yourself. You can google this topic for more info, don't have a link for this handy at the moment.

Chris O
+1  A: 

There is an MSDN sample that covers putting a Winforms user control on an MFC app - dialog or view. In addiition to code this should show you the project settings you will need.

Kate Gregory