编写C#和C ++应用程序的DLL
我需要编写几个DLL,这两个都可以从C#应用程序和C ++应用程序访问。最初,我想我可以通过编写C#中的DLL并从C#和C ++应用程序链接到它们来节省时间/精力。这个方法是明智的,还是应该使用C ++编写DLL?
I need to write a couple DLLs that will both be accessed from a C# application and a C++ application. Initially, I was thinking that I could save time/effort by writing the DLLs in C# and linking to them from the C# and C++ applications. Is this approach wise, or should the DLLs be written using C++?
我的建议是实现代码,最舒适,但不要忘记interop要求,当你去。了解您的接口是什么,以及在最终产品中需要什么胶。在填写实现之前编写接口并测试interop。
My advice would be to implement the code where you are most comfortable, but don't forget the interop requirement as you go. Know upfront what your interface is and what glue is required in the end product. Write the interface and test the interop before you fill out the implementation.
如果你的要求的复杂性使舒适度无关紧要,我会写在C ++中,你可以通过P / Invoke访问。
If the complexity of your requirement makes comfort level irrelevant, I would write it in C++ in such a way that you can access via P/Invoke.
一个重要的因素是你使用C ++ / CLI或本地C ++。这在C ++ / CLI和C#之间互操作要容易得多,在任何方向。
One important factor is are you using C++/CLI or native C++. It's a lot easier to interop between C++/CLI and C#, in either direction.