MFC C++/CLR wrapper

Amernauth 41 Reputation points
2021-02-21T21:16:20.29+00:00

Hello! I've been doing some extensive research and writing cursory code to get more familiar with creating a C++/CLR wrapper so I can access MFC methods from my WinForms C# application. A while back I was able to successfully create an interop DLL which I used to facilitate requests to an ActiveX C++ .exe out of process application which was created using MFC. Now, I'd like to completely bypass using the ActiveX .exe and create wrappers to call the MFC methods directly. First question .. Besides porting the C++ code over to .Net which would be extremely time consuming, is the creation of the wrappers ideal? Secondly .. Any other alternatives beside creating the wrappers? Third. Any tutorials outlining this process specific to creating a C++/CLR wrapper so the user can access MFC methods? Thanks!

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,487 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,595 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 9,351 Reputation points Microsoft Vendor
    2021-02-22T06:08:00.36+00:00

    Hi,

    First question .. Besides porting the C++ code over to .Net which would be extremely time consuming, is the creation of the wrappers ideal? Secondly .. Any other alternatives beside creating the wrappers?

    Yes, it is possible to use C++/CLI to write a managed wrapper for native C++ code. This wrapper (a DLL) can be consumed by a WinForms C#.

    Third. Any tutorials outlining this process specific to creating a C++/CLR wrapper so the user can access MFC methods?

    About C++/CLI wrapper for native C++ to use as reference in C#, I suggest you could refer to the links:

    https://stackoverflow.com/questions/10223186/c-cli-wrapper-for-native-c-to-use-as-reference-in-c-sharp/10223965

    https://stackoverflow.com/questions/25342536/calling-mfc-dialog-from-c-sharp-net

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful