none
Inquiry on .NET COM interop compatibility RRS feed

  • Question

  • Hi all,


    I have a WinForm .NET 3.5 library (VS2008 project), which i would like to use in a MFC 7.1 application (VS2003 project).

    If I export .NET library as COM server and interop with legacy MFC 7.1 application, will there be a .NET runtime compatibility issue?

    I'm really new to interop and COM, and want to know if it is feasible or not.


    If COM is the wrong direction, what would be the proper way?

    Thanks in advance!

     

    Best Regards,

    Wade

    Tuesday, November 30, 2010 6:57 AM

Answers

  • Hello Wade,

     

    1. >> If I export .NET library as COM server and interop with legacy MFC 7.1 application, will there be a .NET runtime compatibility issue?

    1.1 No, there will not be any compatibility issues.

    1.2 What you need to do is to ensure that your .Net classes use various COM attributes (esp ComVisibleAttribute, GuidAttribute, InterfaceTypeAttribute, etc)

    1.3 Ensure that your .NET class library is registered properly via regasm.exe. Be sure to use the /tlb flag to export the types in the .Net class library into a Type Library file (.tlb).

    1.4 You will need to use the type library in order to build your MFC client application. The type library needs to be imported into your MFC source codes via the #import statement.

    1.5 Then, after compiling your MFC app, ensure that your .NET class library and all other dependency class libraries are copied into the same directory as the client application unless you have registered your .Net class library into the Global Aseembly Cache (GAC).

     

    2. >> If COM is the wrong direction, what would be the proper way?

    2.1 A .NET class library can be exposed as a COM server (via a COM-callable wrapper) just as much as an unmanaged COM server may be exposed as a .NET class library (via a Runtime-Callable Wrapper).

     

    - Bio.

     

    • Marked as answer by __Wade__ Wednesday, December 1, 2010 12:59 PM
    Tuesday, November 30, 2010 3:08 PM

All replies

  • Hello Wade,

     

    1. >> If I export .NET library as COM server and interop with legacy MFC 7.1 application, will there be a .NET runtime compatibility issue?

    1.1 No, there will not be any compatibility issues.

    1.2 What you need to do is to ensure that your .Net classes use various COM attributes (esp ComVisibleAttribute, GuidAttribute, InterfaceTypeAttribute, etc)

    1.3 Ensure that your .NET class library is registered properly via regasm.exe. Be sure to use the /tlb flag to export the types in the .Net class library into a Type Library file (.tlb).

    1.4 You will need to use the type library in order to build your MFC client application. The type library needs to be imported into your MFC source codes via the #import statement.

    1.5 Then, after compiling your MFC app, ensure that your .NET class library and all other dependency class libraries are copied into the same directory as the client application unless you have registered your .Net class library into the Global Aseembly Cache (GAC).

     

    2. >> If COM is the wrong direction, what would be the proper way?

    2.1 A .NET class library can be exposed as a COM server (via a COM-callable wrapper) just as much as an unmanaged COM server may be exposed as a .NET class library (via a Runtime-Callable Wrapper).

     

    - Bio.

     

    • Marked as answer by __Wade__ Wednesday, December 1, 2010 12:59 PM
    Tuesday, November 30, 2010 3:08 PM
  • Hi Bio,

    Thanks a lot for your reply!

    Just a follow up question:

    My .NET library is actually a WinForm GUI control library, I also have a WinForm application (.exe) that makes use of this library.

    My ultimate goal is to integrate the WinForm control (.NET 3.5) into the MFC 7.1 app. If that's not possible, I wonder if I can expose the WinForm control (or the WinForm exe) as out-of-proc COM, so it can interact with MFC 7.1 app?

    To actually do this may take some time, I just want to make sure it's a workable solution before digging into this.

    Thanks in advance!

     

    Best Regards,

    Wade

    Thursday, December 2, 2010 6:03 AM
  • Hello Wade,

    >> My ultimate goal is to integrate the WinForm control (.NET 3.5) into the MFC 7.1 app.

    1. I think the most natural way to do this would be to expose your WinForm controls as ActiveX controls.

    2. Here is a link to a code project article that explains how this can be done :

    http://www.codeproject.com/KB/miscctrl/exposingdotnetcontrols.aspx

    The article is a little old though.

    3. Also interesting is the discussion in the following link :

    http://bytes.com/topic/asp-net/answers/308854-how-create-activex-control-using-c-use-asp-net-webform

    - Bio.

     

    Thursday, December 2, 2010 11:51 PM