移植(非托管)C ++到C#与使用C ++作为一个C#应用程序DLL [英] Porting (unmanaged) C++ to C# vs. using the C++ as a DLL in a C# application

查看:92
本文介绍了移植(非托管)C ++到C#与使用C ++作为一个C#应用程序DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在普通的旧的C代码库++(无.NET /托管代码)和我移植使用此代码为C#应用程序。我面临两种选择:

I have a code library written in plain old C++ (no .NET/managed code) and I'm porting the application that uses this code to C#. I'm faced with two options:


  1. 改写C ++代码在C#中实现相同的功能;

  2. 编译C ++作为一个DLL,并把它作为在C#应用程序库。

我是比较新的C#而我与在C#应用程序使用非托管代码库的影响相当陌生的(或者甚至有话)。代码本身的大小适中;它可能会只需要几天在C#重写,但我的想法是离开代码作为它可以让我在其它应用程序中使用它,以及(和编译它在UNIX等)。

I'm relatively new to C# and am pretty unfamiliar with the implications of using an unmanaged code library in a C# app (or if there even are any). The code itself is moderate in size; it will likely take only a few days to rewrite in C#, but my thought is that leaving the code as a it is would allow me to use it in other applications as well (and to compile it on UNIX, etc).

我应该知道做这个决定的时候是什么样的东西?是否有任何重大的缺点或缺陷,使用在C#应用程序的DLL?

What sort of things should I be aware of when making this decision? Are there any major drawbacks or gotchas to using the DLL in the C# application?

推荐答案

我会使用C做一个包装库++ / CLI揭露库为C#。这可以留下您的库不变,只是把它包起来,从.NET应用,提供最佳的两个选项。

I would make a wrapper library using C++/CLI to expose the library to C#. This can leave your library unchanged, and just wrap it for use from .NET, providing the best of both options.

这篇关于移植(非托管)C ++到C#与使用C ++作为一个C#应用程序DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆