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

查看:153
本文介绍了将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#,但我的想法是,让代码作为它是允许我在其他应用程序中使用它(以及在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).

作出此决定时,我应该注意什么样的事情?

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 ++应用程序中使用DLL的任何主要缺点或困难。 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天全站免登陆