Search code examples
.netdllmfcunmanagedmanaged

Wrapping MFC native code for use in Managed Code


I have an old MFC code that I would like to call from my managed C# WPF .Net application. For wrapping the native code, I discovered that I had the options to either use 1) P/Invoke 2) C++/CLI or 3) COM.

But I have another concern. I read that you have to build MFC Extension DLL whenever it’s going to include classes derived from the MFC. Also, that the calling side of this DLL must be an MFC environment, which I think means that this DLL is not workable inside my managed code.

In my application, I have classes that derive from base MFC classes. I use the document view architecture, and my Doc, View , MainFrame, App classes are derived from MFC classes. Does this mean that I have no other option than to build an MFC Extension DLL, and that there is no way to use this DLL in my managed application. Any suggestions how to get around this problem?


Solution

  • Why don't you encapsulate your MFC code in a MFC ActiveX Project and use Interoperability to call it from your managed code application? Seems the easiest solution to me.