Managed C++ wrappers for legacy C++ libraries

后端 未结 5 1496
挽巷
挽巷 2020-12-14 14:02

We\'re looking at writing a .Net-callable wrapper for some legacy C++ libraries using managed C++.

It all looks pretty easy. Is there anything we need to watch out

5条回答
  •  离开以前
    2020-12-14 14:37

    As said by others: 98% of the time it just works, its debuggable, and fast.

    What I encountered beyond mentiond so far:

    • Don't compile all your legacy c++ code as managed. There were some articles suggesting that would be useful, but it is usually just slower.
    • Don't forget to catch unmanaged exceptions and rethrow them as managed ones.
    • If you use MFC, note that you you can't use the .lib runtime, so you'll be deploying MFC runtimes as well.
    • OpenMP (a threading library) won't run in C++/CLI.
    • we had some build issues in VS2005 when we made the C++/CLI dll's dependent on C# dlls from our own code.

    It even worked so well that I started on writing C++/CLI code to run unit tests on C++ code. NUnit/Resharper will happily find and run the unit test in a C++/CLI DLL, that can directly call into your native code at ANY LEVEL, even test your template container classes.

提交回复
热议问题