Can managed and unmanaged C++/MFC be mixed in one dll?

风格不统一 提交于 2019-12-24 02:18:05

问题


Previously we had software in MFC (VC6), VB6 and C# applications that needed to call the same engine written in C++ (and MFC). The engine required C++ for speed. At the time we decided to use COM as the interface because all three could use it with the least issues in marshalling, etc.

Our MFC application is now deprecated and we have recently decided to dump VB6, so what we've got left is C#.

We can just leave the COM engine as-is, but it would be nice to get away from COM registration, etc., and have a managed interface to work with. COM registration occasionally causes support issues if there is something wrong with the person's machine.

Is it possible to have a dll with the existing unmanaged C++/MFC, and a .NET front end interface?


回答1:


You can have a C++/CLI DLL that uses MFC classes internally. One nice advantage to mixed-mode DLL creation with C++/CLI is that you can use native C++ just about anywhere within the DLL (following the C++/CLI rules) and "it just works".

The goal here, however, should be to provide nice, clean, managed wrappers that can be called from your C# application.

That being said - you'll most likely want to avoid using MFC for any user interface elements. Though possible to host MFC content in C# and vice versa, it often is problematic - you're better off just encapsulating the C++ engine (time critical operations) and legacy code in nice, clean managed wrappers using C++/CLI.




回答2:


C++/CLI can do both.



来源:https://stackoverflow.com/questions/3018944/can-managed-and-unmanaged-c-mfc-be-mixed-in-one-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!